diff --git a/.betterer.results b/.betterer.results index 5b5eea8023a..c8618ec5aaf 100644 --- a/.betterer.results +++ b/.betterer.results @@ -4134,11 +4134,11 @@ exports[`better eslint`] = { [37, 48, 3, "Unexpected any. Specify a different type.", "193409811"], [50, 46, 3, "Unexpected any. Specify a different type.", "193409811"] ], - "public/app/features/alerting/state/alertDef.ts:2887521080": [ + "public/app/features/alerting/state/alertDef.ts:1683373860": [ [78, 34, 3, "Unexpected any. Specify a different type.", "193409811"], - [159, 34, 3, "Unexpected any. Specify a different type.", "193409811"], - [174, 4, 14, "Do not use any type assertions.", "3854427458"], - [178, 36, 3, "Unexpected any. Specify a different type.", "193409811"] + [165, 34, 3, "Unexpected any. Specify a different type.", "193409811"], + [180, 4, 14, "Do not use any type assertions.", "3854427458"], + [184, 36, 3, "Unexpected any. Specify a different type.", "193409811"] ], "public/app/features/alerting/state/query_part.ts:2255335987": [ [4, 10, 3, "Unexpected any. Specify a different type.", "193409811"], diff --git a/public/app/features/alerting/state/alertDef.ts b/public/app/features/alerting/state/alertDef.ts index de4f61cf7a6..41f0d3e9660 100644 --- a/public/app/features/alerting/state/alertDef.ts +++ b/public/app/features/alerting/state/alertDef.ts @@ -81,8 +81,14 @@ function createReducerPart(model: any) { return new QueryPart(model, def); } +// state can also contain a "Reason", ie. "Alerting (NoData)" which indicates that the actual state is "Alerting" but +// the reason it is set to "Alerting" is "NoData"; a lack of data points to evaluate. +function normalizeAlertState(state: string) { + return state.toLowerCase().replace(/_/g, '').split(' ')[0]; +} + function getStateDisplayModel(state: string) { - const normalizedState = state.toLowerCase().replace(/_/g, ''); + const normalizedState = normalizeAlertState(state); switch (normalizedState) { case 'normal': @@ -121,13 +127,6 @@ function getStateDisplayModel(state: string) { stateClass: 'alert-state-warning', }; } - case 'unknown': { - return { - text: 'UNKNOWN', - iconClass: 'question-circle', - stateClass: '.alert-state-paused', - }; - } case 'firing': { return { @@ -152,9 +151,16 @@ function getStateDisplayModel(state: string) { stateClass: 'alert-state-critical', }; } - } - throw { message: 'Unknown alert state' }; + case 'unknown': + default: { + return { + text: 'UNKNOWN', + iconClass: 'question-circle', + stateClass: '.alert-state-paused', + }; + } + } } function joinEvalMatches(matches: any, separator: string) {