mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Alerting] Add more rule execution context (#117504)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
322303268a
commit
a0650c7510
4 changed files with 53 additions and 4 deletions
|
@ -105,7 +105,7 @@ export class ActionExecutor {
|
|||
name: `execute_action`,
|
||||
type: 'actions',
|
||||
labels: {
|
||||
actionId,
|
||||
actions_connector_id: actionId,
|
||||
},
|
||||
},
|
||||
async (span) => {
|
||||
|
@ -135,7 +135,7 @@ export class ActionExecutor {
|
|||
if (span) {
|
||||
span.name = `execute_action ${actionTypeId}`;
|
||||
span.addLabels({
|
||||
actionTypeId,
|
||||
actions_connector_type_id: actionTypeId,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import apm from 'elastic-apm-node';
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { Dictionary, pickBy, mapValues, without, cloneDeep } from 'lodash';
|
||||
import type { Request } from '@hapi/hapi';
|
||||
|
@ -529,6 +529,17 @@ export class TaskRunner<
|
|||
// Ensure API key is still valid and user has access
|
||||
try {
|
||||
alert = await rulesClient.get({ id: alertId });
|
||||
|
||||
if (apm.currentTransaction) {
|
||||
apm.currentTransaction.name = `Execute Alerting Rule: "${alert.name}"`;
|
||||
apm.currentTransaction.addLabels({
|
||||
alerting_rule_consumer: alert.consumer,
|
||||
alerting_rule_name: alert.name,
|
||||
alerting_rule_tags: alert.tags.join(', '),
|
||||
alerting_rule_type_id: alert.alertTypeId,
|
||||
alerting_rule_params: JSON.stringify(alert.params),
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
throw new ErrorWithReason(AlertExecutionStatusErrorReasons.Read, err);
|
||||
}
|
||||
|
@ -560,6 +571,13 @@ export class TaskRunner<
|
|||
schedule: taskSchedule,
|
||||
} = this.taskInstance;
|
||||
|
||||
if (apm.currentTransaction) {
|
||||
apm.currentTransaction.name = `Execute Alerting Rule`;
|
||||
apm.currentTransaction.addLabels({
|
||||
alerting_rule_id: alertId,
|
||||
});
|
||||
}
|
||||
|
||||
const runDate = new Date();
|
||||
const runDateString = runDate.toISOString();
|
||||
this.logger.debug(`executing alert ${this.alertType.id}:${alertId} at ${runDateString}`);
|
||||
|
@ -615,6 +633,14 @@ export class TaskRunner<
|
|||
executionStatus.lastExecutionDate = new Date(event.event.start);
|
||||
}
|
||||
|
||||
if (apm.currentTransaction) {
|
||||
if (executionStatus.status === 'ok' || executionStatus.status === 'active') {
|
||||
apm.currentTransaction.setOutcome('success');
|
||||
} else if (executionStatus.status === 'error' || executionStatus.status === 'unknown') {
|
||||
apm.currentTransaction.setOutcome('failure');
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
`alertExecutionStatus for ${this.alertType.id}:${alertId}: ${JSON.stringify(executionStatus)}`
|
||||
);
|
||||
|
@ -855,6 +881,12 @@ function generateNewAndRecoveredInstanceEvents<
|
|||
const recoveredAlertInstanceIds = Object.keys(recoveredAlertInstances);
|
||||
const newIds = without(currentAlertInstanceIds, ...originalAlertInstanceIds);
|
||||
|
||||
if (apm.currentTransaction) {
|
||||
apm.currentTransaction.addLabels({
|
||||
alerting_new_alerts: newIds.length,
|
||||
});
|
||||
}
|
||||
|
||||
for (const id of recoveredAlertInstanceIds) {
|
||||
const { group: actionGroup, subgroup: actionSubgroup } =
|
||||
recoveredAlertInstances[id].getLastScheduledActions() ?? {};
|
||||
|
@ -1035,6 +1067,14 @@ function logActiveAndRecoveredInstances<
|
|||
const { logger, activeAlertInstances, recoveredAlertInstances, alertLabel } = params;
|
||||
const activeInstanceIds = Object.keys(activeAlertInstances);
|
||||
const recoveredInstanceIds = Object.keys(recoveredAlertInstances);
|
||||
|
||||
if (apm.currentTransaction) {
|
||||
apm.currentTransaction.addLabels({
|
||||
alerting_active_alerts: activeInstanceIds.length,
|
||||
alerting_recovered_alerts: recoveredInstanceIds.length,
|
||||
});
|
||||
}
|
||||
|
||||
if (activeInstanceIds.length > 0) {
|
||||
logger.debug(
|
||||
`alert ${alertLabel} has ${activeInstanceIds.length} active alert instances: ${JSON.stringify(
|
||||
|
|
|
@ -35,6 +35,9 @@ jest.mock('uuid', () => ({
|
|||
|
||||
jest.mock('elastic-apm-node', () => ({
|
||||
currentTraceparent: 'parent',
|
||||
currentTransaction: {
|
||||
type: 'taskManager run',
|
||||
},
|
||||
}));
|
||||
|
||||
describe('TaskScheduling', () => {
|
||||
|
|
|
@ -99,9 +99,15 @@ export class TaskScheduling {
|
|||
...options,
|
||||
taskInstance: ensureDeprecatedFieldsAreCorrected(taskInstance, this.logger),
|
||||
});
|
||||
|
||||
const traceparent =
|
||||
agent.currentTransaction && agent.currentTransaction.type !== 'request'
|
||||
? agent.currentTraceparent
|
||||
: '';
|
||||
|
||||
return await this.store.schedule({
|
||||
...modifiedTask,
|
||||
traceparent: agent.currentTraceparent ?? '',
|
||||
traceparent: traceparent || '',
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue