Skip to content

Commit

Permalink
fix: bug where an adguard version upgrade results in duplicate adguar…
Browse files Browse the repository at this point in the history
…d_running metrics for a server
  • Loading branch information
henrywhitaker3 committed Apr 5, 2024
1 parent 8efba6b commit dac5820
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

var (
initialised = []string{}
versions = map[string]string{}
)

func Work(ctx context.Context, interval time.Duration, clients []*adguard.Client) {
Expand Down Expand Up @@ -92,6 +93,16 @@ func collectStatus(ctx context.Context, client *adguard.Client) {
metrics.ScrapeErrors.WithLabelValues(client.Url()).Inc()
return
}
// Persist the running version the first time
if _, ok := versions[client.Url()]; !ok {
versions[client.Url()] = status.Version
}

// Check if the adguard version has changed
if versions[client.Url()] != status.Version {
metrics.Running.Reset()
}

metrics.Running.WithLabelValues(client.Url(), status.Version).Set(float64(status.Running.Int()))
metrics.ProtectionEnabled.WithLabelValues(client.Url()).Set(float64(status.ProtectionEnabled.Int()))
}
Expand Down

0 comments on commit dac5820

Please sign in to comment.