Don't use prometheus.DefaultRegisterer in annotationsimpl/loki. (#107311)
* Don't use prometheus.DefaultRegisterer in annotationsimpl/loki.
This commit is contained in:
@@ -3,6 +3,8 @@ package annotationsimpl
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/annotations/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/annotations/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl/loki"
|
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl/loki"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
@@ -33,6 +35,7 @@ func ProvideService(
|
|||||||
tracer tracing.Tracer,
|
tracer tracing.Tracer,
|
||||||
ruleStore *alertingStore.DBstore,
|
ruleStore *alertingStore.DBstore,
|
||||||
dashSvc dashboards.DashboardService,
|
dashSvc dashboards.DashboardService,
|
||||||
|
reg prometheus.Registerer,
|
||||||
) *RepositoryImpl {
|
) *RepositoryImpl {
|
||||||
l := log.New("annotations")
|
l := log.New("annotations")
|
||||||
l.Debug("Initializing annotations service")
|
l.Debug("Initializing annotations service")
|
||||||
@@ -41,7 +44,7 @@ func ProvideService(
|
|||||||
write := xormStore
|
write := xormStore
|
||||||
|
|
||||||
var read readStore
|
var read readStore
|
||||||
historianStore := loki.NewLokiHistorianStore(cfg.UnifiedAlerting.StateHistory, db, ruleStore, log.New("annotations.loki"), tracer)
|
historianStore := loki.NewLokiHistorianStore(cfg.UnifiedAlerting.StateHistory, db, ruleStore, log.New("annotations.loki"), tracer, reg)
|
||||||
if historianStore != nil {
|
if historianStore != nil {
|
||||||
l.Debug("Using composite read store")
|
l.Debug("Using composite read store")
|
||||||
read = NewCompositeStore(log.New("annotations.composite"), xormStore, historianStore)
|
read = NewCompositeStore(log.New("annotations.composite"), xormStore, historianStore)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@@ -70,7 +71,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
|||||||
kvstore.NewFakeKVStore())
|
kvstore.NewFakeKVStore())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashSvc.RegisterDashboardPermissions(accesscontrolmock.NewMockedPermissionsService())
|
dashSvc.RegisterDashboardPermissions(accesscontrolmock.NewMockedPermissionsService())
|
||||||
repo := ProvideService(sql, cfg, features, tagService, tracing.InitializeTracerForTest(), ruleStore, dashSvc)
|
repo := ProvideService(sql, cfg, features, tagService, tracing.InitializeTracerForTest(), ruleStore, dashSvc, prometheus.NewPedanticRegistry())
|
||||||
|
|
||||||
dashboard1 := testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
dashboard1 := testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
@@ -344,7 +345,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
|||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
cfg.AnnotationMaximumTagsLength = 60
|
cfg.AnnotationMaximumTagsLength = 60
|
||||||
ruleStore := alertingStore.SetupStoreForTesting(t, sql)
|
ruleStore := alertingStore.SetupStoreForTesting(t, sql)
|
||||||
repo := ProvideService(sql, cfg, tc.features, tagimpl.ProvideService(sql), tracing.InitializeTracerForTest(), ruleStore, dashSvc)
|
repo := ProvideService(sql, cfg, tc.features, tagimpl.ProvideService(sql), tracing.InitializeTracerForTest(), ruleStore, dashSvc, prometheus.NewPedanticRegistry())
|
||||||
|
|
||||||
usr.Permissions = map[int64]map[string][]string{1: tc.permissions}
|
usr.Permissions = map[int64]map[string][]string{1: tc.permissions}
|
||||||
testutil.SetupRBACPermission(t, sql, role, usr)
|
testutil.SetupRBACPermission(t, sql, role, usr)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ type LokiHistorianStore struct {
|
|||||||
ruleStore RuleStore
|
ruleStore RuleStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLokiHistorianStore(cfg setting.UnifiedAlertingStateHistorySettings, db db.DB, ruleStore RuleStore, log log.Logger, tracer tracing.Tracer) *LokiHistorianStore {
|
func NewLokiHistorianStore(cfg setting.UnifiedAlertingStateHistorySettings, db db.DB, ruleStore RuleStore, log log.Logger, tracer tracing.Tracer, reg prometheus.Registerer) *LokiHistorianStore {
|
||||||
if !useStore(cfg) {
|
if !useStore(cfg) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ func NewLokiHistorianStore(cfg setting.UnifiedAlertingStateHistorySettings, db d
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &LokiHistorianStore{
|
return &LokiHistorianStore{
|
||||||
client: historian.NewLokiClient(lokiCfg, historian.NewRequester(), ngmetrics.NewHistorianMetrics(prometheus.DefaultRegisterer, subsystem), log, tracer),
|
client: historian.NewLokiClient(lokiCfg, historian.NewRequester(), ngmetrics.NewHistorianMetrics(reg, subsystem), log, tracer),
|
||||||
db: db,
|
db: db,
|
||||||
log: log,
|
log: log,
|
||||||
ruleStore: ruleStore,
|
ruleStore: ruleStore,
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package service
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
@@ -35,7 +37,7 @@ func newPublicDashboardServiceImpl(
|
|||||||
}
|
}
|
||||||
tagService := tagimpl.ProvideService(store)
|
tagService := tagimpl.ProvideService(store)
|
||||||
if annotationsRepo == nil {
|
if annotationsRepo == nil {
|
||||||
annotationsRepo = annotationsimpl.ProvideService(store, cfg, featuremgmt.WithFeatures(), tagService, tracing.InitializeTracerForTest(), nil, dashboardService)
|
annotationsRepo = annotationsimpl.ProvideService(store, cfg, featuremgmt.WithFeatures(), tagService, tracing.InitializeTracerForTest(), nil, dashboardService, prometheus.NewPedanticRegistry())
|
||||||
}
|
}
|
||||||
|
|
||||||
if publicDashboardStore == nil {
|
if publicDashboardStore == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user