From 67b01329a03716e996da2565ae26a466e21f608e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 7 Feb 2023 10:20:41 -0800 Subject: [PATCH] lib/writeconcurrencylimiter: initialize concurrencyLimitCh before exporting `vm_concurrent_insert_capacity` and `vm_concurrent_insert_current` metrics This will result in proper calculations for the the alerting rule: avg_over_time(vm_concurrent_insert_current[1m]) >= vm_concurrent_insert_capacity See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3761 --- lib/writeconcurrencylimiter/concurrencylimiter.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/writeconcurrencylimiter/concurrencylimiter.go b/lib/writeconcurrencylimiter/concurrencylimiter.go index eaf6fbc18..3d83bff44 100644 --- a/lib/writeconcurrencylimiter/concurrencylimiter.go +++ b/lib/writeconcurrencylimiter/concurrencylimiter.go @@ -126,9 +126,11 @@ var ( concurrencyLimitTimeout = metrics.NewCounter(`vm_concurrent_insert_limit_timeout_total`) _ = metrics.NewGauge(`vm_concurrent_insert_capacity`, func() float64 { + concurrencyLimitChOnce.Do(initConcurrencyLimitCh) return float64(cap(concurrencyLimitCh)) }) _ = metrics.NewGauge(`vm_concurrent_insert_current`, func() float64 { + concurrencyLimitChOnce.Do(initConcurrencyLimitCh) return float64(len(concurrencyLimitCh)) }) )