Skip to content

Commit

Permalink
fix: duplicated register bedis client metrics (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkaidChan authored Nov 1, 2023
1 parent dbe8e64 commit 62b3edb
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions bcs-services/bcs-bscp/pkg/dal/bedis/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,46 @@
package bedis

import (
"sync"

"github.com/prometheus/client_golang/prometheus"

"bscp.io/pkg/metrics"
)

var (
metricInstance *metric
once sync.Once
)

func initMetric() *metric {
m := new(metric)
labels := prometheus.Labels{}
m.cmdLagMS = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: metrics.Namespace,
Subsystem: metrics.BedisCmdSubSys,
Name: "lag_milliseconds",
Help: "the lags(milliseconds) to exec a bedis command",
ConstLabels: labels,
Buckets: []float64{1, 2, 3, 4, 5, 7, 9, 12, 14, 16, 18, 20, 40, 60, 80, 100, 150, 200, 500},
}, []string{"cmd"})
metrics.Register().MustRegister(m.cmdLagMS)

m.errCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
once.Do(func() {
m := new(metric)
labels := prometheus.Labels{}
m.cmdLagMS = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: metrics.Namespace,
Subsystem: metrics.BedisCmdSubSys,
Name: "total_err_count",
Help: "the total error count when exec a bedis command",
Name: "lag_milliseconds",
Help: "the lags(milliseconds) to exec a bedis command",
ConstLabels: labels,
Buckets: []float64{1, 2, 3, 4, 5, 7, 9, 12, 14, 16, 18, 20, 40, 60, 80, 100, 150, 200, 500},
}, []string{"cmd"})
metrics.Register().MustRegister(m.errCounter)
metrics.Register().MustRegister(m.cmdLagMS)

m.errCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metrics.Namespace,
Subsystem: metrics.BedisCmdSubSys,
Name: "total_err_count",
Help: "the total error count when exec a bedis command",
ConstLabels: labels,
}, []string{"cmd"})
metrics.Register().MustRegister(m.errCounter)

metricInstance = m

return m
})
return metricInstance
}

type metric struct {
Expand Down

0 comments on commit 62b3edb

Please sign in to comment.