From 2eaada17db363d5acbf2b177766688af9e5ae5b8 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:50:29 +0100 Subject: [PATCH] Alerting: Track if new gm rules are created with queries and expressions transformable to simple mode (#101121) track if new gm rules are created with queries and expressions transformable to simple mode --- .../app/features/alerting/unified/Analytics.ts | 1 + .../alert-rule-form/AlertRuleForm.tsx | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/public/app/features/alerting/unified/Analytics.ts b/public/app/features/alerting/unified/Analytics.ts index 25e7e973c83..9f3cf849cda 100644 --- a/public/app/features/alerting/unified/Analytics.ts +++ b/public/app/features/alerting/unified/Analytics.ts @@ -197,6 +197,7 @@ export const trackAlertRuleFormError = ( export const trackNewGrafanaAlertRuleFormSavedSuccess = (payload: { simplifiedQueryEditor: boolean; simplifiedNotificationEditor: boolean; + canBeTransformedToSimpleQuery: boolean; }) => { reportInteraction('grafana_alerting_grafana_rule_creation_new_success', payload); }; diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx index 2a9846b0e62..c838e6231ea 100644 --- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx @@ -22,6 +22,7 @@ import { isGrafanaRulerRulePaused, isRecordingRuleByType, } from 'app/features/alerting/unified/utils/rules'; +import { isExpressionQuery } from 'app/features/expressions/guards'; import { RuleGroupIdentifier, RuleIdentifier, RuleWithLocation } from 'app/types/unified-alerting'; import { PostableRuleGrafanaRuleDTO, RulerRuleDTO } from 'app/types/unified-alerting-dto'; @@ -45,6 +46,10 @@ import { formValuesFromPrefill, translateRouteParamToRuleType, } from '../../../rule-editor/formDefaults'; +import { + areQueriesTransformableToSimpleCondition, + isExpressionQueryInAlert, +} from '../../../rule-editor/formProcessing'; import { RuleFormType, RuleFormValues } from '../../../types/rule-form'; import { MANUAL_ROUTING_KEY, @@ -155,13 +160,20 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => { if (!existing) { // when creating a new rule, we save the manual routing setting , and editorSettings.simplifiedQueryEditor to the local storage storeInLocalStorageValues(values); + // save the rule to the rule group await addRuleToRuleGroup.execute(ruleGroupIdentifier, ruleDefinition, evaluateEvery); - grafanaTypeRule && + // track the new Grafana-managed rule creation in the analytics + if (grafanaTypeRule) { + const dataQueries = values.queries.filter((query) => !isExpressionQuery(query.model)); + const expressionQueries = values.queries.filter((query) => isExpressionQueryInAlert(query)); trackNewGrafanaAlertRuleFormSavedSuccess({ simplifiedQueryEditor: values.editorSettings?.simplifiedQueryEditor ?? false, simplifiedNotificationEditor: values.editorSettings?.simplifiedNotificationEditor ?? false, - }); // new Grafana-managed rule + canBeTransformedToSimpleQuery: areQueriesTransformableToSimpleCondition(dataQueries, expressionQueries), + }); + } } else { + // when updating an existing rule const ruleIdentifier = fromRulerRuleAndRuleGroupIdentifier(ruleGroupIdentifier, existing.rule); await updateRuleInRuleGroup.execute( ruleGroupIdentifier,