add feature toggle

pull/107644/head
Vadim Stepanov 4 days ago
parent 147998d178
commit de7af8f755
No known key found for this signature in database
  1. 5
      packages/grafana-data/src/types/featureToggles.gen.ts
  2. 9
      pkg/services/featuremgmt/registry.go
  3. 1
      pkg/services/featuremgmt/toggles_gen.csv
  4. 4
      pkg/services/featuremgmt/toggles_gen.go
  5. 15
      pkg/services/featuremgmt/toggles_gen.json
  6. 6
      pkg/services/ngalert/ngalert.go
  7. 46
      pkg/services/ngalert/ngalert_test.go

@ -1026,4 +1026,9 @@ export interface FeatureToggles {
* @default false
*/
enablePluginImporter?: boolean;
/**
* Enables the notification history feature
* @default false
*/
alertingNotificationHistory?: boolean;
}

@ -1765,6 +1765,15 @@ var (
FrontendOnly: true,
Expression: "false",
},
{
Name: "alertingNotificationHistory",
Description: "Enables the notification history feature",
Stage: FeatureStageExperimental,
Owner: grafanaAlertingSquad,
HideFromAdminPage: true,
HideFromDocs: true,
Expression: "false",
},
}
)

@ -229,3 +229,4 @@ newInfluxDSConfigPageDesign,privatePreview,@grafana/partner-datasources,false,fa
enableAppChromeExtensions,experimental,@grafana/plugins-platform-backend,false,false,true
foldersAppPlatformAPI,experimental,@grafana/grafana-search-navigate-organise,false,false,true
enablePluginImporter,experimental,@grafana/plugins-platform-backend,false,false,true
alertingNotificationHistory,experimental,@grafana/alerting-squad,false,false,false

1 Name Stage Owner requiresDevMode RequiresRestart FrontendOnly
229 enableAppChromeExtensions experimental @grafana/plugins-platform-backend false false true
230 foldersAppPlatformAPI experimental @grafana/grafana-search-navigate-organise false false true
231 enablePluginImporter experimental @grafana/plugins-platform-backend false false true
232 alertingNotificationHistory experimental @grafana/alerting-squad false false false

@ -926,4 +926,8 @@ const (
// FlagEnablePluginImporter
// Set this to true to use the new PluginImporter functionality
FlagEnablePluginImporter = "enablePluginImporter"
// FlagAlertingNotificationHistory
// Enables the notification history feature
FlagAlertingNotificationHistory = "alertingNotificationHistory"
)

@ -222,6 +222,21 @@
"expression": "true"
}
},
{
"metadata": {
"name": "alertingNotificationHistory",
"resourceVersion": "1752677257304",
"creationTimestamp": "2025-07-16T14:47:37Z"
},
"spec": {
"description": "Enables the notification history feature",
"stage": "experimental",
"codeowner": "@grafana/alerting-squad",
"hideFromAdminPage": true,
"hideFromDocs": true,
"expression": "false"
}
},
{
"metadata": {
"name": "alertingNotificationsStepMode",

@ -287,6 +287,7 @@ func (ng *AlertNG) init() error {
notificationHistorian, err := configureNotificationHistorian(
initCtx,
ng.FeatureToggles,
ng.Cfg.UnifiedAlerting.NotificationHistory,
ng.Metrics.GetNotificationHistorianMetrics(),
ng.Log,
@ -732,11 +733,16 @@ func configureHistorianBackend(
func configureNotificationHistorian(
ctx context.Context,
featureToggles featuremgmt.FeatureToggles,
cfg setting.UnifiedAlertingNotificationHistorySettings,
met *metrics.NotificationHistorian,
l log.Logger,
tracer tracing.Tracer,
) (*notifier.NotificationHistorian, error) {
if !featureToggles.IsEnabled(ctx, featuremgmt.FlagAlertingNotificationHistory) {
return nil, nil
}
if !cfg.Enabled {
met.Info.Set(0)
return nil, nil

@ -240,6 +240,7 @@ func TestConfigureNotificationHistorian(t *testing.T) {
met := metrics.NewNotificationHistorianMetrics(reg)
logger := log.NewNopLogger()
tracer := tracing.InitializeTracerForTest()
ft := featuremgmt.WithFeatures(featuremgmt.FlagAlertingNotificationHistory)
cfg := setting.UnifiedAlertingNotificationHistorySettings{
Enabled: true,
LokiSettings: setting.UnifiedAlertingLokiSettings{
@ -248,7 +249,7 @@ func TestConfigureNotificationHistorian(t *testing.T) {
},
}
h, err := configureNotificationHistorian(context.Background(), cfg, met, logger, tracer)
h, err := configureNotificationHistorian(context.Background(), ft, cfg, met, logger, tracer)
require.NotNil(t, h)
require.NoError(t, err)
@ -263,25 +264,42 @@ grafana_alerting_notification_history_info 1
})
t.Run("emit special zero metric if notification history disabled", func(t *testing.T) {
reg := prometheus.NewRegistry()
met := metrics.NewNotificationHistorianMetrics(reg)
logger := log.NewNopLogger()
tracer := tracing.InitializeTracerForTest()
cfg := setting.UnifiedAlertingNotificationHistorySettings{
Enabled: false,
testCases := []struct {
name string
ft featuremgmt.FeatureToggles
cfg setting.UnifiedAlertingNotificationHistorySettings
}{
{
"disabled via config",
featuremgmt.WithFeatures(featuremgmt.FlagAlertingNotificationHistory),
setting.UnifiedAlertingNotificationHistorySettings{Enabled: false},
},
{
"disabled via feature toggle",
featuremgmt.WithFeatures(),
setting.UnifiedAlertingNotificationHistorySettings{Enabled: true},
},
}
h, err := configureNotificationHistorian(context.Background(), cfg, met, logger, tracer)
require.Nil(t, h)
require.NoError(t, err)
exp := bytes.NewBufferString(`
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
reg := prometheus.NewRegistry()
met := metrics.NewNotificationHistorianMetrics(reg)
logger := log.NewNopLogger()
tracer := tracing.InitializeTracerForTest()
h, err := configureNotificationHistorian(context.Background(), tc.ft, tc.cfg, met, logger, tracer)
require.Nil(t, h)
require.NoError(t, err)
exp := bytes.NewBufferString(`
# HELP grafana_alerting_notification_history_info Information about the notification history store.
# TYPE grafana_alerting_notification_history_info gauge
grafana_alerting_notification_history_info 0
`)
err = testutil.GatherAndCompare(reg, exp, "grafana_alerting_notification_history_info")
require.NoError(t, err)
err = testutil.GatherAndCompare(reg, exp, "grafana_alerting_notification_history_info")
require.NoError(t, err)
})
}
})
}

Loading…
Cancel
Save