From 68f2f52d9a3ea0118877fbaed706e6673f3c62ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Hern=C3=A1ndez?= Date: Mon, 15 Dec 2025 13:42:40 +0100 Subject: [PATCH] add a FE feature toggle to get a 'compact' response from the /rules endpoint --- .../grafana-data/src/types/featureToggles.gen.ts | 5 +++++ pkg/services/featuremgmt/registry.go | 7 +++++++ pkg/services/featuremgmt/toggles_gen.csv | 1 + pkg/services/featuremgmt/toggles_gen.go | 4 ++++ pkg/services/featuremgmt/toggles_gen.json | 16 ++++++++++++++++ .../alerting/unified/api/prometheusApi.ts | 3 +++ .../unified/rule-list/GrafanaGroupLoader.tsx | 2 ++ .../rule-list/hooks/prometheusGroupsGenerator.ts | 2 ++ 8 files changed, 40 insertions(+) diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index 4aeb394b81f..da1b38d7990 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -422,6 +422,11 @@ export interface FeatureToggles { */ alertingQueryOptimization?: boolean; /** + * Returns compact API responses for alert rules list, reducing payload size by omitting the query, notification settings, and metadata + * @default false + */ + alertingCompactRulesResponse?: boolean; + /** * Distributes alert rule evaluations more evenly over time, including spreading out rules within the same group. Disables sequential evaluation if enabled. */ jitterAlertRulesWithinGroups?: boolean; diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index c1b318c97b4..c7a9b9adaa2 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -686,6 +686,13 @@ var ( Owner: grafanaAlertingSquad, Expression: "false", }, + { + Name: "alertingCompactRulesResponse", + Description: "Returns compact API responses for alert rules list, reducing payload size by omitting the query, notification settings, and metadata", + Stage: FeatureStageExperimental, + Owner: grafanaAlertingSquad, + Expression: "false", + }, { Name: "jitterAlertRulesWithinGroups", Description: "Distributes alert rule evaluations more evenly over time, including spreading out rules within the same group. Disables sequential evaluation if enabled.", diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index f05b0d41da3..fccb0298a28 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -95,6 +95,7 @@ tableSharedCrosshair,experimental,@grafana/dataviz-squad,false,false,true kubernetesFeatureToggles,experimental,@grafana/grafana-operator-experience-squad,false,false,true cloudRBACRoles,preview,@grafana/identity-access-team,false,true,false alertingQueryOptimization,GA,@grafana/alerting-squad,false,false,false +alertingCompactRulesResponse,experimental,@grafana/alerting-squad,false,false,false jitterAlertRulesWithinGroups,preview,@grafana/alerting-squad,false,true,false secretsManagementAppPlatform,experimental,@grafana/grafana-operator-experience-squad,false,false,false secretsManagementAppPlatformUI,experimental,@grafana/grafana-operator-experience-squad,false,false,false diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 6e106fd9950..c7d31315272 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -279,6 +279,10 @@ const ( // Optimizes eligible queries in order to reduce load on datasources FlagAlertingQueryOptimization = "alertingQueryOptimization" + // FlagAlertingCompactRulesResponse + // Returns compact API responses for alert rules list, reducing payload size by omitting the query, notification settings, and metadata + FlagAlertingCompactRulesResponse = "alertingCompactRulesResponse" + // FlagJitterAlertRulesWithinGroups // Distributes alert rule evaluations more evenly over time, including spreading out rules within the same group. Disables sequential evaluation if enabled. FlagJitterAlertRulesWithinGroups = "jitterAlertRulesWithinGroups" diff --git a/pkg/services/featuremgmt/toggles_gen.json b/pkg/services/featuremgmt/toggles_gen.json index 561ffd562ca..e4c355528c1 100644 --- a/pkg/services/featuremgmt/toggles_gen.json +++ b/pkg/services/featuremgmt/toggles_gen.json @@ -195,6 +195,22 @@ "codeowner": "@grafana/alerting-squad" } }, + { + "metadata": { + "name": "alertingCompactRulesResponse", + "resourceVersion": "1765802340688", + "creationTimestamp": "2025-12-15T12:24:06Z", + "annotations": { + "grafana.app/updatedTimestamp": "2025-12-15 12:39:00.688866597 +0000 UTC" + } + }, + "spec": { + "description": "Returns compact API responses for alert rules list, reducing payload size by omitting the query, notification settings, and metadata", + "stage": "experimental", + "codeowner": "@grafana/alerting-squad", + "expression": "false" + } + }, { "metadata": { "name": "alertingDisableSendAlertsExternal", diff --git a/public/app/features/alerting/unified/api/prometheusApi.ts b/public/app/features/alerting/unified/api/prometheusApi.ts index 3c4fe219dd0..cd252364c14 100644 --- a/public/app/features/alerting/unified/api/prometheusApi.ts +++ b/public/app/features/alerting/unified/api/prometheusApi.ts @@ -47,6 +47,7 @@ export type GrafanaPromRulesOptions = Omit ({ url: `api/prometheus/grafana/api/v1/rules`, params: { @@ -120,6 +122,7 @@ export const prometheusApi = alertingApi.injectEndpoints({ 'search.rule_name': title, 'search.rule_group': searchGroupName, dashboard_uid: dashboardUid, + compact: compact, }, }), providesTags: (_result, _error, { folderUid, groupName, ruleName }) => { diff --git a/public/app/features/alerting/unified/rule-list/GrafanaGroupLoader.tsx b/public/app/features/alerting/unified/rule-list/GrafanaGroupLoader.tsx index a92b67822d2..670670d6801 100644 --- a/public/app/features/alerting/unified/rule-list/GrafanaGroupLoader.tsx +++ b/public/app/features/alerting/unified/rule-list/GrafanaGroupLoader.tsx @@ -3,6 +3,7 @@ import { useMemo } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { t } from '@grafana/i18n'; +import { config } from '@grafana/runtime'; import { Alert, Stack, useStyles2 } from '@grafana/ui'; import { GrafanaRuleGroupIdentifier } from 'app/types/unified-alerting'; @@ -44,6 +45,7 @@ export function GrafanaGroupLoader({ folderUid: groupIdentifier.namespace.uid, groupName: groupIdentifier.groupName, limitAlerts: 0, + compact: config.featureToggles.alertingCompactRulesResponse, }, { pollingInterval: RULE_LIST_POLL_INTERVAL_MS } ); diff --git a/public/app/features/alerting/unified/rule-list/hooks/prometheusGroupsGenerator.ts b/public/app/features/alerting/unified/rule-list/hooks/prometheusGroupsGenerator.ts index add1097fa0f..61d4ebf1f0a 100644 --- a/public/app/features/alerting/unified/rule-list/hooks/prometheusGroupsGenerator.ts +++ b/public/app/features/alerting/unified/rule-list/hooks/prometheusGroupsGenerator.ts @@ -1,6 +1,7 @@ import { useCallback } from 'react'; import { MergeExclusive } from 'type-fest'; +import { config } from '@grafana/runtime'; import { DataSourceRulesSourceIdentifier, RuleHealth } from 'app/types/unified-alerting'; import { PromAlertingRuleState, PromRuleGroupDTO } from 'app/types/unified-alerting-dto'; @@ -76,6 +77,7 @@ export function useGrafanaGroupsGenerator(hookOptions: UseGeneratorHookOptions = ...fetchOptions, limitAlerts: hookOptions.limitAlerts, ...fetchOptions.filter, + compact: config.featureToggles.alertingCompactRulesResponse, }).unwrap(); if (hookOptions.populateCache) {