From 177d93409712774ac4c39895c07bed97d0bb1840 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Thu, 21 Apr 2022 11:13:08 -0400 Subject: [PATCH] Moving some things around --- x-pack/plugins/actions/common/types.ts | 1 - .../plugins/actions/server/lib/action_executor.ts | 14 +++++++++++--- .../actions/server/lib/task_runner_factory.ts | 10 +--------- x-pack/plugins/actions/server/plugin.ts | 12 ++++++------ .../server/monitoring/node_level_metrics.ts | 3 ++- .../plugins/monitoring_collection/server/plugin.ts | 12 ++++++------ 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/actions/common/types.ts b/x-pack/plugins/actions/common/types.ts index 43fba02eab89..20de64a7cc3b 100644 --- a/x-pack/plugins/actions/common/types.ts +++ b/x-pack/plugins/actions/common/types.ts @@ -32,7 +32,6 @@ type ActionTypeExecutorResultStatus = typeof ActionTypeExecutorResultStatusValue export interface ActionTypeExecutorResult { actionId: string; - actionTypeId?: string; status: ActionTypeExecutorResultStatus; message?: string; serviceMessage?: string; diff --git a/x-pack/plugins/actions/server/lib/action_executor.ts b/x-pack/plugins/actions/server/lib/action_executor.ts index b5201f5d2e85..fd6ff5ebaf67 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.ts @@ -30,6 +30,7 @@ import { ActionsClient } from '../actions_client'; import { ActionExecutionSource } from './action_execution_source'; import { RelatedSavedObjects } from './related_saved_objects'; import { createActionEventLogRecordObject } from './create_action_event_log_record_object'; +import { NodeLevelMetrics } from '../monitoring'; // 1,000,000 nanoseconds in 1 millisecond const Millis2Nanos = 1000 * 1000; @@ -46,6 +47,7 @@ export interface ActionExecutorContext { actionTypeRegistry: ActionTypeRegistryContract; eventLogger: IEventLogger; preconfiguredActions: PreConfiguredAction[]; + nodeLevelMetrics?: NodeLevelMetrics; } export interface TaskInfo { @@ -247,10 +249,14 @@ export class ActionExecutor { status: 'ok', }; - result.actionTypeId = actionTypeId; - event.event = event.event || {}; + this.actionExecutorContext?.nodeLevelMetrics?.execution( + actionId, + actionTypeId, + event.event?.duration ? event.event?.duration / Millis2Nanos : undefined + ); + if (result.status === 'ok') { span?.setOutcome('success'); event.event.outcome = 'success'; @@ -262,6 +268,7 @@ export class ActionExecutor { event.error = event.error || {}; event.error.message = actionErrorToMessage(result); logger.warn(`action execution failure: ${actionLabel}: ${event.error.message}`); + this.actionExecutorContext?.nodeLevelMetrics?.failure(actionId, actionTypeId); } else { span?.setOutcome('failure'); event.event.outcome = 'failure'; @@ -271,6 +278,7 @@ export class ActionExecutor { logger.warn( `action execution failure: ${actionLabel}: returned unexpected result "${result.status}"` ); + this.actionExecutorContext?.nodeLevelMetrics?.failure(actionId, actionTypeId); } eventLogger.logEvent(event); @@ -347,7 +355,7 @@ export class ActionExecutor { }); eventLogger.logEvent(event); - return this.actionInfo; + this.actionExecutorContext?.nodeLevelMetrics?.timeout(actionId, this.actionInfo.actionTypeId); } } diff --git a/x-pack/plugins/actions/server/lib/task_runner_factory.ts b/x-pack/plugins/actions/server/lib/task_runner_factory.ts index 35ed221d8e51..2e342a7c6227 100644 --- a/x-pack/plugins/actions/server/lib/task_runner_factory.ts +++ b/x-pack/plugins/actions/server/lib/task_runner_factory.ts @@ -34,7 +34,6 @@ import { ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE } from '../constants/saved_objects import { asSavedObjectExecutionSource } from './action_execution_source'; import { RelatedSavedObjects, validatedRelatedSavedObjects } from './related_saved_objects'; import { injectSavedObjectReferences } from './action_task_params_utils'; -import { NodeLevelMetrics } from '../monitoring'; export interface TaskRunnerContext { logger: Logger; @@ -43,7 +42,6 @@ export interface TaskRunnerContext { spaceIdToNamespace: SpaceIdToNamespaceFunction; basePathService: IBasePath; getUnsecuredSavedObjectsClient: (request: KibanaRequest) => SavedObjectsClientContract; - nodeLevelMetrics?: NodeLevelMetrics; } export class TaskRunnerFactory { @@ -75,7 +73,6 @@ export class TaskRunnerFactory { spaceIdToNamespace, basePathService, getUnsecuredSavedObjectsClient, - nodeLevelMetrics, } = this.taskRunnerContext!; const taskInfo = { @@ -134,14 +131,12 @@ export class TaskRunnerFactory { } } - nodeLevelMetrics?.execution(actionId, executorResult?.actionTypeId); if ( executorResult && executorResult?.status === 'error' && executorResult?.retry !== undefined && isRetryableBasedOnAttempts ) { - nodeLevelMetrics?.failure(actionId); logger.error( `Action '${actionId}' failed ${ !!executorResult.retry ? willRetryMessage : willNotRetryMessage @@ -155,7 +150,6 @@ export class TaskRunnerFactory { executorResult.retry as boolean | Date ); } else if (executorResult && executorResult?.status === 'error') { - nodeLevelMetrics?.failure(actionId, executorResult?.actionTypeId); logger.error( `Action '${actionId}' failed ${willNotRetryMessage}: ${executorResult.message}` ); @@ -198,7 +192,7 @@ export class TaskRunnerFactory { const path = addSpaceIdToPath('/', spaceId); basePathService.set(request, path); - const actionInfo = await actionExecutor.logCancellation({ + await actionExecutor.logCancellation({ actionId, request, consumer, @@ -207,8 +201,6 @@ export class TaskRunnerFactory { ...getSourceFromReferences(references), }); - nodeLevelMetrics?.timeout(actionId, actionInfo?.actionTypeId); - logger.debug( `Cancelling action task for action with id ${actionId} - execution error due to timeout.` ); diff --git a/x-pack/plugins/actions/server/plugin.ts b/x-pack/plugins/actions/server/plugin.ts index ee03898478f2..43631d999c7d 100644 --- a/x-pack/plugins/actions/server/plugin.ts +++ b/x-pack/plugins/actions/server/plugin.ts @@ -438,6 +438,11 @@ export class ActionsPlugin implements Plugin core.savedObjects.getScopedClient(request); + let nodeLevelMetrics; + if (plugins.monitoringCollection) { + nodeLevelMetrics = new NodeLevelMetrics(plugins.monitoringCollection); + } + actionExecutor!.initialize({ logger, eventLogger: this.eventLogger!, @@ -452,13 +457,9 @@ export class ActionsPlugin implements Plugin spaceIdToNamespace(plugins.spaces, spaceId), getUnsecuredSavedObjectsClient: (request: KibanaRequest) => this.getUnsecuredSavedObjectsClient(core.savedObjects, request), - nodeLevelMetrics, }); this.eventLogService!.isEsContextReady().then(() => { diff --git a/x-pack/plugins/alerting/server/monitoring/node_level_metrics.ts b/x-pack/plugins/alerting/server/monitoring/node_level_metrics.ts index 0a939e34007e..2400de288389 100644 --- a/x-pack/plugins/alerting/server/monitoring/node_level_metrics.ts +++ b/x-pack/plugins/alerting/server/monitoring/node_level_metrics.ts @@ -29,8 +29,9 @@ export class NodeLevelMetrics { } public failure(ruleId: string, reason: RuleExecutionStatusErrorReasons) { - this.monitoringCollection.reportCounter(`${PREFIX}rule_${reason}_failures`, { + this.monitoringCollection.reportCounter(`${PREFIX}rule_failures`, { rule_id: ruleId, + failure_reason: reason, }); } diff --git a/x-pack/plugins/monitoring_collection/server/plugin.ts b/x-pack/plugins/monitoring_collection/server/plugin.ts index 0cd9e0c9d7ca..42398a6165d4 100644 --- a/x-pack/plugins/monitoring_collection/server/plugin.ts +++ b/x-pack/plugins/monitoring_collection/server/plugin.ts @@ -39,9 +39,9 @@ export interface MetricSet { } export type KibanaIdentifier = Record & { - version: string; - uuid: string; - cluster_uuid?: string; + kibana_version: string; + kibana_uuid: string; + es_cluster_uuid?: string; }; export class MonitoringCollectionPlugin implements Plugin { @@ -114,8 +114,8 @@ export class MonitoringCollectionPlugin implements Plugin { @@ -123,7 +123,7 @@ export class MonitoringCollectionPlugin implements Plugin {