From 76444c7913851303d8fae61046d8c2b0d858080d Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:59:00 +0100 Subject: [PATCH] Alerting: Add alertingOptimizeReducerInUI feature toggle (#96608) add alertingOptimizeReducerInUI feature toggle --- .../configure-grafana/feature-toggles/index.md | 1 + .../src/types/featureToggles.gen.ts | 1 + pkg/services/featuremgmt/registry.go | 8 ++++++++ pkg/services/featuremgmt/toggles_gen.csv | 1 + pkg/services/featuremgmt/toggles_gen.go | 4 ++++ pkg/services/featuremgmt/toggles_gen.json | 17 +++++++++++++++++ .../QueryAndExpressionsStep.tsx | 5 +++-- 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md index 3b1ba4e21de..15d4cb8adce 100644 --- a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md +++ b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md @@ -80,6 +80,7 @@ Most [generally available](https://grafana.com/docs/release-life-cycle/#general- | `cloudwatchMetricInsightsCrossAccount` | Enables cross account observability for Cloudwatch Metric Insights query builder | Yes | | `azureMonitorDisableLogLimit` | Disables the log limit restriction for Azure Monitor when true. The limit is enabled by default. | | | `preinstallAutoUpdate` | Enables automatic updates for pre-installed plugins | Yes | +| `alertingUIOptimizeReducer` | Enables removing the reducer from the alerting UI when creating a new alert rule and using instant query | Yes | ## Public preview feature toggles diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index cb6ac1c9e56..d4725a2ddfc 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -239,4 +239,5 @@ export interface FeatureToggles { crashDetection?: boolean; jaegerBackendMigration?: boolean; reportingUseRawTimeRange?: boolean; + alertingUIOptimizeReducer?: boolean; } diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 5ded2146b25..9024c5bfe76 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -1650,6 +1650,14 @@ var ( Owner: grafanaSharingSquad, Expression: "false", // disabled by default }, + { + Name: "alertingUIOptimizeReducer", + Description: "Enables removing the reducer from the alerting UI when creating a new alert rule and using instant query", + Stage: FeatureStageGeneralAvailability, + FrontendOnly: true, + Owner: grafanaAlertingSquad, + Expression: "true", // enabled by default + }, } ) diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index aa60cb4ba3a..b51f005ccce 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -220,3 +220,4 @@ enableSCIM,experimental,@grafana/identity-access-team,false,false,false crashDetection,experimental,@grafana/observability-traces-and-profiling,false,false,true jaegerBackendMigration,experimental,@grafana/oss-big-tent,false,false,false reportingUseRawTimeRange,preview,@grafana/sharing-squad,false,false,false +alertingUIOptimizeReducer,GA,@grafana/alerting-squad,false,false,true diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 262fca16761..e4b508f069c 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -890,4 +890,8 @@ const ( // FlagReportingUseRawTimeRange // Uses the original report or dashboard time range instead of making an absolute transformation FlagReportingUseRawTimeRange = "reportingUseRawTimeRange" + + // FlagAlertingUIOptimizeReducer + // Enables removing the reducer from the alerting UI when creating a new alert rule and using instant query + FlagAlertingUIOptimizeReducer = "alertingUIOptimizeReducer" ) diff --git a/pkg/services/featuremgmt/toggles_gen.json b/pkg/services/featuremgmt/toggles_gen.json index 3c4ec27c279..ccd3b13c163 100644 --- a/pkg/services/featuremgmt/toggles_gen.json +++ b/pkg/services/featuremgmt/toggles_gen.json @@ -314,6 +314,23 @@ "expression": "true" } }, + { + "metadata": { + "name": "alertingUIOptimizeReducer", + "resourceVersion": "1731923458730", + "creationTimestamp": "2024-11-18T09:06:02Z", + "annotations": { + "grafana.app/updatedTimestamp": "2024-11-18 09:50:58.730825 +0000 UTC" + } + }, + "spec": { + "description": "Enables removing the reducer from the alerting UI when creating a new alert rule and using instant query", + "stage": "GA", + "codeowner": "@grafana/alerting-squad", + "frontend": true, + "expression": "true" + } + }, { "metadata": { "name": "alertmanagerRemoteOnly", diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx index 074ed6365e8..5bf853f9c64 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx @@ -265,6 +265,7 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P ); const updateExpressionAndDatasource = useSetExpressionAndDataSource(); + const isOptimizeReducerEnabled = config.featureToggles.alertingUIOptimizeReducer ?? false; const onChangeQueries = useCallback( (updatedQueries: AlertQuery[]) => { @@ -280,7 +281,7 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P // we only remove or add the reducer(optimize reducer) expression when creating a new alert. // When editing an alert, we assume the user wants to manually adjust expressions and queries for more control and customization. - if (!editingExistingRule) { + if (!editingExistingRule && isOptimizeReducerEnabled) { dispatch(optimizeReduceExpression({ updatedQueries, expressionQueries })); } @@ -293,7 +294,7 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P dispatch(rewireExpressions({ oldRefId, newRefId })); } }, - [queries, updateExpressionAndDatasource, getValues, setValue, editingExistingRule] + [queries, updateExpressionAndDatasource, getValues, setValue, editingExistingRule, isOptimizeReducerEnabled] ); const onChangeRecordingRulesQueries = useCallback(