Skip to content

Commit eb9411c

Browse files
kibanamachineymao1elasticmachine
authored
[8.x] [Response Ops][Task Manager] Adding background task to mark removed task types as `unrecognized` (#199057) (#199706)
# Backport This will backport the following commits from `main` to `8.x`: - [[Response Ops][Task Manager] Adding background task to mark removed task types as &#x60;unrecognized&#x60; (#199057)](#199057) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ying Mao","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-11T20:17:46Z","message":"[Response Ops][Task Manager] Adding background task to mark removed task types as `unrecognized` (#199057)\n\nResolves https://github.com/elastic/kibana/issues/192686\r\n\r\n## Summary\r\n\r\nCreates a background task to search for removed task types and mark them\r\nas unrecognized. Removes the current logic that does this during the\r\ntask claim cycle for both task claim strategies.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"be949d66e43ae24e9bce4a13a4613ad00e1dce9a","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:Task Manager","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.17.0"],"title":"[Response Ops][Task Manager] Adding background task to mark removed task types as `unrecognized`","number":199057,"url":"https://github.com/elastic/kibana/pull/199057","mergeCommit":{"message":"[Response Ops][Task Manager] Adding background task to mark removed task types as `unrecognized` (#199057)\n\nResolves https://github.com/elastic/kibana/issues/192686\r\n\r\n## Summary\r\n\r\nCreates a background task to search for removed task types and mark them\r\nas unrecognized. Removes the current logic that does this during the\r\ntask claim cycle for both task claim strategies.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"be949d66e43ae24e9bce4a13a4613ad00e1dce9a"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199057","number":199057,"mergeCommit":{"message":"[Response Ops][Task Manager] Adding background task to mark removed task types as `unrecognized` (#199057)\n\nResolves https://github.com/elastic/kibana/issues/192686\r\n\r\n## Summary\r\n\r\nCreates a background task to search for removed task types and mark them\r\nas unrecognized. Removes the current logic that does this during the\r\ntask claim cycle for both task claim strategies.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"be949d66e43ae24e9bce4a13a4613ad00e1dce9a"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Ying Mao <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent ddbaeae commit eb9411c

File tree

22 files changed

+547
-556
lines changed

22 files changed

+547
-556
lines changed

x-pack/plugins/task_manager/server/plugin.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { TaskManagerConfig } from './config';
2929
import { createInitialMiddleware, addMiddlewareToChain, Middleware } from './lib/middleware';
3030
import { removeIfExists } from './lib/remove_if_exists';
3131
import { setupSavedObjects, BACKGROUND_TASK_NODE_SO_NAME, TASK_SO_NAME } from './saved_objects';
32-
import { TaskDefinitionRegistry, TaskTypeDictionary, REMOVED_TYPES } from './task_type_dictionary';
32+
import { TaskDefinitionRegistry, TaskTypeDictionary } from './task_type_dictionary';
3333
import { AggregationOpts, FetchResult, SearchOpts, TaskStore } from './task_store';
3434
import { createManagedConfiguration } from './lib/create_managed_configuration';
3535
import { TaskScheduling } from './task_scheduling';
@@ -45,6 +45,10 @@ import { metricsStream, Metrics } from './metrics';
4545
import { TaskManagerMetricsCollector } from './metrics/task_metrics_collector';
4646
import { TaskPartitioner } from './lib/task_partitioner';
4747
import { getDefaultCapacity } from './lib/get_default_capacity';
48+
import {
49+
registerMarkRemovedTasksAsUnrecognizedDefinition,
50+
scheduleMarkRemovedTasksAsUnrecognizedDefinition,
51+
} from './removed_tasks/mark_removed_tasks_as_unrecognized';
4852

4953
export interface TaskManagerSetupContract {
5054
/**
@@ -221,6 +225,11 @@ export class TaskManagerPlugin
221225
}
222226

223227
registerDeleteInactiveNodesTaskDefinition(this.logger, core.getStartServices, this.definitions);
228+
registerMarkRemovedTasksAsUnrecognizedDefinition(
229+
this.logger,
230+
core.getStartServices,
231+
this.definitions
232+
);
224233

225234
if (this.config.unsafe.exclude_task_types.length) {
226235
this.logger.warn(
@@ -332,7 +341,6 @@ export class TaskManagerPlugin
332341
this.taskPollingLifecycle = new TaskPollingLifecycle({
333342
config: this.config!,
334343
definitions: this.definitions,
335-
unusedTypes: REMOVED_TYPES,
336344
logger: this.logger,
337345
executionContext,
338346
taskStore,
@@ -384,6 +392,7 @@ export class TaskManagerPlugin
384392
});
385393

386394
scheduleDeleteInactiveNodesTaskDefinition(this.logger, taskScheduling).catch(() => {});
395+
scheduleMarkRemovedTasksAsUnrecognizedDefinition(this.logger, taskScheduling).catch(() => {});
387396

388397
return {
389398
fetch: (opts: SearchOpts): Promise<FetchResult> => taskStore.fetch(opts),

x-pack/plugins/task_manager/server/polling_lifecycle.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ describe('TaskPollingLifecycle', () => {
106106
},
107107
taskStore: mockTaskStore,
108108
logger: taskManagerLogger,
109-
unusedTypes: [],
110109
definitions: new TaskTypeDictionary(taskManagerLogger),
111110
middleware: createInitialMiddleware(),
112111
startingCapacity: 20,

x-pack/plugins/task_manager/server/polling_lifecycle.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export interface ITaskEventEmitter<T> {
5555
export type TaskPollingLifecycleOpts = {
5656
logger: Logger;
5757
definitions: TaskTypeDictionary;
58-
unusedTypes: string[];
5958
taskStore: TaskStore;
6059
config: TaskManagerConfig;
6160
middleware: Middleware;
@@ -115,7 +114,6 @@ export class TaskPollingLifecycle implements ITaskEventEmitter<TaskLifecycleEven
115114
config,
116115
taskStore,
117116
definitions,
118-
unusedTypes,
119117
executionContext,
120118
usageCounter,
121119
taskPartitioner,
@@ -153,7 +151,6 @@ export class TaskPollingLifecycle implements ITaskEventEmitter<TaskLifecycleEven
153151
maxAttempts: config.max_attempts,
154152
excludedTaskTypes: config.unsafe.exclude_task_types,
155153
definitions,
156-
unusedTypes,
157154
logger: this.logger,
158155
getAvailableCapacity: (taskType?: string) => this.pool.availableCapacity(taskType),
159156
taskPartitioner,

x-pack/plugins/task_manager/server/queries/mark_available_tasks_as_claimed.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe('mark_available_tasks_as_claimed', () => {
7070
fieldUpdates,
7171
claimableTaskTypes: definitions.getAllTypes(),
7272
skippedTaskTypes: [],
73-
unusedTaskTypes: [],
7473
taskMaxAttempts: Array.from(definitions).reduce((accumulator, [type, { maxAttempts }]) => {
7574
return { ...accumulator, [type]: maxAttempts || defaultMaxAttempts };
7675
}, {}),
@@ -153,8 +152,6 @@ if (doc['task.runAt'].size()!=0) {
153152
ctx._source.task.status = "claiming"; ${Object.keys(fieldUpdates)
154153
.map((field) => `ctx._source.task.${field}=params.fieldUpdates.${field};`)
155154
.join(' ')}
156-
} else if (params.unusedTaskTypes.contains(ctx._source.task.taskType)) {
157-
ctx._source.task.status = "unrecognized";
158155
} else {
159156
ctx.op = "noop";
160157
}`,
@@ -167,7 +164,6 @@ if (doc['task.runAt'].size()!=0) {
167164
},
168165
claimableTaskTypes: ['sampleTask', 'otherTask'],
169166
skippedTaskTypes: [],
170-
unusedTaskTypes: [],
171167
taskMaxAttempts: {
172168
sampleTask: 5,
173169
otherTask: 1,
@@ -242,7 +238,6 @@ if (doc['task.runAt'].size()!=0) {
242238
fieldUpdates,
243239
claimableTaskTypes: ['foo', 'bar'],
244240
skippedTaskTypes: [],
245-
unusedTaskTypes: [],
246241
taskMaxAttempts: {
247242
foo: 5,
248243
bar: 2,

x-pack/plugins/task_manager/server/queries/mark_available_tasks_as_claimed.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,13 @@ export interface UpdateFieldsAndMarkAsFailedOpts {
202202
};
203203
claimableTaskTypes: string[];
204204
skippedTaskTypes: string[];
205-
unusedTaskTypes: string[];
206205
taskMaxAttempts: { [field: string]: number };
207206
}
208207

209208
export const updateFieldsAndMarkAsFailed = ({
210209
fieldUpdates,
211210
claimableTaskTypes,
212211
skippedTaskTypes,
213-
unusedTaskTypes,
214212
taskMaxAttempts,
215213
}: UpdateFieldsAndMarkAsFailedOpts): ScriptClause => {
216214
const setScheduledAtScript = `if(ctx._source.task.retryAt != null && ZonedDateTime.parse(ctx._source.task.retryAt).toInstant().toEpochMilli() < params.now) {
@@ -227,8 +225,6 @@ export const updateFieldsAndMarkAsFailed = ({
227225
source: `
228226
if (params.claimableTaskTypes.contains(ctx._source.task.taskType)) {
229227
${setScheduledAtAndMarkAsClaimed}
230-
} else if (params.unusedTaskTypes.contains(ctx._source.task.taskType)) {
231-
ctx._source.task.status = "unrecognized";
232228
} else {
233229
ctx.op = "noop";
234230
}`,
@@ -238,7 +234,6 @@ export const updateFieldsAndMarkAsFailed = ({
238234
fieldUpdates,
239235
claimableTaskTypes,
240236
skippedTaskTypes,
241-
unusedTaskTypes,
242237
taskMaxAttempts,
243238
},
244239
};

x-pack/plugins/task_manager/server/queries/task_claiming.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ describe('TaskClaiming', () => {
8383
strategy: 'non-default',
8484
definitions,
8585
excludedTaskTypes: [],
86-
unusedTypes: [],
8786
taskStore: taskStoreMock.create({ taskManagerId: '' }),
8887
maxAttempts: 2,
8988
getAvailableCapacity: () => 10,
@@ -134,7 +133,6 @@ describe('TaskClaiming', () => {
134133
strategy: 'default',
135134
definitions,
136135
excludedTaskTypes: [],
137-
unusedTypes: [],
138136
taskStore: taskStoreMock.create({ taskManagerId: '' }),
139137
maxAttempts: 2,
140138
getAvailableCapacity: () => 10,

x-pack/plugins/task_manager/server/queries/task_claiming.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export interface TaskClaimingOpts {
3434
logger: Logger;
3535
strategy: string;
3636
definitions: TaskTypeDictionary;
37-
unusedTypes: string[];
3837
taskStore: TaskStore;
3938
maxAttempts: number;
4039
excludedTaskTypes: string[];
@@ -92,7 +91,6 @@ export class TaskClaiming {
9291
private readonly taskClaimingBatchesByType: TaskClaimingBatches;
9392
private readonly taskMaxAttempts: Record<string, number>;
9493
private readonly excludedTaskTypes: string[];
95-
private readonly unusedTypes: string[];
9694
private readonly taskClaimer: TaskClaimerFn;
9795
private readonly taskPartitioner: TaskPartitioner;
9896

@@ -111,7 +109,6 @@ export class TaskClaiming {
111109
this.taskClaimingBatchesByType = this.partitionIntoClaimingBatches(this.definitions);
112110
this.taskMaxAttempts = Object.fromEntries(this.normalizeMaxAttempts(this.definitions));
113111
this.excludedTaskTypes = opts.excludedTaskTypes;
114-
this.unusedTypes = opts.unusedTypes;
115112
this.taskClaimer = getTaskClaimer(this.logger, opts.strategy);
116113
this.events$ = new Subject<TaskClaim>();
117114
this.taskPartitioner = opts.taskPartitioner;
@@ -178,7 +175,6 @@ export class TaskClaiming {
178175
taskStore: this.taskStore,
179176
events$: this.events$,
180177
getCapacity: this.getAvailableCapacity,
181-
unusedTypes: this.unusedTypes,
182178
definitions: this.definitions,
183179
taskMaxAttempts: this.taskMaxAttempts,
184180
excludedTaskTypes: this.excludedTaskTypes,

0 commit comments

Comments
 (0)