globalize mongo metrics

multiple calls for options would duplicate/override
This commit is contained in:
rasmus 2022-11-06 19:04:03 +02:00
parent 368359a043
commit 80ea6b7821

View File

@ -11,8 +11,8 @@ import (
"go.uber.org/zap"
)
func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
promDbHeartbeat := promauto.NewHistogramVec(prom.HistogramOpts{
var (
promDbHeartbeat = promauto.NewHistogramVec(prom.HistogramOpts{
Namespace: PrometheusPrefix,
Subsystem: "database",
Name: "heartbeat_time",
@ -20,7 +20,7 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
Buckets: []float64{1},
}, []string{"connection_id"})
promDbCmd := promauto.NewHistogramVec(prom.HistogramOpts{
promDbCmd = promauto.NewHistogramVec(prom.HistogramOpts{
Namespace: PrometheusPrefix,
Subsystem: "database",
Name: "operation_latency", // "command_time",
@ -28,13 +28,15 @@ func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
Buckets: []float64{0.1, 0.2, 0.5, 1, 5, 10, 50},
}, []string{"connection_id", "command_name"})
promDbCmdErr := promauto.NewCounterVec(prom.CounterOpts{
promDbCmdErr = promauto.NewCounterVec(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "database",
Name: "errors",
Help: "Failed commands (also reflected elsewhere)",
}, []string{"connection_id", "command_name"})
)
func mongoMonitoredClientOptions(l *zap.Logger) *mongoOpt.ClientOptions {
return mongoOpt.Client().
SetServerMonitor(&mongoEvent.ServerMonitor{
ServerHeartbeatSucceeded: func(ev *mongoEvent.ServerHeartbeatSucceededEvent) {