mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Show paused status in rules group accordion (#64068)
* Show paused status in group accordion * Fix linting * display number of paused alerts within normal label
This commit is contained in:
parent
92ee03db78
commit
33f66e6350
@ -6,7 +6,7 @@ import { Badge } from '@grafana/ui';
|
|||||||
import { CombinedRule, CombinedRuleGroup, CombinedRuleNamespace } from 'app/types/unified-alerting';
|
import { CombinedRule, CombinedRuleGroup, CombinedRuleNamespace } from 'app/types/unified-alerting';
|
||||||
import { PromAlertingRuleState } from 'app/types/unified-alerting-dto';
|
import { PromAlertingRuleState } from 'app/types/unified-alerting-dto';
|
||||||
|
|
||||||
import { isAlertingRule, isRecordingRule, isRecordingRulerRule } from '../../utils/rules';
|
import { isAlertingRule, isRecordingRule, isRecordingRulerRule, isGrafanaRulerRulePaused } from '../../utils/rules';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
includeTotal?: boolean;
|
includeTotal?: boolean;
|
||||||
@ -20,6 +20,7 @@ const emptyStats = {
|
|||||||
[PromAlertingRuleState.Firing]: 0,
|
[PromAlertingRuleState.Firing]: 0,
|
||||||
[PromAlertingRuleState.Pending]: 0,
|
[PromAlertingRuleState.Pending]: 0,
|
||||||
[PromAlertingRuleState.Inactive]: 0,
|
[PromAlertingRuleState.Inactive]: 0,
|
||||||
|
paused: 0,
|
||||||
error: 0,
|
error: 0,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
@ -31,6 +32,9 @@ export const RuleStats: FC<Props> = ({ group, namespaces, includeTotal }) => {
|
|||||||
|
|
||||||
const calcRule = (rule: CombinedRule) => {
|
const calcRule = (rule: CombinedRule) => {
|
||||||
if (rule.promRule && isAlertingRule(rule.promRule)) {
|
if (rule.promRule && isAlertingRule(rule.promRule)) {
|
||||||
|
if (isGrafanaRulerRulePaused(rule)) {
|
||||||
|
stats.paused += 1;
|
||||||
|
}
|
||||||
stats[rule.promRule.state] += 1;
|
stats[rule.promRule.state] += 1;
|
||||||
}
|
}
|
||||||
if (ruleHasError(rule)) {
|
if (ruleHasError(rule)) {
|
||||||
@ -82,7 +86,17 @@ export const RuleStats: FC<Props> = ({ group, namespaces, includeTotal }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calculated[PromAlertingRuleState.Inactive]) {
|
if (calculated[PromAlertingRuleState.Inactive] && calculated.paused) {
|
||||||
|
statsComponents.push(
|
||||||
|
<Badge
|
||||||
|
color="green"
|
||||||
|
key="paused"
|
||||||
|
text={`${calculated[PromAlertingRuleState.Inactive]} normal (${calculated.paused} paused)`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calculated[PromAlertingRuleState.Inactive] && !calculated.paused) {
|
||||||
statsComponents.push(
|
statsComponents.push(
|
||||||
<Badge color="green" key="inactive" text={`${calculated[PromAlertingRuleState.Inactive]} normal`} />
|
<Badge color="green" key="inactive" text={`${calculated[PromAlertingRuleState.Inactive]} normal`} />
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,7 @@ import { CombinedRule } from 'app/types/unified-alerting';
|
|||||||
import { DEFAULT_PER_PAGE_PAGINATION } from '../../../../../core/constants';
|
import { DEFAULT_PER_PAGE_PAGINATION } from '../../../../../core/constants';
|
||||||
import { useHasRuler } from '../../hooks/useHasRuler';
|
import { useHasRuler } from '../../hooks/useHasRuler';
|
||||||
import { Annotation } from '../../utils/constants';
|
import { Annotation } from '../../utils/constants';
|
||||||
import { isGrafanaRulerRule } from '../../utils/rules';
|
import { isGrafanaRulerRule, isGrafanaRulerRulePaused } from '../../utils/rules';
|
||||||
import { DynamicTable, DynamicTableColumnProps, DynamicTableItemProps } from '../DynamicTable';
|
import { DynamicTable, DynamicTableColumnProps, DynamicTableItemProps } from '../DynamicTable';
|
||||||
import { DynamicTableWithGuidelines } from '../DynamicTableWithGuidelines';
|
import { DynamicTableWithGuidelines } from '../DynamicTableWithGuidelines';
|
||||||
import { ProvisioningBadge } from '../Provisioning';
|
import { ProvisioningBadge } from '../Provisioning';
|
||||||
@ -117,8 +117,7 @@ function useColumns(showSummaryColumn: boolean, showGroupColumn: boolean) {
|
|||||||
|
|
||||||
const isDeleting = !!(hasRuler(rulesSource) && rulerRulesLoaded(rulesSource) && promRule && !rulerRule);
|
const isDeleting = !!(hasRuler(rulesSource) && rulerRulesLoaded(rulesSource) && promRule && !rulerRule);
|
||||||
const isCreating = !!(hasRuler(rulesSource) && rulerRulesLoaded(rulesSource) && rulerRule && !promRule);
|
const isCreating = !!(hasRuler(rulesSource) && rulerRulesLoaded(rulesSource) && rulerRule && !promRule);
|
||||||
const isGrafanaManagedRule = isGrafanaRulerRule(rulerRule);
|
const isPaused = isGrafanaRulerRulePaused(rule);
|
||||||
const isPaused = isGrafanaManagedRule && Boolean(rulerRule.grafana_alert.is_paused);
|
|
||||||
|
|
||||||
return <RuleState rule={rule} isDeleting={isDeleting} isCreating={isCreating} isPaused={isPaused} />;
|
return <RuleState rule={rule} isDeleting={isDeleting} isCreating={isCreating} isPaused={isPaused} />;
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
AlertingRule,
|
AlertingRule,
|
||||||
CloudRuleIdentifier,
|
CloudRuleIdentifier,
|
||||||
|
CombinedRule,
|
||||||
CombinedRuleGroup,
|
CombinedRuleGroup,
|
||||||
CombinedRuleWithLocation,
|
CombinedRuleWithLocation,
|
||||||
GrafanaRuleIdentifier,
|
GrafanaRuleIdentifier,
|
||||||
@ -55,6 +56,10 @@ export function isGrafanaRulerRule(rule?: RulerRuleDTO): rule is RulerGrafanaRul
|
|||||||
return typeof rule === 'object' && 'grafana_alert' in rule;
|
return typeof rule === 'object' && 'grafana_alert' in rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isGrafanaRulerRulePaused(rule: CombinedRule) {
|
||||||
|
return rule.rulerRule && isGrafanaRulerRule(rule.rulerRule) && Boolean(rule.rulerRule.grafana_alert.is_paused);
|
||||||
|
}
|
||||||
|
|
||||||
export function alertInstanceKey(alert: Alert): string {
|
export function alertInstanceKey(alert: Alert): string {
|
||||||
return JSON.stringify(alert.labels);
|
return JSON.stringify(alert.labels);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user