Skip to content

Commit

Permalink
monitoring: use new collector timeout config
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Jan 16, 2025
1 parent 19c6cce commit 6c6bb3c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion monitoring/asset_balances_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (a *assetBalancesCollector) Collect(ch chan<- prometheus.Metric) {
a.collectMx.Lock()
defer a.collectMx.Unlock()

ctxdb, cancel := context.WithTimeout(context.Background(), dbTimeout)
ctxdb, cancel := context.WithTimeout(context.Background(), promTimeout)
defer cancel()

assets, err := a.cfg.AssetStore.FetchAllAssets(ctxdb, false, false, nil)
Expand Down
2 changes: 1 addition & 1 deletion monitoring/asset_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (a *universeStatsCollector) Collect(ch chan<- prometheus.Metric) {
a.collectMx.Lock()
defer a.collectMx.Unlock()

ctx, cancel := context.WithTimeout(context.Background(), dbTimeout)
ctx, cancel := context.WithTimeout(context.Background(), promTimeout)
defer cancel()

universeStats, err := a.cfg.UniverseStats.AggregateSyncStats(ctx)
Expand Down
2 changes: 1 addition & 1 deletion monitoring/db_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (a *dbCollector) Collect(ch chan<- prometheus.Metric) {
a.collectMx.Lock()
defer a.collectMx.Unlock()

ctxdb, cancel := context.WithTimeout(context.Background(), dbTimeout)
ctxdb, cancel := context.WithTimeout(context.Background(), promTimeout)
defer cancel()

// Fetch the db size.
Expand Down
11 changes: 7 additions & 4 deletions monitoring/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ var (
// serverMetrics is a global variable that holds the Prometheus metrics
// for the gRPC server.
serverMetrics *grpc_prometheus.ServerMetrics
)

const (
// dbTimeout is the default database timeout.
dbTimeout = 20 * time.Second
promTimeout time.Duration
)

// PrometheusExporter is a metric exporter that uses Prometheus directly. The
Expand All @@ -46,6 +43,12 @@ func (p *PrometheusExporter) Start() error {
return fmt.Errorf("server metrics not set")
}

if p.config.CollectorRPCTimeout.Seconds() != 0 {
promTimeout = p.config.CollectorRPCTimeout
} else {
promTimeout = time.Second * 20
}

// Create a custom Prometheus registry.
p.registry = prometheus.NewRegistry()
p.registry.MustRegister(collectors.NewProcessCollector(
Expand Down

0 comments on commit 6c6bb3c

Please sign in to comment.