Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicated register bedis client metrics #2721

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading