Skip to content

Commit

Permalink
Moving some things around
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Apr 21, 2022
1 parent 164a9de commit 177d934
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/actions/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type ActionTypeExecutorResultStatus = typeof ActionTypeExecutorResultStatusValue

export interface ActionTypeExecutorResult<Data> {
actionId: string;
actionTypeId?: string;
status: ActionTypeExecutorResultStatus;
message?: string;
serviceMessage?: string;
Expand Down
14 changes: 11 additions & 3 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +47,7 @@ export interface ActionExecutorContext {
actionTypeRegistry: ActionTypeRegistryContract;
eventLogger: IEventLogger;
preconfiguredActions: PreConfiguredAction[];
nodeLevelMetrics?: NodeLevelMetrics;
}

export interface TaskInfo {
Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -347,7 +355,7 @@ export class ActionExecutor {
});

eventLogger.logEvent(event);
return this.actionInfo;
this.actionExecutorContext?.nodeLevelMetrics?.timeout(actionId, this.actionInfo.actionTypeId);
}
}

Expand Down
10 changes: 1 addition & 9 deletions x-pack/plugins/actions/server/lib/task_runner_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +42,6 @@ export interface TaskRunnerContext {
spaceIdToNamespace: SpaceIdToNamespaceFunction;
basePathService: IBasePath;
getUnsecuredSavedObjectsClient: (request: KibanaRequest) => SavedObjectsClientContract;
nodeLevelMetrics?: NodeLevelMetrics;
}

export class TaskRunnerFactory {
Expand Down Expand Up @@ -75,7 +73,6 @@ export class TaskRunnerFactory {
spaceIdToNamespace,
basePathService,
getUnsecuredSavedObjectsClient,
nodeLevelMetrics,
} = this.taskRunnerContext!;

const taskInfo = {
Expand Down Expand Up @@ -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
Expand All @@ -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}`
);
Expand Down Expand Up @@ -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,
Expand All @@ -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.`
);
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ export class ActionsPlugin implements Plugin<PluginSetupContract, PluginStartCon
const getScopedSavedObjectsClientWithoutAccessToActions = (request: KibanaRequest) =>
core.savedObjects.getScopedClient(request);

let nodeLevelMetrics;
if (plugins.monitoringCollection) {
nodeLevelMetrics = new NodeLevelMetrics(plugins.monitoringCollection);
}

actionExecutor!.initialize({
logger,
eventLogger: this.eventLogger!,
Expand All @@ -452,13 +457,9 @@ export class ActionsPlugin implements Plugin<PluginSetupContract, PluginStartCon
encryptedSavedObjectsClient,
actionTypeRegistry: actionTypeRegistry!,
preconfiguredActions,
nodeLevelMetrics,
});

let nodeLevelMetrics;
if (plugins.monitoringCollection) {
nodeLevelMetrics = new NodeLevelMetrics(plugins.monitoringCollection);
}

taskRunnerFactory!.initialize({
logger,
actionTypeRegistry: actionTypeRegistry!,
Expand All @@ -467,7 +468,6 @@ export class ActionsPlugin implements Plugin<PluginSetupContract, PluginStartCon
spaceIdToNamespace: (spaceId?: string) => spaceIdToNamespace(plugins.spaces, spaceId),
getUnsecuredSavedObjectsClient: (request: KibanaRequest) =>
this.getUnsecuredSavedObjectsClient(core.savedObjects, request),
nodeLevelMetrics,
});

this.eventLogService!.isEsContextReady().then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/monitoring_collection/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export interface MetricSet {
}

export type KibanaIdentifier = Record<string, string> & {
version: string;
uuid: string;
cluster_uuid?: string;
kibana_version: string;
kibana_uuid: string;
es_cluster_uuid?: string;
};

export class MonitoringCollectionPlugin implements Plugin<MonitoringCollectionSetup, void, {}, {}> {
Expand Down Expand Up @@ -114,16 +114,16 @@ export class MonitoringCollectionPlugin implements Plugin<MonitoringCollectionSe
start(core: CoreStart) {
this.client = core.elasticsearch.client;
const kibanaDimensions: KibanaIdentifier = {
version: this.kibanaVersion!,
uuid: this.kibanaUuid!,
kibana_version: this.kibanaVersion!,
kibana_uuid: this.kibanaUuid!,
};

(async () => {
const response = await core.elasticsearch.client.asInternalUser.info({
filter_path: 'cluster_uuid',
});

kibanaDimensions.cluster_uuid = response.cluster_uuid;
kibanaDimensions.es_cluster_uuid = response.cluster_uuid;
})();

setInterval(async () => {
Expand Down

0 comments on commit 177d934

Please sign in to comment.