Skip to content

Commit

Permalink
Merge pull request #8 from vinted/fix/retry_on_error_config
Browse files Browse the repository at this point in the history
Configure if should retry metrics retrieval on error.
  • Loading branch information
vbalys authored Oct 9, 2024
2 parents 9e158f1 + 0c606ee commit 4e1596a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"graphqlURL": "http://localhost:8090/graphql/",
"graphqlAPIToken": "Token SECRET",
"cacheExpire": 0,
"retryOnError": false,
"metricsPrefix": "graphql_exporter_",
"queries":[
{
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Cfg struct {
GraphqlURL string
GraphqlAPIToken string
CacheExpire int64
RetryOnError bool
MetricsPrefix string
Queries []Query
}
Expand Down
12 changes: 8 additions & 4 deletions internal/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ func (collector *GraphqlCollector) updateMetrics() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
metrics, err := collector.getMetrics(ctx)
collector.accessMu.Lock()
defer collector.accessMu.Unlock()
if err != nil {
slog.Error(fmt.Sprintf("error collecting metrics: %s", err))
if !config.Config.RetryOnError {
collector.cachedAt = time.Now().Unix()
}
return err
} else {
collector.cachedMetrics = metrics
collector.cachedAt = time.Now().Unix()
}
collector.accessMu.Lock()
collector.cachedMetrics = metrics
collector.cachedAt = time.Now().Unix()
collector.accessMu.Unlock()
}
return nil
}
Expand Down

0 comments on commit 4e1596a

Please sign in to comment.