mirror of https://github.com/grafana/grafana.git
add feature toggle
This commit is contained in:
parent
147998d178
commit
de7af8f755
|
@ -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
|
||||
|
|
|
|
@ -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,15 +264,30 @@ grafana_alerting_notification_history_info 1
|
|||
})
|
||||
|
||||
t.Run("emit special zero metric if notification history disabled", func(t *testing.T) {
|
||||
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},
|
||||
},
|
||||
}
|
||||
|
||||
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()
|
||||
cfg := setting.UnifiedAlertingNotificationHistorySettings{
|
||||
Enabled: false,
|
||||
}
|
||||
|
||||
h, err := configureNotificationHistorian(context.Background(), cfg, met, logger, tracer)
|
||||
h, err := configureNotificationHistorian(context.Background(), tc.ft, tc.cfg, met, logger, tracer)
|
||||
require.Nil(t, h)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -283,6 +299,8 @@ grafana_alerting_notification_history_info 0
|
|||
err = testutil.GatherAndCompare(reg, exp, "grafana_alerting_notification_history_info")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type mockDB struct {
|
||||
|
|
Loading…
Reference in New Issue