Alerting: Use folder_uid instead of file for Grafana managed alert rules (#88497)

This commit is contained in:
Gilles De Mey 2024-06-05 12:46:23 +02:00 committed by GitHub
parent cd5f485df7
commit 33d4e59ffb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,5 @@
import { set } from 'lodash';
import { RelativeTimeRange } from '@grafana/data';
import { Matcher } from 'app/plugins/datasource/alertmanager/types';
import { RuleIdentifier, RuleNamespace, RulerDataSourceConfig } from 'app/types/unified-alerting';
@ -17,7 +19,7 @@ import {
import { ExportFormats } from '../components/export/providers';
import { Folder } from '../components/rule-editor/RuleFolderPicker';
import { getDatasourceAPIUid, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';
import { getDatasourceAPIUid, GRAFANA_RULES_SOURCE_NAME, isGrafanaRulesSource } from '../utils/datasource';
import { arrayKeyValuesToObject } from '../utils/labels';
import { isCloudRuleIdentifier, isPrometheusRuleIdentifier } from '../utils/rules';
@ -174,13 +176,20 @@ export const alertRuleApi = alertingApi.injectEndpoints({
>({
query: ({ ruleSourceName, namespace, groupName, ruleName, dashboardUid, panelId }) => {
const queryParams: Record<string, string | undefined> = {
file: namespace,
rule_group: groupName,
rule_name: ruleName,
dashboard_uid: dashboardUid, // Supported only by Grafana managed rules
panel_id: panelId?.toString(), // Supported only by Grafana managed rules
};
if (namespace) {
if (isGrafanaRulesSource(ruleSourceName)) {
set(queryParams, 'folder_uid', namespace);
} else {
set(queryParams, 'file', namespace);
}
}
return {
url: `api/prometheus/${getDatasourceAPIUid(ruleSourceName)}/api/v1/rules`,
params: queryParams,