Alerting: Fix display of Normal (Updated) in alert history (#102476)

* Fix display of `Normal (Updated)` in alert history

* Update useRuleHistoryRecords.test.tsx

* Update regex
This commit is contained in:
Tom Ratcliffe
2025-03-25 12:59:18 +02:00
committed by GitHub
parent 3776a0baed
commit a13d90db45
3 changed files with 29 additions and 18 deletions
@@ -48,17 +48,19 @@ describe('logRecordsToDataFrame', () => {
const frame = logRecordsToDataFrame(JSON.stringify(instanceLabels), records, [], theme);
const stateField = frame.fields[1];
expect(stateField.config.mappings).toHaveLength(1);
expect(stateField.config.mappings).toHaveLength(3);
expect(stateField.config.mappings![0].options).toMatchObject({
Alerting: {
color: theme.colors.error.main,
},
pattern: '/^normal/i',
result: { color: theme.colors.success.main },
});
expect(stateField.config.mappings![1].options).toMatchObject({
pattern: '/Alerting/',
result: { color: theme.colors.error.main },
});
expect(stateField.config.mappings![2].options).toMatchObject({
Pending: {
color: theme.colors.warning.main,
},
Normal: {
color: theme.colors.success.main,
},
NoData: {
color: theme.colors.info.main,
},
@@ -119,18 +119,27 @@ export function logRecordsToDataFrame(
color: { mode: 'thresholds' },
custom: { fillOpacity: 100 },
mappings: [
{
type: MappingType.RegexToText,
options: {
// Map as a regex so we capture `Normal`, and `Normal (Updated)`
pattern: '/^normal/i',
result: { color: theme.colors.success.main },
},
},
{
type: MappingType.RegexToText,
options: {
pattern: '/Alerting/',
result: { color: theme.colors.error.main },
},
},
{
type: MappingType.ValueToText,
options: {
Alerting: {
color: theme.colors.error.main,
},
Pending: {
color: theme.colors.warning.main,
},
Normal: {
color: theme.colors.success.main,
},
NoData: {
color: theme.colors.info.main,
},
@@ -91,14 +91,14 @@ export const namespaces: Record<string, RulerRuleGroupDTO[]> = {
//-------------------- for alert history tests we reuse these constants --------------------
export const time_0 = 1718368710000;
// time1 + 30 seg
export const time_plus_30 = 1718368740000;
// time1 + 5 seg
export const time_plus_5 = 1718368715000;
export const time_plus_5 = time_0 + 5 * 1000;
// time1 + 15 seg
export const time_plus_15 = 1718368725000;
export const time_plus_15 = time_0 + 15 * 1000;
// time1 + 10 seg
export const time_plus_10 = 1718368720000;
export const time_plus_10 = time_0 + 10 * 1000;
// time1 + 30 seg
export const time_plus_30 = time_0 + 30 * 1000;
// returns 4 transitions. times is an array of 4 timestamps.
export const getHistoryResponse = (times: number[]) => ({