diff --git a/docs/sources/panels-visualizations/visualizations/alert-list/index.md b/docs/sources/panels-visualizations/visualizations/alert-list/index.md index 4dd942279f1..3e6550a8f5e 100644 --- a/docs/sources/panels-visualizations/visualizations/alert-list/index.md +++ b/docs/sources/panels-visualizations/visualizations/alert-list/index.md @@ -105,6 +105,7 @@ These options allow you to limit alerts shown to only those that match the query | Alert instance label | Filter alert instances using [label](ref:alert-label) querying. For example,`{severity="critical", instance=~"cluster-us-.+"}`. | | Datasource | Filter alerts from the selected data source. | | Folder | Filter alerts by the selected folder. Only alerts from dashboards in this folder are displayed. | +| Show alerts with 0 instances | Filter for alert rules with no instances. Alert rules with 0 (zero) instances are hidden by default. You can choose to show them by toggling this switch. Because these rules have no instances, they remain hidden if the **Alert instance label** filter is configured. | ### Alert state filter options diff --git a/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx b/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx index 3408ecf7078..680942f86f2 100644 --- a/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx +++ b/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx @@ -323,7 +323,7 @@ function filterRules(props: PanelProps, rules: Combined ); } - // Remove rules having 0 instances + // Remove rules having 0 instances unless explicitly configured // AlertInstances filters instances and we need to prevent situation // when we display a rule with 0 instances filteredRules = filteredRules.reduce((rules, rule) => { @@ -337,7 +337,12 @@ function filterRules(props: PanelProps, rules: Combined alertingRule.alerts ?? [] ) : []; - if (filteredAlerts.length) { + if ( + filteredAlerts.length || + (alertingRule?.state === PromAlertingRuleState.Inactive && + options.showInactiveAlerts && + !options.alertInstanceLabelFilter.length) + ) { // We intentionally don't set alerts to filteredAlerts // because later we couldn't display that some alerts are hidden (ref AlertInstances filtering) rules.push(rule); diff --git a/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx b/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx index e609c34d0f3..a77e61d44af 100644 --- a/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx +++ b/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx @@ -113,6 +113,7 @@ const defaultOptions: UnifiedAlertListOptions = { alertInstanceLabelFilter: '', datasource: 'grafana', viewMode: ViewMode.List, + showInactiveAlerts: false, }; const defaultProps: PanelProps = { diff --git a/public/app/plugins/panel/alertlist/module.tsx b/public/app/plugins/panel/alertlist/module.tsx index 9ec66e40984..e919102f8ce 100644 --- a/public/app/plugins/panel/alertlist/module.tsx +++ b/public/app/plugins/panel/alertlist/module.tsx @@ -129,7 +129,7 @@ const unifiedAlertList = new PanelPlugin(UnifiedAlertLi showIf: (options) => options.datasource === GRAFANA_DATASOURCE_NAME || !Boolean(options.datasource), path: 'folder', name: 'Folder', - description: 'Filter for alerts in the selected folder (only for Grafana alerts)', + description: 'Filter for alerts in the selected folder (for Grafana-managed alert rules only)', id: 'folder', defaultValue: null, editor: function RenderFolderPicker(props) { @@ -148,6 +148,14 @@ const unifiedAlertList = new PanelPlugin(UnifiedAlertLi }, category: ['Filter'], }) + .addBooleanSwitch({ + path: 'showInactiveAlerts', + name: 'Show alerts with 0 instances', + description: + 'Include alert rules which have 0 (zero) instances. Because these rules have no instances, they remain hidden if the Alert instance label filter is configured.', + defaultValue: false, + category: ['Filter'], + }) .addBooleanSwitch({ path: 'stateFilter.firing', name: 'Alerting / Firing', diff --git a/public/app/plugins/panel/alertlist/types.ts b/public/app/plugins/panel/alertlist/types.ts index b128b631b66..fd9e9cf3540 100644 --- a/public/app/plugins/panel/alertlist/types.ts +++ b/public/app/plugins/panel/alertlist/types.ts @@ -38,6 +38,7 @@ export interface AlertListOptions { pending: boolean; }; folderId: number; + showInactiveAlerts: boolean; } export interface StateFilter { @@ -62,4 +63,5 @@ export interface UnifiedAlertListOptions { alertInstanceLabelFilter: string; datasource: string; viewMode: ViewMode; + showInactiveAlerts: boolean; } diff --git a/public/app/plugins/panel/alertlist/util.test.tsx b/public/app/plugins/panel/alertlist/util.test.tsx index cf4f87a6ae5..b8513cb55b4 100644 --- a/public/app/plugins/panel/alertlist/util.test.tsx +++ b/public/app/plugins/panel/alertlist/util.test.tsx @@ -18,6 +18,7 @@ const defaultOption: UnifiedAlertListOptions = { alertInstanceLabelFilter: '', datasource: 'Alertmanager', viewMode: ViewMode.List, + showInactiveAlerts: false, }; const alerts: Alert[] = [