From 2ba729f904d43fc71829214bab7ba00d17f4ad67 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher Date: Tue, 6 Oct 2020 11:12:20 +0100 Subject: [PATCH] [Logs UI] Add timestamp as a context variable to log threshold alerts (#78932) * Add timestamp context variable --- .../lib/alerting/log_threshold/log_threshold_executor.ts | 5 ++++- .../log_threshold/register_log_threshold_alert_type.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts index 0ea65f94c940..d3d34cd2aad5 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts @@ -340,9 +340,12 @@ type AlertInstanceUpdater = ( export const updateAlertInstance: AlertInstanceUpdater = (alertInstance, state, actions) => { if (actions && actions.length > 0) { + const sharedContext = { + timestamp: new Date().toISOString(), + }; actions.forEach((actionSet) => { const { actionGroup, context } = actionSet; - alertInstance.scheduleActions(actionGroup, context); + alertInstance.scheduleActions(actionGroup, { ...sharedContext, ...context }); }); } diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts index 2c1d7e097660..34afddc2a4d4 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts @@ -13,6 +13,13 @@ import { import { InfraBackendLibs } from '../../infra_types'; import { decodeOrThrow } from '../../../../common/runtime_types'; +const timestampActionVariableDescription = i18n.translate( + 'xpack.infra.logs.alerting.threshold.timestampActionVariableDescription', + { + defaultMessage: 'UTC timestamp of when the alert was triggered', + } +); + const documentCountActionVariableDescription = i18n.translate( 'xpack.infra.logs.alerting.threshold.documentCountActionVariableDescription', { @@ -85,6 +92,7 @@ export async function registerLogThresholdAlertType( executor: createLogThresholdExecutor(libs), actionVariables: { context: [ + { name: 'timestamp', description: timestampActionVariableDescription }, { name: 'matchingDocuments', description: documentCountActionVariableDescription }, { name: 'conditions', description: conditionsActionVariableDescription }, { name: 'group', description: groupByActionVariableDescription },