Alerting: Remove feature toggles relating to Loki Alert State History (#103540)
* Remove feature toggles relating to Loki Alert State History
This commit is contained in:
@@ -41,7 +41,7 @@ func ProvideService(
|
||||
write := xormStore
|
||||
|
||||
var read readStore
|
||||
historianStore := loki.NewLokiHistorianStore(cfg.UnifiedAlerting.StateHistory, features, db, ruleStore, log.New("annotations.loki"), tracer)
|
||||
historianStore := loki.NewLokiHistorianStore(cfg.UnifiedAlerting.StateHistory, db, ruleStore, log.New("annotations.loki"), tracer)
|
||||
if historianStore != nil {
|
||||
l.Debug("Using composite read store")
|
||||
read = NewCompositeStore(log.New("annotations.composite"), xormStore, historianStore)
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/services/annotations/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
@@ -58,8 +56,8 @@ type LokiHistorianStore struct {
|
||||
ruleStore RuleStore
|
||||
}
|
||||
|
||||
func NewLokiHistorianStore(cfg setting.UnifiedAlertingStateHistorySettings, ft featuremgmt.FeatureToggles, db db.DB, ruleStore RuleStore, log log.Logger, tracer tracing.Tracer) *LokiHistorianStore {
|
||||
if !useStore(cfg, ft) {
|
||||
func NewLokiHistorianStore(cfg setting.UnifiedAlertingStateHistorySettings, db db.DB, ruleStore RuleStore, log log.Logger, tracer tracing.Tracer) *LokiHistorianStore {
|
||||
if !useStore(cfg) {
|
||||
return nil
|
||||
}
|
||||
lokiCfg, err := historian.NewLokiConfig(cfg)
|
||||
@@ -294,22 +292,16 @@ func buildHistoryQuery(query *annotations.ItemQuery, dashboards map[string]int64
|
||||
return historyQuery
|
||||
}
|
||||
|
||||
func useStore(cfg setting.UnifiedAlertingStateHistorySettings, ft featuremgmt.FeatureToggles) bool {
|
||||
func useStore(cfg setting.UnifiedAlertingStateHistorySettings) bool {
|
||||
if !cfg.Enabled {
|
||||
return false
|
||||
}
|
||||
|
||||
// Override config based on feature toggles.
|
||||
// We pass in a no-op logger here since this function is also called during ngalert init,
|
||||
// and we don't want to log the same info twice.
|
||||
ngalert.ApplyStateHistoryFeatureToggles(&cfg, ft, log.NewNopLogger())
|
||||
|
||||
backend, err := historian.ParseBackendType(cfg.Backend)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// We should only query Loki if annotations do not exist in the database.
|
||||
// To be doubly sure, ensure that the feature toggle to only use Loki is enabled.
|
||||
return backend == historian.BackendTypeLoki && ft.IsEnabledGlobally(featuremgmt.FlagAlertStateHistoryLokiOnly)
|
||||
return backend == historian.BackendTypeLoki
|
||||
}
|
||||
|
||||
@@ -872,7 +872,7 @@ func TestUseStore(t *testing.T) {
|
||||
cfg := setting.UnifiedAlertingStateHistorySettings{
|
||||
Enabled: false,
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
|
||||
@@ -882,7 +882,7 @@ func TestUseStore(t *testing.T) {
|
||||
Enabled: true,
|
||||
Backend: "invalid-backend",
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
|
||||
@@ -892,7 +892,7 @@ func TestUseStore(t *testing.T) {
|
||||
Backend: "multiple",
|
||||
MultiPrimary: "invalid-backend",
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
|
||||
@@ -903,7 +903,7 @@ func TestUseStore(t *testing.T) {
|
||||
MultiPrimary: "annotations",
|
||||
MultiSecondaries: []string{"annotations", "invalid-backend"},
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
})
|
||||
@@ -913,7 +913,7 @@ func TestUseStore(t *testing.T) {
|
||||
Enabled: true,
|
||||
Backend: "annotations",
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
|
||||
@@ -924,7 +924,7 @@ func TestUseStore(t *testing.T) {
|
||||
Backend: "multiple",
|
||||
MultiPrimary: "loki",
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
|
||||
@@ -935,7 +935,7 @@ func TestUseStore(t *testing.T) {
|
||||
MultiPrimary: "annotations",
|
||||
MultiSecondaries: []string{"loki"},
|
||||
}
|
||||
use := useStore(cfg, featuremgmt.WithFeatures())
|
||||
use := useStore(cfg)
|
||||
require.False(t, use)
|
||||
})
|
||||
})
|
||||
@@ -946,12 +946,7 @@ func TestUseStore(t *testing.T) {
|
||||
Enabled: true,
|
||||
Backend: "loki",
|
||||
}
|
||||
features := featuremgmt.WithFeatures(
|
||||
featuremgmt.FlagAlertStateHistoryLokiOnly,
|
||||
featuremgmt.FlagAlertStateHistoryLokiPrimary,
|
||||
featuremgmt.FlagAlertStateHistoryLokiSecondary,
|
||||
)
|
||||
use := useStore(cfg, features)
|
||||
use := useStore(cfg)
|
||||
require.True(t, use)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user