chore(unified-storage): add dual writer metric to track instance modes (#105144)

This commit is contained in:
Mustafa Sencer Özcan
2025-05-12 09:18:06 +02:00
committed by GitHub
parent 719b5fe9cc
commit cb28213f1d
3 changed files with 37 additions and 2 deletions
+5
View File
@@ -298,6 +298,7 @@ func InstallAPIs(
// this is needed to support setting a default RESTOptionsGetter for new APIs that don't
// support the legacy storage type.
var dualWrite grafanarest.DualWriteBuilder
metrics := newBuilderMetrics(reg)
// nolint:staticcheck
if storageOpts.StorageType != options.StorageTypeLegacy {
@@ -359,6 +360,9 @@ func InstallAPIs(
if err != nil {
return nil, err
}
metrics.recordDualWriterModes(gr.Resource, gr.Group, mode, currentMode)
switch currentMode {
case grafanarest.Mode0:
return legacy, nil
@@ -366,6 +370,7 @@ func InstallAPIs(
return storage, nil
default:
}
if dualWriterPeriodicDataSyncJobEnabled {
// The mode might have changed in SetDualWritingMode, so apply current mode first.
syncerCfg.Mode = currentMode
+30
View File
@@ -0,0 +1,30 @@
package builder
import (
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type builderMetrics struct {
dualWriterTargetMode *prometheus.GaugeVec
dualWriterCurrentMode *prometheus.GaugeVec
}
func newBuilderMetrics(reg prometheus.Registerer) *builderMetrics {
return &builderMetrics{
dualWriterTargetMode: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "unified_storage_dual_writer_target_mode",
Help: "Unified Storage dual writer target mode",
}, []string{"resource", "group"}),
dualWriterCurrentMode: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "unified_storage_dual_writer_current_mode",
Help: "Unified storage dual writer current mode",
}, []string{"resource", "group"}),
}
}
func (m *builderMetrics) recordDualWriterModes(resource, group string, targetMode, currentMode grafanarest.DualWriterMode) {
m.dualWriterTargetMode.WithLabelValues(resource, group).Set(float64(targetMode))
m.dualWriterCurrentMode.WithLabelValues(resource, group).Set(float64(currentMode))
}
+2 -2
View File
@@ -27,7 +27,6 @@ import (
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/serverlock"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/middleware"
@@ -122,6 +121,7 @@ func ProvideService(
restConfigProvider RestConfigProvider,
buildHandlerChainFuncFromBuilders builder.BuildHandlerChainFuncFromBuilders,
eventualRestConfigProvider *eventualRestConfigProvider,
reg prometheus.Registerer,
) (*service, error) {
scheme := builder.ProvideScheme()
codecs := builder.ProvideCodecFactory(scheme)
@@ -137,7 +137,7 @@ func ProvideService(
authorizer: authorizer.NewGrafanaAuthorizer(cfg),
tracing: tracing,
db: db, // For Unified storage
metrics: metrics.ProvideRegisterer(),
metrics: reg,
kvStore: kvStore,
pluginClient: pluginClient,
datasources: datasources,