Skip to content

Commit a99d1e5

Browse files
mikecoteCAWilson94
authored andcommitted
Exclude unrecognized tasks from the task manager aggregate API (elastic#202163)
In this PR, I'm removing tasks with a status `unrecognized` from returning on any `taskStore.aggregate` calls. Without this, we had unrecognized recurring tasks that were still part of the task manager capacity calculation under `assumedAverageRecurringRequiredThroughputPerMinutePerKibana`. ## To Verify 1. Create a few ES Query alerting rules running every 1s 2. Capture the task manager health API report via `/api/task_manager/_health` 3. Apply the following diff to mark es query alerting tasks as unrecognized ``` diff --git a/x-pack/plugins/stack_alerts/server/rule_types/es_query/index.ts b/x-pack/plugins/stack_alerts/server/rule_types/es_query/index.ts index 1988eeb..8d649f4c6a5 100644 --- a/x-pack/plugins/stack_alerts/server/rule_types/es_query/index.ts +++ b/x-pack/plugins/stack_alerts/server/rule_types/es_query/index.ts @@ -10,5 +10,5 @@ import { getRuleType } from './rule_type'; export function register(params: RegisterRuleTypesParams, isServerless: boolean) { const { alerting, core } = params; - alerting.registerType(getRuleType(core, isServerless)); + // alerting.registerType(getRuleType(core, isServerless)); } diff --git a/x-pack/plugins/task_manager/server/removed_tasks/mark_removed_tasks_as_unrecognized.ts b/x-pack/plugins/task_manager/server/removed_tasks/mark_removed_tasks_as_unrecognized.ts index e28d522..dbfc1bbd135 100644 --- a/x-pack/plugins/task_manager/server/removed_tasks/mark_removed_tasks_as_unrecognized.ts +++ b/x-pack/plugins/task_manager/server/removed_tasks/mark_removed_tasks_as_unrecognized.ts @@ -33,6 +33,11 @@ export async function scheduleMarkRemovedTasksAsUnrecognizedDefinition( state: {}, params: {}, }); + try { + await taskScheduling.runSoon(TASK_ID); + } catch (e) { + // Ignore + } } catch (e) { logger.error(`Error scheduling ${TASK_ID} task, received ${e.message}`); } diff --git a/x-pack/plugins/task_manager/server/task_type_dictionary.ts b/x-pack/plugins/task_manager/server/task_type_dictionary.ts index e0b28ec..142c07bb507 100644 --- a/x-pack/plugins/task_manager/server/task_type_dictionary.ts +++ b/x-pack/plugins/task_manager/server/task_type_dictionary.ts @@ -32,6 +32,8 @@ export const REMOVED_TYPES: string[] = [ 'cleanup_failed_action_executions', 'reports:monitor', + + 'alerting:.es-query', ]; /** ``` 5. Capture the task manager health API report again via `/api/task_manager/_health` 6. Notice the number dropped for `capacity_estimation.value.observed.avg_recurring_required_throughput_per_minute`
1 parent 4f1415f commit a99d1e5

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,14 @@ describe('TaskStore', () => {
555555
body: {
556556
size: 0,
557557
query: {
558-
bool: { filter: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }] },
558+
bool: {
559+
filter: {
560+
bool: {
561+
must: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }],
562+
must_not: [{ term: { 'task.status': 'unrecognized' } }],
563+
},
564+
},
565+
},
559566
},
560567
aggs: { testAgg: { terms: { field: 'task.taskType' } } },
561568
},
@@ -578,7 +585,12 @@ describe('TaskStore', () => {
578585
must: [
579586
{
580587
bool: {
581-
filter: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }],
588+
filter: {
589+
bool: {
590+
must: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }],
591+
must_not: [{ term: { 'task.status': 'unrecognized' } }],
592+
},
593+
},
582594
},
583595
},
584596
{ term: { 'task.taskType': 'bar' } },
@@ -600,7 +612,14 @@ describe('TaskStore', () => {
600612
body: {
601613
size: 0,
602614
query: {
603-
bool: { filter: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }] },
615+
bool: {
616+
filter: {
617+
bool: {
618+
must: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }],
619+
must_not: [{ term: { 'task.status': 'unrecognized' } }],
620+
},
621+
},
622+
},
604623
},
605624
aggs: { testAgg: { terms: { field: 'task.taskType' } } },
606625
runtime_mappings: { testMapping: { type: 'long', script: { source: `` } } },

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
ConcreteTaskInstance,
3535
ConcreteTaskInstanceVersion,
3636
TaskInstance,
37+
TaskStatus,
3738
TaskLifecycle,
3839
TaskLifecycleResult,
3940
SerializedConcreteTaskInstance,
@@ -842,7 +843,12 @@ function ensureAggregationOnlyReturnsEnabledTaskObjects(opts: AggregationOpts):
842843
const originalQuery = opts.query;
843844
const filterToOnlyTasks = {
844845
bool: {
845-
filter: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }],
846+
filter: {
847+
bool: {
848+
must: [{ term: { type: 'task' } }, { term: { 'task.enabled': true } }],
849+
must_not: [{ term: { 'task.status': TaskStatus.Unrecognized } }],
850+
},
851+
},
846852
},
847853
};
848854
const query = originalQuery

0 commit comments

Comments
 (0)