[Observability][Alerts] Add last updated at label and fix started at label (#134254)

* [Observability][Alerts] Add last updated at label and fix started at label

* Fixing tests by adding lastUpdated

* Adding additional fields to tests

* Update x-pack/plugins/observability/public/pages/alerts/components/alerts_flyout/alerts_flyout.tsx

Co-authored-by: Faisal Kanout <faisal@kanout.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Faisal Kanout <faisal@kanout.com>
This commit is contained in:
Chris Cowan 2022-06-14 13:20:31 -06:00 committed by GitHub
parent 6a6b1eeafa
commit 3382a2a07a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 10 deletions

View file

@ -79,6 +79,9 @@ export const translations = {
lastUpdatedLabel: i18n.translate('xpack.observability.alertsFlyout.lastUpdatedLabel', {
defaultMessage: 'Last updated',
}),
startedAtLabel: i18n.translate('xpack.observability.alertsFlyout.startedAtLabel', {
defaultMessage: 'Started at',
}),
durationLabel: i18n.translate('xpack.observability.alertsFlyout.durationLabel', {
defaultMessage: 'Duration',
}),

View file

@ -70,6 +70,7 @@ const activeAlert: TopAlert = {
},
active: true,
start: 1630587249674,
lastUpdated: 1630588131750,
};
const recoveredAlert: TopAlert = {
@ -98,4 +99,5 @@ const recoveredAlert: TopAlert = {
},
active: false,
start: 1630587936699,
lastUpdated: 1630588125729,
};

View file

@ -88,11 +88,19 @@ export function AlertsFlyout({
),
},
{
title: translations.alertsFlyout.lastUpdatedLabel,
title: translations.alertsFlyout.startedAtLabel,
description: (
<span title={alertData.start.toString()}>{moment(alertData.start).format(dateFormat)}</span>
),
},
{
title: translations.alertsFlyout.lastUpdatedLabel,
description: (
<span title={alertData.lastUpdated.toString()}>
{moment(alertData.lastUpdated).format(dateFormat)}
</span>
),
},
{
title: translations.alertsFlyout.durationLabel,
description: asDuration(alertData.fields[ALERT_DURATION], { extended: true }),

View file

@ -22,8 +22,23 @@ import {
ALERT_STATUS_RECOVERED,
ALERT_RULE_CONSUMER,
SPACE_IDS,
TIMESTAMP,
} from '@kbn/rule-data-utils';
const createDates = (start: string, duration: number, isEnd?: boolean) => {
const started = new Date(start);
const lastTimestamp = new Date(started.valueOf() + duration);
const dates = {
[TIMESTAMP]: lastTimestamp.toISOString(),
[ALERT_START]: started.toISOString(),
[ALERT_DURATION]: duration,
};
if (isEnd) {
return { ...dates, [ALERT_END]: lastTimestamp.toISOString() };
}
return dates;
};
export const apmAlertResponseExample = [
{
[ALERT_RULE_TYPE_ID]: ['apm.error_rate'],
@ -31,21 +46,19 @@ export const apmAlertResponseExample = [
[ALERT_RULE_NAME]: ['Error count threshold | opbeans-java (smith test)'],
[ALERT_RULE_CONSUMER]: ['apm'],
[SPACE_IDS]: ['default'],
[ALERT_DURATION]: [180057000],
[ALERT_STATUS]: [ALERT_STATUS_ACTIVE],
[ALERT_SEVERITY]: ['warning'],
tags: ['apm', 'service.name:opbeans-java'],
[ALERT_UUID]: ['0175ec0a-a3b1-4d41-b557-e21c2d024352'],
[ALERT_RULE_UUID]: ['474920d0-93e9-11eb-ac86-0b455460de81'],
'event.action': ['active'],
'@timestamp': ['2021-04-12T13:53:49.550Z'],
[ALERT_INSTANCE_ID]: ['apm.error_rate_opbeans-java_production'],
[ALERT_START]: ['2021-04-12T13:50:49.493Z'],
[ALERT_RULE_PRODUCER]: ['apm'],
'event.kind': ['state'],
[ALERT_RULE_CATEGORY]: ['Error count threshold'],
'service.environment': ['production'],
'processor.event': ['error'],
...createDates('2021-04-12T13:50:49.493Z', 180057000),
},
{
[ALERT_RULE_TYPE_ID]: ['apm.error_rate'],
@ -53,28 +66,25 @@ export const apmAlertResponseExample = [
[ALERT_RULE_NAME]: ['Error count threshold | opbeans-java (smith test)'],
[ALERT_RULE_CONSUMER]: ['apm'],
[SPACE_IDS]: ['default'],
[ALERT_DURATION]: [2419005000],
[ALERT_END]: ['2021-04-12T13:49:49.446Z'],
[ALERT_STATUS]: [ALERT_STATUS_RECOVERED],
tags: ['apm', 'service.name:opbeans-java'],
[ALERT_UUID]: ['32b940e1-3809-4c12-8eee-f027cbb385e2'],
[ALERT_RULE_UUID]: ['474920d0-93e9-11eb-ac86-0b455460de81'],
'event.action': ['close'],
'@timestamp': ['2021-04-12T13:49:49.446Z'],
[ALERT_INSTANCE_ID]: ['apm.error_rate_opbeans-java_production'],
[ALERT_START]: ['2021-04-12T13:09:30.441Z'],
[ALERT_RULE_PRODUCER]: ['apm'],
'event.kind': ['state'],
[ALERT_RULE_CATEGORY]: ['Error count threshold'],
'service.environment': ['production'],
'processor.event': ['error'],
...createDates('2021-04-12T13:09:30.441Z', 2419005000, true),
},
];
export const dynamicIndexPattern = {
fields: [
{
name: '@timestamp',
name: TIMESTAMP,
type: 'date',
esTypes: ['date'],
searchable: true,
@ -242,6 +252,6 @@ export const dynamicIndexPattern = {
readFromDocValues: true,
},
],
timeFieldName: '@timestamp',
timeFieldName: TIMESTAMP,
title: '.kibana_smith-alerts-observability*',
};

View file

@ -6,6 +6,7 @@
*/
import {
TIMESTAMP,
ALERT_START,
ALERT_STATUS,
ALERT_STATUS_ACTIVE,
@ -48,5 +49,6 @@ export const parseAlert =
fields: parsedFields,
active: parsedFields[ALERT_STATUS] === ALERT_STATUS_ACTIVE,
start: new Date(parsedFields[ALERT_START] ?? 0).getTime(),
lastUpdated: new Date(parsedFields[TIMESTAMP] ?? 0).getTime(),
};
};

View file

@ -50,6 +50,7 @@ interface RuleStatsState {
export interface TopAlert {
fields: ParsedTechnicalFields & ParsedExperimentalFields;
start: number;
lastUpdated: number;
reason: string;
link?: string;
active: boolean;

View file

@ -137,6 +137,7 @@ describe('useFetchAlertDetail', () => {
"kibana.version": "8.1.0",
"tags": Array [],
},
"lastUpdated": 1643653257204,
"link": undefined,
"reason": "Document count reported no data in the last 1 hour for all hosts",
"start": 1643639463649,

View file

@ -151,6 +151,7 @@ export default ({ getService }: FtrProviderContext) => {
const expectedTitles = [
'Status',
'Started at',
'Last updated',
'Duration',
'Expected value',
@ -160,6 +161,7 @@ export default ({ getService }: FtrProviderContext) => {
const expectedDescriptions = [
'Active',
'Oct 19, 2021 @ 15:00:41.555',
'Oct 19, 2021 @ 15:20:38.749',
'20 minutes',
'5',
'30.727896995708154',