From 943370b5b3b293cb8294195b287d38c584f3148e Mon Sep 17 00:00:00 2001 From: "huangqing.zhu" Date: Tue, 5 Nov 2024 14:29:04 +0800 Subject: [PATCH] fix --- collector.go | 5 ++--- metric.go | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/collector.go b/collector.go index a67986f..c16d121 100644 --- a/collector.go +++ b/collector.go @@ -23,7 +23,7 @@ func (c *client) RegisterCollector(rc RegisterCollectorFunc) { }) } -var colOnceMap sync.Map +var colOnce sync.Once var col = &collector{ delayLengthDesc: prometheus.NewDesc( prometheus.BuildFQName(namespace, "delay", "queue_length"), @@ -40,8 +40,7 @@ type collector struct { func registerCollector(rc RegisterCollectorFunc, c *client) { col.cs.Store(c, struct{}{}) - m, _ := colOnceMap.LoadOrStore(rc, &sync.Once{}) - m.(*sync.Once).Do(func() { + colOnce.Do(func() { rc(col) }) } diff --git a/metric.go b/metric.go index ce0ddc6..906a94d 100644 --- a/metric.go +++ b/metric.go @@ -17,7 +17,7 @@ const ( ) var ( - metricOnceMap sync.Map + metricOnce sync.Once metric *prometheus.SummaryVec errMetric, hitsMetric, missMetric *prometheus.CounterVec delayPollErrorMetric, delayReclaimErrorMetric, delayReclaimCountMetric *prometheus.CounterVec @@ -55,8 +55,7 @@ func init() { } func registerMetric(rc RegisterCollectorFunc) { - m, _ := metricOnceMap.LoadOrStore(rc, &sync.Once{}) - m.(*sync.Once).Do(func() { + metricOnce.Do(func() { rc(errMetric) rc(hitsMetric) rc(missMetric)