mirror of https://github.com/grafana/grafana
Alerting: Add a "Reason" to Alert Instances to show underlying cause of state. (#49259)
This change adds a field to state.State and models.AlertInstance that indicate the "Reason" that an instance has its current state. This helps us account for cases where the state is "Normal" but the underlying evaluation returned "NoData" or "Error", for example. Fixes #42606 Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>pull/49387/head
parent
26a206cce2
commit
1cc034d960
@ -1,14 +1,14 @@ |
||||
import React, { FC } from 'react'; |
||||
|
||||
import { AlertState } from '@grafana/data'; |
||||
import { GrafanaAlertState, PromAlertingRuleState } from 'app/types/unified-alerting-dto'; |
||||
import { GrafanaAlertStateWithReason, PromAlertingRuleState } from 'app/types/unified-alerting-dto'; |
||||
|
||||
import { alertStateToReadable, alertStateToState } from '../../utils/rules'; |
||||
import { StateTag } from '../StateTag'; |
||||
interface Props { |
||||
state: PromAlertingRuleState | GrafanaAlertState | AlertState; |
||||
state: PromAlertingRuleState | GrafanaAlertStateWithReason | AlertState; |
||||
} |
||||
|
||||
export const AlertStateTag: FC<Props> = ({ state }) => ( |
||||
<StateTag state={alertStateToState[state]}>{alertStateToReadable(state)}</StateTag> |
||||
<StateTag state={alertStateToState(state)}>{alertStateToReadable(state)}</StateTag> |
||||
); |
||||
|
@ -0,0 +1,28 @@ |
||||
import { |
||||
GrafanaAlertState, |
||||
PromAlertingRuleState, |
||||
mapStateWithReasonToBaseState, |
||||
} from 'app/types/unified-alerting-dto'; |
||||
|
||||
describe('Unified Alerting DTO', () => { |
||||
describe('mapStateWithReasonToBaseState', () => { |
||||
it.each` |
||||
arg | expected |
||||
${GrafanaAlertState.Normal} | ${GrafanaAlertState.Normal} |
||||
${'Normal (NoData)'} | ${GrafanaAlertState.Normal} |
||||
${'Normal (Error)'} | ${GrafanaAlertState.Normal} |
||||
${GrafanaAlertState.Alerting} | ${GrafanaAlertState.Alerting} |
||||
${'Alerting (NoData)'} | ${GrafanaAlertState.Alerting} |
||||
${'Alerting (Error)'} | ${GrafanaAlertState.Alerting} |
||||
${'Pending '} | ${GrafanaAlertState.Pending} |
||||
${'NoData'} | ${GrafanaAlertState.NoData} |
||||
${'Error'} | ${GrafanaAlertState.Error} |
||||
${PromAlertingRuleState.Firing} | ${PromAlertingRuleState.Firing} |
||||
${PromAlertingRuleState.Pending} | ${PromAlertingRuleState.Pending} |
||||
${PromAlertingRuleState.Inactive} | ${PromAlertingRuleState.Inactive} |
||||
`('should map correctly', ({ arg, expected }) => {
|
||||
const result = mapStateWithReasonToBaseState(arg); |
||||
expect(result).toEqual(expected); |
||||
}); |
||||
}); |
||||
}); |
Loading…
Reference in new issue