mirror of
https://github.com/grafana/grafana.git
synced 2025-09-20 00:00:43 +08:00
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:
@ -72,6 +72,7 @@ export interface UnifiedAlertingConfig {
|
||||
alertStateHistoryBackend?: string;
|
||||
// will be undefined if implementation is not "multiple"
|
||||
alertStateHistoryPrimary?: string;
|
||||
recordingRulesEnabled?: boolean;
|
||||
}
|
||||
|
||||
/** Supported OAuth services
|
||||
|
@ -160,6 +160,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
minInterval: '',
|
||||
alertStateHistoryBackend: undefined,
|
||||
alertStateHistoryPrimary: undefined,
|
||||
recordingRulesEnabled: false,
|
||||
};
|
||||
applicationInsightsConnectionString?: string;
|
||||
applicationInsightsEndpointUrl?: string;
|
||||
|
@ -97,6 +97,7 @@ type FrontendSettingsUnifiedAlertingDTO struct {
|
||||
MinInterval string `json:"minInterval"`
|
||||
AlertStateHistoryBackend string `json:"alertStateHistoryBackend,omitempty"`
|
||||
AlertStateHistoryPrimary string `json:"alertStateHistoryPrimary,omitempty"`
|
||||
RecordingRulesEnabled bool `json:"recordingRulesEnabled"`
|
||||
}
|
||||
|
||||
// Enterprise-only
|
||||
|
@ -337,6 +337,8 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
frontendSettings.UnifiedAlerting.AlertStateHistoryPrimary = hs.Cfg.UnifiedAlerting.StateHistory.MultiPrimary
|
||||
}
|
||||
|
||||
frontendSettings.UnifiedAlerting.RecordingRulesEnabled = hs.Cfg.UnifiedAlerting.RecordingRules.Enabled
|
||||
|
||||
if hs.Cfg.UnifiedAlerting.Enabled != nil {
|
||||
frontendSettings.UnifiedAlertingEnabled = *hs.Cfg.UnifiedAlerting.Enabled
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ import { css } from '@emotion/css';
|
||||
import { useToggle } from 'react-use';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { Button, LinkButton, LoadingPlaceholder, Pagination, Spinner, Stack, Text, useStyles2 } from '@grafana/ui';
|
||||
import { useQueryParams } from 'app/core/hooks/useQueryParams';
|
||||
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 { LogMessages, logInfo } from '../../Analytics';
|
||||
import { useGrafanaManagedRecordingRulesSupport } from '../../featureToggles';
|
||||
import { AlertingAction, useAlertingAbility } from '../../hooks/useAbilities';
|
||||
import { flattenGrafanaManagedRules } from '../../hooks/useCombinedRuleNamespaces';
|
||||
import { usePagination } from '../../hooks/usePagination';
|
||||
@ -57,7 +57,7 @@ export const GrafanaRules = ({ namespaces, expandAll }: Props) => {
|
||||
const [showExportDrawer, toggleShowExportDrawer] = useToggle(false);
|
||||
const hasGrafanaAlerts = namespaces.length > 0;
|
||||
|
||||
const grafanaRecordingRulesEnabled = config.featureToggles.grafanaManagedRecordingRules;
|
||||
const grafanaRecordingRulesEnabled = useGrafanaManagedRecordingRulesSupport();
|
||||
|
||||
return (
|
||||
<section className={styles.wrapper}>
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { config } from '@grafana/runtime';
|
||||
import { Dropdown, EmptyState, LinkButton, Menu, MenuItem, Stack, TextLink } from '@grafana/ui';
|
||||
import { Trans, t } from 'app/core/internationalization';
|
||||
|
||||
import { useGrafanaManagedRecordingRulesSupport } from '../../featureToggles';
|
||||
import { useRulesAccess } from '../../utils/accessControlHooks';
|
||||
|
||||
const RecordingRulesButtons = () => {
|
||||
const { canCreateGrafanaRules, canCreateCloudRules } = useRulesAccess();
|
||||
const grafanaRecordingRulesEnabled = config.featureToggles.grafanaManagedRecordingRules;
|
||||
const grafanaRecordingRulesEnabled = useGrafanaManagedRecordingRulesSupport();
|
||||
const canCreateAll = canCreateGrafanaRules && canCreateCloudRules && grafanaRecordingRulesEnabled;
|
||||
|
||||
// User can create Grafana and DS-managed recording rules, show a dropdown
|
||||
|
@ -1,3 +1,6 @@
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
export const shouldUsePrometheusRulesPrimary = () => config.featureToggles.alertingPrometheusRulesPrimary ?? false;
|
||||
|
||||
export const useGrafanaManagedRecordingRulesSupport = () =>
|
||||
config.unifiedAlerting.recordingRulesEnabled && config.featureToggles.grafanaManagedRecordingRules;
|
||||
|
Reference in New Issue
Block a user