Alerting: Check recording rules are enabled as well as feature toggle (#102633)

* Add `recordingRulesEnabled` to grafanaBootData

* Check for recording rules being enabled, as well as feature toggle

* Remove unnecessary config line

* Move recording rules check to featureToggles file

* Update NoRulesCTA.tsx
This commit is contained in:
Tom Ratcliffe
2025-03-26 08:59:45 +00:00
committed by GitHub
parent db50c3c5fb
commit 01c7283a88
7 changed files with 12 additions and 4 deletions

View File

@ -72,6 +72,7 @@ export interface UnifiedAlertingConfig {
alertStateHistoryBackend?: string; alertStateHistoryBackend?: string;
// will be undefined if implementation is not "multiple" // will be undefined if implementation is not "multiple"
alertStateHistoryPrimary?: string; alertStateHistoryPrimary?: string;
recordingRulesEnabled?: boolean;
} }
/** Supported OAuth services /** Supported OAuth services

View File

@ -160,6 +160,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
minInterval: '', minInterval: '',
alertStateHistoryBackend: undefined, alertStateHistoryBackend: undefined,
alertStateHistoryPrimary: undefined, alertStateHistoryPrimary: undefined,
recordingRulesEnabled: false,
}; };
applicationInsightsConnectionString?: string; applicationInsightsConnectionString?: string;
applicationInsightsEndpointUrl?: string; applicationInsightsEndpointUrl?: string;

View File

@ -97,6 +97,7 @@ type FrontendSettingsUnifiedAlertingDTO struct {
MinInterval string `json:"minInterval"` MinInterval string `json:"minInterval"`
AlertStateHistoryBackend string `json:"alertStateHistoryBackend,omitempty"` AlertStateHistoryBackend string `json:"alertStateHistoryBackend,omitempty"`
AlertStateHistoryPrimary string `json:"alertStateHistoryPrimary,omitempty"` AlertStateHistoryPrimary string `json:"alertStateHistoryPrimary,omitempty"`
RecordingRulesEnabled bool `json:"recordingRulesEnabled"`
} }
// Enterprise-only // Enterprise-only

View File

@ -337,6 +337,8 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
frontendSettings.UnifiedAlerting.AlertStateHistoryPrimary = hs.Cfg.UnifiedAlerting.StateHistory.MultiPrimary frontendSettings.UnifiedAlerting.AlertStateHistoryPrimary = hs.Cfg.UnifiedAlerting.StateHistory.MultiPrimary
} }
frontendSettings.UnifiedAlerting.RecordingRulesEnabled = hs.Cfg.UnifiedAlerting.RecordingRules.Enabled
if hs.Cfg.UnifiedAlerting.Enabled != nil { if hs.Cfg.UnifiedAlerting.Enabled != nil {
frontendSettings.UnifiedAlertingEnabled = *hs.Cfg.UnifiedAlerting.Enabled frontendSettings.UnifiedAlertingEnabled = *hs.Cfg.UnifiedAlerting.Enabled
} }

View File

@ -2,7 +2,6 @@ import { css } from '@emotion/css';
import { useToggle } from 'react-use'; import { useToggle } from 'react-use';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2 } from '@grafana/data';
import { config } from '@grafana/runtime';
import { Button, LinkButton, LoadingPlaceholder, Pagination, Spinner, Stack, Text, useStyles2 } from '@grafana/ui'; import { Button, LinkButton, LoadingPlaceholder, Pagination, Spinner, Stack, Text, useStyles2 } from '@grafana/ui';
import { useQueryParams } from 'app/core/hooks/useQueryParams'; import { useQueryParams } from 'app/core/hooks/useQueryParams';
import { Trans, t } from 'app/core/internationalization'; import { Trans, t } from 'app/core/internationalization';
@ -10,6 +9,7 @@ import { CombinedRuleNamespace } from 'app/types/unified-alerting';
import { DEFAULT_PER_PAGE_PAGINATION } from '../../../../../core/constants'; import { DEFAULT_PER_PAGE_PAGINATION } from '../../../../../core/constants';
import { LogMessages, logInfo } from '../../Analytics'; import { LogMessages, logInfo } from '../../Analytics';
import { useGrafanaManagedRecordingRulesSupport } from '../../featureToggles';
import { AlertingAction, useAlertingAbility } from '../../hooks/useAbilities'; import { AlertingAction, useAlertingAbility } from '../../hooks/useAbilities';
import { flattenGrafanaManagedRules } from '../../hooks/useCombinedRuleNamespaces'; import { flattenGrafanaManagedRules } from '../../hooks/useCombinedRuleNamespaces';
import { usePagination } from '../../hooks/usePagination'; import { usePagination } from '../../hooks/usePagination';
@ -57,7 +57,7 @@ export const GrafanaRules = ({ namespaces, expandAll }: Props) => {
const [showExportDrawer, toggleShowExportDrawer] = useToggle(false); const [showExportDrawer, toggleShowExportDrawer] = useToggle(false);
const hasGrafanaAlerts = namespaces.length > 0; const hasGrafanaAlerts = namespaces.length > 0;
const grafanaRecordingRulesEnabled = config.featureToggles.grafanaManagedRecordingRules; const grafanaRecordingRulesEnabled = useGrafanaManagedRecordingRulesSupport();
return ( return (
<section className={styles.wrapper}> <section className={styles.wrapper}>

View File

@ -1,12 +1,12 @@
import { config } from '@grafana/runtime';
import { Dropdown, EmptyState, LinkButton, Menu, MenuItem, Stack, TextLink } from '@grafana/ui'; import { Dropdown, EmptyState, LinkButton, Menu, MenuItem, Stack, TextLink } from '@grafana/ui';
import { Trans, t } from 'app/core/internationalization'; import { Trans, t } from 'app/core/internationalization';
import { useGrafanaManagedRecordingRulesSupport } from '../../featureToggles';
import { useRulesAccess } from '../../utils/accessControlHooks'; import { useRulesAccess } from '../../utils/accessControlHooks';
const RecordingRulesButtons = () => { const RecordingRulesButtons = () => {
const { canCreateGrafanaRules, canCreateCloudRules } = useRulesAccess(); const { canCreateGrafanaRules, canCreateCloudRules } = useRulesAccess();
const grafanaRecordingRulesEnabled = config.featureToggles.grafanaManagedRecordingRules; const grafanaRecordingRulesEnabled = useGrafanaManagedRecordingRulesSupport();
const canCreateAll = canCreateGrafanaRules && canCreateCloudRules && grafanaRecordingRulesEnabled; const canCreateAll = canCreateGrafanaRules && canCreateCloudRules && grafanaRecordingRulesEnabled;
// User can create Grafana and DS-managed recording rules, show a dropdown // User can create Grafana and DS-managed recording rules, show a dropdown

View File

@ -1,3 +1,6 @@
import { config } from '@grafana/runtime'; import { config } from '@grafana/runtime';
export const shouldUsePrometheusRulesPrimary = () => config.featureToggles.alertingPrometheusRulesPrimary ?? false; export const shouldUsePrometheusRulesPrimary = () => config.featureToggles.alertingPrometheusRulesPrimary ?? false;
export const useGrafanaManagedRecordingRulesSupport = () =>
config.unifiedAlerting.recordingRulesEnabled && config.featureToggles.grafanaManagedRecordingRules;