Skip to content

Commit

Permalink
Bring back task runner tests and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiWu committed Nov 29, 2024
1 parent 6935204 commit b2981fa
Show file tree
Hide file tree
Showing 3 changed files with 1,065 additions and 106 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export const config: PluginConfigDescriptor<AlertingConfig> = {
rules: { run: { alerts: { max: true } } },
},
deprecations: ({ renameFromRoot, deprecate }) => [
deprecate('maxEphemeralActionsPerAlert', 'a future version', {
deprecate('maxEphemeralActionsPerAlert', '9.0.0', {
level: 'warning',
message: `Configuring "xpack.alerting.maxEphemeralActionsPerAlert" is deprecated and will be removed in a future version. Remove this setting to increase action execution resiliency.`,
message: `The setting "xpack.alerting.maxEphemeralActionsPerAlert" is deprecated and currently ignored by the system. Please remove this setting.`,
}),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { createTaskRunError, TaskErrorSource } from '@kbn/task-manager-plugin/server';
import {
ExecuteOptions as EnqueueExecutionOptions,
ExecutionResponseItem,
ExecutionResponseType,
} from '@kbn/actions-plugin/server/create_execute_function';
Expand Down Expand Up @@ -94,34 +93,28 @@ export class ActionScheduler<
return { throttledSummaryActions };
}

const bulkScheduleRequest: EnqueueExecutionOptions[] = [];

for (const result of allActionsToScheduleResult) {
bulkScheduleRequest.push(result.actionToEnqueue);
}

let bulkScheduleResponse: ExecutionResponseItem[] = [];

if (!!bulkScheduleRequest.length) {
for (const c of chunk(bulkScheduleRequest, BULK_SCHEDULE_CHUNK_SIZE)) {
let enqueueResponse;
try {
enqueueResponse = await withAlertingSpan('alerting:bulk-enqueue-actions', () =>
this.context.actionsClient!.bulkEnqueueExecution(c)
);
} catch (e) {
if (e.statusCode === 404) {
throw createTaskRunError(e, TaskErrorSource.USER);
}
throw createTaskRunError(e, TaskErrorSource.FRAMEWORK);
}
if (enqueueResponse.errors) {
bulkScheduleResponse = bulkScheduleResponse.concat(
enqueueResponse.items.filter(
(i) => i.response === ExecutionResponseType.QUEUED_ACTIONS_LIMIT_ERROR
)
);
for (const c of chunk(allActionsToScheduleResult, BULK_SCHEDULE_CHUNK_SIZE)) {
let enqueueResponse;
try {
enqueueResponse = await withAlertingSpan('alerting:bulk-enqueue-actions', () =>
this.context.actionsClient!.bulkEnqueueExecution(
c.map((actions) => actions.actionToEnqueue)
)
);
} catch (e) {
if (e.statusCode === 404) {
throw createTaskRunError(e, TaskErrorSource.USER);
}
throw createTaskRunError(e, TaskErrorSource.FRAMEWORK);
}
if (enqueueResponse.errors) {
bulkScheduleResponse = bulkScheduleResponse.concat(
enqueueResponse.items.filter(
(i) => i.response === ExecutionResponseType.QUEUED_ACTIONS_LIMIT_ERROR
)
);
}
}

Expand Down
Loading

0 comments on commit b2981fa

Please sign in to comment.