mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix normalization of alert states for panel annotations (#51637)
A bug introduced by #49259 would crash the annotations view of a panel with a linked alert rule. States are now normalized so crashes won't occur and the base state is used instead.
This commit is contained in:
parent
64a2c4783f
commit
d63ffa314e
@ -4134,11 +4134,11 @@ exports[`better eslint`] = {
|
|||||||
[37, 48, 3, "Unexpected any. Specify a different type.", "193409811"],
|
[37, 48, 3, "Unexpected any. Specify a different type.", "193409811"],
|
||||||
[50, 46, 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"],
|
[78, 34, 3, "Unexpected any. Specify a different type.", "193409811"],
|
||||||
[159, 34, 3, "Unexpected any. Specify a different type.", "193409811"],
|
[165, 34, 3, "Unexpected any. Specify a different type.", "193409811"],
|
||||||
[174, 4, 14, "Do not use any type assertions.", "3854427458"],
|
[180, 4, 14, "Do not use any type assertions.", "3854427458"],
|
||||||
[178, 36, 3, "Unexpected any. Specify a different type.", "193409811"]
|
[184, 36, 3, "Unexpected any. Specify a different type.", "193409811"]
|
||||||
],
|
],
|
||||||
"public/app/features/alerting/state/query_part.ts:2255335987": [
|
"public/app/features/alerting/state/query_part.ts:2255335987": [
|
||||||
[4, 10, 3, "Unexpected any. Specify a different type.", "193409811"],
|
[4, 10, 3, "Unexpected any. Specify a different type.", "193409811"],
|
||||||
|
@ -81,8 +81,14 @@ function createReducerPart(model: any) {
|
|||||||
return new QueryPart(model, def);
|
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) {
|
function getStateDisplayModel(state: string) {
|
||||||
const normalizedState = state.toLowerCase().replace(/_/g, '');
|
const normalizedState = normalizeAlertState(state);
|
||||||
|
|
||||||
switch (normalizedState) {
|
switch (normalizedState) {
|
||||||
case 'normal':
|
case 'normal':
|
||||||
@ -121,13 +127,6 @@ function getStateDisplayModel(state: string) {
|
|||||||
stateClass: 'alert-state-warning',
|
stateClass: 'alert-state-warning',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'unknown': {
|
|
||||||
return {
|
|
||||||
text: 'UNKNOWN',
|
|
||||||
iconClass: 'question-circle',
|
|
||||||
stateClass: '.alert-state-paused',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'firing': {
|
case 'firing': {
|
||||||
return {
|
return {
|
||||||
@ -152,9 +151,16 @@ function getStateDisplayModel(state: string) {
|
|||||||
stateClass: 'alert-state-critical',
|
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) {
|
function joinEvalMatches(matches: any, separator: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user