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