From 9c15662cf6337b37f2932cf7b20fe5e05d310153 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:42:42 +0200 Subject: [PATCH] Alerting: Add AI buttons in some alerting workflows (#107754) * Add alerting ai buttons for cloud * add tracking for ai buttons usage * Empty commit to trigger GitHub Actions * add FrontendOnly in ff * update analytics folder * prettier * revert ff being frontend only * review comments * address some review comments * refactor * revert change and remove comment * prettier * update betterer * remove unused property * prettier * address review comments * prettier * update test * fix linter errors * add translations * prettier * update workspace --------- Co-authored-by: Gilles De Mey --- .betterer.results | 3 - go.mod | 2 +- go.sum | 4 +- .../src/types/featureToggles.gen.ts | 20 +++++ pkg/services/featuremgmt/registry.go | 36 ++++++++ pkg/services/featuremgmt/toggles_gen.csv | 4 + pkg/services/featuremgmt/toggles_gen.go | 16 ++++ pkg/services/featuremgmt/toggles_gen.json | 89 +++++++++++++++++++ .../components/receivers/TemplateForm.tsx | 12 +++ .../rule-editor/AnnotationsStep.tsx | 3 + .../rule-editor/labels/LabelsFieldInForm.tsx | 29 +++--- .../EventListSceneObject.tsx | 69 ++++++++------ .../addAIAlertRuleButton.test.tsx | 47 ++++++++++ .../addAIAlertRuleButton.ts | 30 +++++++ .../addAIImproveAnnotationsButton.test.tsx | 51 +++++++++++ .../addAIImproveAnnotationsButton.ts | 30 +++++++ .../addAIImproveLabelsButton.test.tsx | 51 +++++++++++ .../addAIImproveLabelsButton.ts | 30 +++++++ .../addAITemplateButton.test.tsx | 52 +++++++++++ .../addAITemplateButton.ts | 33 +++++++ .../addAITriageButton.test.tsx | 61 +++++++++++++ .../AI/AIGenTriageButton/addAITriageButton.ts | 34 +++++++ .../unified/rule-list/RuleList.v1.tsx | 18 ++-- .../unified/rule-list/RuleList.v2.tsx | 2 + .../dashboard/components/GenAI/hooks.ts | 2 +- public/locales/en-US/grafana.json | 9 ++ 26 files changed, 684 insertions(+), 53 deletions(-) create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenAlertRuleButton/addAIAlertRuleButton.test.tsx create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenAlertRuleButton/addAIAlertRuleButton.ts create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenImproveAnnotationsButton/addAIImproveAnnotationsButton.test.tsx create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenImproveAnnotationsButton/addAIImproveAnnotationsButton.ts create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenImproveLabelsButton/addAIImproveLabelsButton.test.tsx create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenImproveLabelsButton/addAIImproveLabelsButton.ts create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenTemplateButton/addAITemplateButton.test.tsx create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenTemplateButton/addAITemplateButton.ts create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenTriageButton/addAITriageButton.test.tsx create mode 100644 public/app/features/alerting/unified/enterprise-components/AI/AIGenTriageButton/addAITriageButton.ts diff --git a/.betterer.results b/.betterer.results index 8c04156fcf0..ca7e75b3558 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1280,9 +1280,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/components/rule-editor/AnnotationKeyInput.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.tsx:5381": [ - [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "0"] - ], "public/app/features/alerting/unified/components/rule-editor/CloudEvaluationBehavior.tsx:5381": [ [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "0"], [0, 0, 0, "Add noMargin prop to Field components to remove built-in margins. Use layout components like Stack or Grid with the gap prop instead for consistent spacing.", "1"] diff --git a/go.mod b/go.mod index 7de0ab6300c..88da5c2be7a 100644 --- a/go.mod +++ b/go.mod @@ -230,7 +230,7 @@ require ( require ( github.com/grafana/grafana/apps/advisor v0.0.0-20250627191313-2f1a6ae1712b // @grafana/plugins-platform-backend github.com/grafana/grafana/apps/alerting/notifications v0.0.0-20250627191313-2f1a6ae1712b // @grafana/alerting-backend - github.com/grafana/grafana/apps/dashboard v0.0.0-20250627191313-2f1a6ae1712b // @grafana/grafana-app-platform-squad @grafana/dashboards-squad + github.com/grafana/grafana/apps/dashboard v0.0.0-20250716152245-2202c99d7030 // @grafana/grafana-app-platform-squad @grafana/dashboards-squad github.com/grafana/grafana/apps/folder v0.0.0-20250627191313-2f1a6ae1712b // @grafana/grafana-search-and-storage github.com/grafana/grafana/apps/iam v0.0.0-20250627191313-2f1a6ae1712b // @grafana/identity-access-team github.com/grafana/grafana/apps/investigations v0.0.0-20250627191313-2f1a6ae1712b // @fcjack @matryer diff --git a/go.sum b/go.sum index fa234616138..95c6d9f5c9c 100644 --- a/go.sum +++ b/go.sum @@ -1611,8 +1611,8 @@ github.com/grafana/grafana/apps/advisor v0.0.0-20250627191313-2f1a6ae1712b h1:8o github.com/grafana/grafana/apps/advisor v0.0.0-20250627191313-2f1a6ae1712b/go.mod h1:q+h3HbmqU/PposW6lq8cMle1v8vuyX1LCMrGzbabHxc= github.com/grafana/grafana/apps/alerting/notifications v0.0.0-20250627191313-2f1a6ae1712b h1:jr+C3epmjhd5Yyob4P1Z/dPaW4LRTkU5UJLXsI4eaeM= github.com/grafana/grafana/apps/alerting/notifications v0.0.0-20250627191313-2f1a6ae1712b/go.mod h1:WpI7TCck4P2wKTO2WJLBRcfOWvUGvTdxYu3QqS3z7jM= -github.com/grafana/grafana/apps/dashboard v0.0.0-20250627191313-2f1a6ae1712b h1:FJHoqhrVR/PMS9xv7yYGVi73iTB1VXyV/oIXCUssvMQ= -github.com/grafana/grafana/apps/dashboard v0.0.0-20250627191313-2f1a6ae1712b/go.mod h1:eR8wca74ADgxBrvX0uNpdB1qnPaGx/KhCm4Xj8oqHfQ= +github.com/grafana/grafana/apps/dashboard v0.0.0-20250716152245-2202c99d7030 h1:ravSwl2XJacO/o2u3IVaMacd0NpL1Msf9ENLcLbLwO0= +github.com/grafana/grafana/apps/dashboard v0.0.0-20250716152245-2202c99d7030/go.mod h1:1XWiRSVuDQiayapHhQiDc4S4e9GzEZgg/3GeNCuDgn4= github.com/grafana/grafana/apps/folder v0.0.0-20250627191313-2f1a6ae1712b h1:31MwoIKKT9Ay0ZjbT4lkfcPijiWogUWzXs2EjrCgodI= github.com/grafana/grafana/apps/folder v0.0.0-20250627191313-2f1a6ae1712b/go.mod h1:dLtYBp1pza5HYalezNvzlP8JDeKrZ5BKTonDgEOE0NY= github.com/grafana/grafana/apps/iam v0.0.0-20250627191313-2f1a6ae1712b h1:NV8v9xdM/pzjjy+1cLqUseia3bYcvQGh88vZdMW/jA0= diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index 8f3a12c6703..42ffa7f1491 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -749,6 +749,26 @@ export interface FeatureToggles { */ azureMonitorEnableUserAuth?: boolean; /** + * Enable AI-generated alert rules. + * @default false + */ + alertingAIGenAlertRules?: boolean; + /** + * Enable AI-improve alert rules labels and annotations. + * @default false + */ + alertingAIImproveAlertRules?: boolean; + /** + * Enable AI-generated alerting templates. + * @default false + */ + alertingAIGenTemplates?: boolean; + /** + * Enable AI-analyze central state history. + * @default false + */ + alertingAIAnalyzeCentralStateHistory?: boolean; + /** * Enables simplified step mode in the notifications section * @default true */ diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 57084590310..172161a9cf8 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -1277,6 +1277,42 @@ var ( Owner: grafanaPartnerPluginsSquad, Expression: "true", // Enabled by default for now }, + { + Name: "alertingAIGenAlertRules", + Description: "Enable AI-generated alert rules.", + Stage: FeatureStageExperimental, + Owner: grafanaAlertingSquad, + HideFromAdminPage: true, + HideFromDocs: true, + Expression: "false", + }, + { + Name: "alertingAIImproveAlertRules", + Description: "Enable AI-improve alert rules labels and annotations.", + Stage: FeatureStageExperimental, + Owner: grafanaAlertingSquad, + HideFromAdminPage: true, + HideFromDocs: true, + Expression: "false", + }, + { + Name: "alertingAIGenTemplates", + Description: "Enable AI-generated alerting templates.", + Stage: FeatureStageExperimental, + Owner: grafanaAlertingSquad, + HideFromAdminPage: true, + HideFromDocs: true, + Expression: "false", + }, + { + Name: "alertingAIAnalyzeCentralStateHistory", + Description: "Enable AI-analyze central state history.", + Stage: FeatureStageExperimental, + Owner: grafanaAlertingSquad, + HideFromAdminPage: true, + HideFromDocs: true, + Expression: "false", + }, { Name: "alertingNotificationsStepMode", Description: "Enables simplified step mode in the notifications section", diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index d64acfc637e..db43824df5f 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -167,6 +167,10 @@ enableSCIM,preview,@grafana/identity-access-team,false,false,false crashDetection,experimental,@grafana/observability-traces-and-profiling,false,false,true alertingUIOptimizeReducer,GA,@grafana/alerting-squad,false,false,true azureMonitorEnableUserAuth,GA,@grafana/partner-datasources,false,false,false +alertingAIGenAlertRules,experimental,@grafana/alerting-squad,false,false,false +alertingAIImproveAlertRules,experimental,@grafana/alerting-squad,false,false,false +alertingAIGenTemplates,experimental,@grafana/alerting-squad,false,false,false +alertingAIAnalyzeCentralStateHistory,experimental,@grafana/alerting-squad,false,false,false alertingNotificationsStepMode,GA,@grafana/alerting-squad,false,false,true feedbackButton,experimental,@grafana/grafana-operator-experience-squad,false,false,false unifiedStorageSearchUI,experimental,@grafana/search-and-storage,false,false,false diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 197226456c5..4e5aaaf058c 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -679,6 +679,22 @@ const ( // Enables user auth for Azure Monitor datasource only FlagAzureMonitorEnableUserAuth = "azureMonitorEnableUserAuth" + // FlagAlertingAIGenAlertRules + // Enable AI-generated alert rules. + FlagAlertingAIGenAlertRules = "alertingAIGenAlertRules" + + // FlagAlertingAIImproveAlertRules + // Enable AI-improve alert rules labels and annotations. + FlagAlertingAIImproveAlertRules = "alertingAIImproveAlertRules" + + // FlagAlertingAIGenTemplates + // Enable AI-generated alerting templates. + FlagAlertingAIGenTemplates = "alertingAIGenTemplates" + + // FlagAlertingAIAnalyzeCentralStateHistory + // Enable AI-analyze central state history. + FlagAlertingAIAnalyzeCentralStateHistory = "alertingAIAnalyzeCentralStateHistory" + // FlagAlertingNotificationsStepMode // Enables simplified step mode in the notifications section FlagAlertingNotificationsStepMode = "alertingNotificationsStepMode" diff --git a/pkg/services/featuremgmt/toggles_gen.json b/pkg/services/featuremgmt/toggles_gen.json index 39af6383752..362761a9ee1 100644 --- a/pkg/services/featuremgmt/toggles_gen.json +++ b/pkg/services/featuremgmt/toggles_gen.json @@ -71,6 +71,78 @@ "expression": "false" } }, + { + "metadata": { + "name": "alertingAIAnalyzeCentralStateHistory", + "resourceVersion": "1752215431801", + "creationTimestamp": "2025-07-07T14:40:14Z", + "annotations": { + "grafana.app/updatedTimestamp": "2025-07-11 06:30:31.801024 +0000 UTC" + } + }, + "spec": { + "description": "Enable AI-analyze central state history.", + "stage": "experimental", + "codeowner": "@grafana/alerting-squad", + "hideFromAdminPage": true, + "hideFromDocs": true, + "expression": "false" + } + }, + { + "metadata": { + "name": "alertingAIGenAlertRules", + "resourceVersion": "1752215431801", + "creationTimestamp": "2025-07-07T14:40:14Z", + "annotations": { + "grafana.app/updatedTimestamp": "2025-07-11 06:30:31.801024 +0000 UTC" + } + }, + "spec": { + "description": "Enable AI-generated alert rules.", + "stage": "experimental", + "codeowner": "@grafana/alerting-squad", + "hideFromAdminPage": true, + "hideFromDocs": true, + "expression": "false" + } + }, + { + "metadata": { + "name": "alertingAIGenTemplates", + "resourceVersion": "1752215431801", + "creationTimestamp": "2025-07-07T14:40:14Z", + "annotations": { + "grafana.app/updatedTimestamp": "2025-07-11 06:30:31.801024 +0000 UTC" + } + }, + "spec": { + "description": "Enable AI-generated alerting templates.", + "stage": "experimental", + "codeowner": "@grafana/alerting-squad", + "hideFromAdminPage": true, + "hideFromDocs": true, + "expression": "false" + } + }, + { + "metadata": { + "name": "alertingAIImproveAlertRules", + "resourceVersion": "1752215431801", + "creationTimestamp": "2025-07-07T14:40:14Z", + "annotations": { + "grafana.app/updatedTimestamp": "2025-07-11 06:30:31.801024 +0000 UTC" + } + }, + "spec": { + "description": "Enable AI-improve alert rules labels and annotations.", + "stage": "experimental", + "codeowner": "@grafana/alerting-squad", + "hideFromAdminPage": true, + "hideFromDocs": true, + "expression": "false" + } + }, { "metadata": { "name": "alertingBacktesting", @@ -963,6 +1035,23 @@ "expression": "false" } }, + { + "metadata": { + "name": "enableAppChromeExtensions", + "resourceVersion": "1751899214406", + "creationTimestamp": "2025-07-07T14:40:14Z", + "deletionTimestamp": "2025-07-07T15:15:21Z" + }, + "spec": { + "description": "Set this to true to enable all app chrome extensions registered by plugins.", + "stage": "experimental", + "codeowner": "@grafana/plugins-platform-backend", + "frontend": true, + "hideFromAdminPage": true, + "hideFromDocs": true, + "expression": "false" + } + }, { "metadata": { "name": "enableDatagridEditing", diff --git a/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx b/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx index 2033b0a34a3..0d104bd528f 100644 --- a/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx +++ b/public/app/features/alerting/unified/components/receivers/TemplateForm.tsx @@ -29,6 +29,7 @@ import { useAppNotification } from 'app/core/copy/appNotification'; import { ActiveTab as ContactPointsActiveTabs } from 'app/features/alerting/unified/components/contact-points/ContactPoints'; import { TestTemplateAlert } from 'app/plugins/datasource/alertmanager/types'; +import { AITemplateButtonComponent } from '../../enterprise-components/AI/AIGenTemplateButton/addAITemplateButton'; import { GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource'; import { makeAMLink, stringifyErrorLike } from '../../utils/misc'; import { ProvisionedResource, ProvisioningAlert } from '../Provisioning'; @@ -164,6 +165,10 @@ export const TemplateForm = ({ originalTemplate, prefill, alertmanager }: Props) setValue('content', newValue); }; + const handleTemplateGenerated = (template: string) => { + setValue('content', template); + }; + return ( <> @@ -275,6 +280,13 @@ export const TemplateForm = ({ originalTemplate, prefill, alertmanager }: Props) )} + {/* GenAI button – only available for Grafana Alertmanager and enterprise */} + {isGrafanaAlertManager && ( + + )}