Skip to content

Commit 1f94bd4

Browse files
committed
monitoring: use new collector timeout config
1 parent 71a3faa commit 1f94bd4

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

monitoring/asset_balances_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (a *assetBalancesCollector) Collect(ch chan<- prometheus.Metric) {
7272
a.collectMx.Lock()
7373
defer a.collectMx.Unlock()
7474

75-
ctxdb, cancel := context.WithTimeout(context.Background(), dbTimeout)
75+
ctxdb, cancel := context.WithTimeout(context.Background(), promTimeout)
7676
defer cancel()
7777

7878
assets, err := a.cfg.AssetStore.FetchAllAssets(ctxdb, false, false, nil)

monitoring/asset_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (a *universeStatsCollector) Collect(ch chan<- prometheus.Metric) {
9797
a.collectMx.Lock()
9898
defer a.collectMx.Unlock()
9999

100-
ctx, cancel := context.WithTimeout(context.Background(), dbTimeout)
100+
ctx, cancel := context.WithTimeout(context.Background(), promTimeout)
101101
defer cancel()
102102

103103
universeStats, err := a.cfg.UniverseStats.AggregateSyncStats(ctx)

monitoring/db_collector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (a *dbCollector) Collect(ch chan<- prometheus.Metric) {
8484
a.collectMx.Lock()
8585
defer a.collectMx.Unlock()
8686

87-
ctxdb, cancel := context.WithTimeout(context.Background(), dbTimeout)
87+
ctxdb, cancel := context.WithTimeout(context.Background(), promTimeout)
8888
defer cancel()
8989

9090
// Fetch the db size.

monitoring/prometheus.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import (
1212
"github.com/prometheus/client_golang/prometheus/promhttp"
1313
)
1414

15+
const (
16+
// defaultTimeout is the default timeout.
17+
defaultTimeout = 20 * time.Second
18+
)
19+
1520
var (
1621
// serverMetrics is a global variable that holds the Prometheus metrics
1722
// for the gRPC server.
1823
serverMetrics *grpc_prometheus.ServerMetrics
19-
)
2024

21-
const (
22-
// dbTimeout is the default database timeout.
23-
dbTimeout = 20 * time.Second
25+
promTimeout time.Duration
2426
)
2527

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

51+
if p.config.CollectorRPCTimeout.Seconds() != 0 {
52+
promTimeout = p.config.CollectorRPCTimeout
53+
} else {
54+
promTimeout = defaultTimeout
55+
}
56+
4957
// Create a custom Prometheus registry.
5058
p.registry = prometheus.NewRegistry()
5159
p.registry.MustRegister(collectors.NewProcessCollector(

0 commit comments

Comments
 (0)