From c6996541ef14e3d998aa7cb5396882e0a544b64c Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Thu, 16 Jan 2025 12:40:01 +0100 Subject: [PATCH] monitoring: use new collector timeout config --- monitoring/asset_balances_collector.go | 2 +- monitoring/asset_collector.go | 2 +- monitoring/db_collector.go | 2 +- monitoring/prometheus.go | 11 +++++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/monitoring/asset_balances_collector.go b/monitoring/asset_balances_collector.go index 462711c6d..14a609c26 100644 --- a/monitoring/asset_balances_collector.go +++ b/monitoring/asset_balances_collector.go @@ -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) diff --git a/monitoring/asset_collector.go b/monitoring/asset_collector.go index 83e608746..efd1f55ec 100644 --- a/monitoring/asset_collector.go +++ b/monitoring/asset_collector.go @@ -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) diff --git a/monitoring/db_collector.go b/monitoring/db_collector.go index cb3826199..e7b67f71e 100644 --- a/monitoring/db_collector.go +++ b/monitoring/db_collector.go @@ -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. diff --git a/monitoring/prometheus.go b/monitoring/prometheus.go index bbb8e579b..7fa2f3a21 100644 --- a/monitoring/prometheus.go +++ b/monitoring/prometheus.go @@ -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 @@ -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(