Skip to content

Commit

Permalink
[8.x] Set mget task claim strategy as the default (#197070) (#197826)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [Set mget task claim strategy as the default
(#197070)](#197070)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Mike
Côté","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-25T12:57:46Z","message":"Set
mget task claim strategy as the default (#197070)\n\nResolves
https://github.com/elastic/kibana/issues/194625\r\n\r\nIn this PR, I'm
setting `mget` as the default task claiming strategy\r\nalong the
following changes:\r\n- Given we no longer need the 8.16 specific
PRs\r\n(#196317
and\r\nhttps://github.com//pull/196757), I've also
reverted them.\r\n- Given we now use `met` as the default, I've
renamed\r\n`task_manager_claimer_mget` to
`task_manager_claimer_update_by_query`\r\nand made tests in that folder
test using the `update_by_query` claim\r\nstrategy.\r\n- Stabilize flaky
tests caused by mget + polling for tasks more\r\nfrequently\r\n\r\nFlaky
test
runners:\r\n-\r\n[[59b71bc](https://github.com/elastic/kibana/pull/197070/commits/59b71bcdbe4d617a6d91131976540b334c9220ff)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7197\r\n-\r\n[[aea910e](https://github.com/elastic/kibana/pull/197070/commits/aea910e36dc71116dee708a7168971df30a18a3d)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7199\r\n-\r\n[[4723ced](https://github.com/elastic/kibana/pull/197070/commits/4723ced751f0e5114a9bc7a2928dcf0cb326472e)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7206\r\n-\r\n[[d28c8c5](https://github.com/elastic/kibana/pull/197070/commits/d28c8c56f67802107c17a627357251b9eff797ba)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7209\r\n-\r\n[[dd7773a](https://github.com/elastic/kibana/pull/197070/commits/dd7773aebad5664e725c9849c0ed9418f9dc68ed)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7224\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c31f11e7d8c5c586258399c5e702e2247e05d0e4","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":"Set
mget task claim strategy as the
default","number":197070,"url":"https://github.com/elastic/kibana/pull/197070","mergeCommit":{"message":"Set
mget task claim strategy as the default (#197070)\n\nResolves
https://github.com/elastic/kibana/issues/194625\r\n\r\nIn this PR, I'm
setting `mget` as the default task claiming strategy\r\nalong the
following changes:\r\n- Given we no longer need the 8.16 specific
PRs\r\n(#196317
and\r\nhttps://github.com//pull/196757), I've also
reverted them.\r\n- Given we now use `met` as the default, I've
renamed\r\n`task_manager_claimer_mget` to
`task_manager_claimer_update_by_query`\r\nand made tests in that folder
test using the `update_by_query` claim\r\nstrategy.\r\n- Stabilize flaky
tests caused by mget + polling for tasks more\r\nfrequently\r\n\r\nFlaky
test
runners:\r\n-\r\n[[59b71bc](https://github.com/elastic/kibana/pull/197070/commits/59b71bcdbe4d617a6d91131976540b334c9220ff)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7197\r\n-\r\n[[aea910e](https://github.com/elastic/kibana/pull/197070/commits/aea910e36dc71116dee708a7168971df30a18a3d)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7199\r\n-\r\n[[4723ced](https://github.com/elastic/kibana/pull/197070/commits/4723ced751f0e5114a9bc7a2928dcf0cb326472e)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7206\r\n-\r\n[[d28c8c5](https://github.com/elastic/kibana/pull/197070/commits/d28c8c56f67802107c17a627357251b9eff797ba)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7209\r\n-\r\n[[dd7773a](https://github.com/elastic/kibana/pull/197070/commits/dd7773aebad5664e725c9849c0ed9418f9dc68ed)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7224\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c31f11e7d8c5c586258399c5e702e2247e05d0e4"}},"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/197070","number":197070,"mergeCommit":{"message":"Set
mget task claim strategy as the default (#197070)\n\nResolves
https://github.com/elastic/kibana/issues/194625\r\n\r\nIn this PR, I'm
setting `mget` as the default task claiming strategy\r\nalong the
following changes:\r\n- Given we no longer need the 8.16 specific
PRs\r\n(#196317
and\r\nhttps://github.com//pull/196757), I've also
reverted them.\r\n- Given we now use `met` as the default, I've
renamed\r\n`task_manager_claimer_mget` to
`task_manager_claimer_update_by_query`\r\nand made tests in that folder
test using the `update_by_query` claim\r\nstrategy.\r\n- Stabilize flaky
tests caused by mget + polling for tasks more\r\nfrequently\r\n\r\nFlaky
test
runners:\r\n-\r\n[[59b71bc](https://github.com/elastic/kibana/pull/197070/commits/59b71bcdbe4d617a6d91131976540b334c9220ff)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7197\r\n-\r\n[[aea910e](https://github.com/elastic/kibana/pull/197070/commits/aea910e36dc71116dee708a7168971df30a18a3d)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7199\r\n-\r\n[[4723ced](https://github.com/elastic/kibana/pull/197070/commits/4723ced751f0e5114a9bc7a2928dcf0cb326472e)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7206\r\n-\r\n[[d28c8c5](https://github.com/elastic/kibana/pull/197070/commits/d28c8c56f67802107c17a627357251b9eff797ba)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7209\r\n-\r\n[[dd7773a](https://github.com/elastic/kibana/pull/197070/commits/dd7773aebad5664e725c9849c0ed9418f9dc68ed)]\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7224\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c31f11e7d8c5c586258399c5e702e2247e05d0e4"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Mike Côté <[email protected]>
  • Loading branch information
kibanamachine and mikecote authored Oct 25, 2024
1 parent a7a2373 commit 8876584
Show file tree
Hide file tree
Showing 44 changed files with 128 additions and 405 deletions.
2 changes: 1 addition & 1 deletion .buildkite/ftr_platform_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ enabled:
- x-pack/test/spaces_api_integration/security_and_spaces/config_trial.ts
- x-pack/test/spaces_api_integration/security_and_spaces/copy_to_space_config_trial.ts
- x-pack/test/spaces_api_integration/spaces_only/config.ts
- x-pack/test/task_manager_claimer_mget/config.ts
- x-pack/test/task_manager_claimer_update_by_query/config.ts
- x-pack/test/ui_capabilities/security_and_spaces/config.ts
- x-pack/test/ui_capabilities/spaces_only/config.ts
- x-pack/test/upgrade_assistant_integration/config.js
Expand Down
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ x-pack/plugins/runtime_fields @elastic/kibana-management
packages/kbn-safer-lodash-set @elastic/kibana-security
x-pack/test/security_api_integration/plugins/saml_provider @elastic/kibana-security
x-pack/test/plugin_api_integration/plugins/sample_task_plugin @elastic/response-ops
x-pack/test/task_manager_claimer_mget/plugins/sample_task_plugin_mget @elastic/response-ops
x-pack/test/task_manager_claimer_update_by_query/plugins/sample_task_plugin_mget @elastic/response-ops
test/plugin_functional/plugins/saved_object_export_transforms @elastic/kibana-core
test/plugin_functional/plugins/saved_object_import_warnings @elastic/kibana-core
x-pack/test/saved_object_api_integration/common/plugins/saved_object_test_plugin @elastic/kibana-security
Expand Down Expand Up @@ -1457,7 +1457,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/test/alerting_api_integration/observability @elastic/obs-ux-management-team
/x-pack/test/plugin_api_integration/test_suites/task_manager/ @elastic/response-ops
/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/ @elastic/response-ops
/x-pack/test/task_manager_claimer_mget/ @elastic/response-ops
/x-pack/test/task_manager_claimer_update_by_query/ @elastic/response-ops
/docs/user/alerting/ @elastic/response-ops
/docs/management/connectors/ @elastic/response-ops
/x-pack/test/cases_api_integration/ @elastic/response-ops
Expand Down
1 change: 0 additions & 1 deletion config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ uiSettings:
labs:dashboard:deferBelowFold: false

# Task Manager
xpack.task_manager.claim_strategy: mget
xpack.task_manager.allow_reading_invalid_state: false
xpack.task_manager.request_timeouts.update_by_query: 60000
xpack.task_manager.metrics_reset_interval: 120000
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@
"@kbn/safer-lodash-set": "link:packages/kbn-safer-lodash-set",
"@kbn/saml-provider-plugin": "link:x-pack/test/security_api_integration/plugins/saml_provider",
"@kbn/sample-task-plugin": "link:x-pack/test/plugin_api_integration/plugins/sample_task_plugin",
"@kbn/sample-task-plugin-mget": "link:x-pack/test/task_manager_claimer_mget/plugins/sample_task_plugin_mget",
"@kbn/sample-task-plugin-update-by-query": "link:x-pack/test/task_manager_claimer_update_by_query/plugins/sample_task_plugin_mget",
"@kbn/saved-object-export-transforms-plugin": "link:test/plugin_functional/plugins/saved_object_export_transforms",
"@kbn/saved-object-import-warnings-plugin": "link:test/plugin_functional/plugins/saved_object_import_warnings",
"@kbn/saved-object-test-plugin": "link:x-pack/test/saved_object_api_integration/common/plugins/saved_object_test_plugin",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1480,8 +1480,8 @@
"@kbn/saml-provider-plugin/*": ["x-pack/test/security_api_integration/plugins/saml_provider/*"],
"@kbn/sample-task-plugin": ["x-pack/test/plugin_api_integration/plugins/sample_task_plugin"],
"@kbn/sample-task-plugin/*": ["x-pack/test/plugin_api_integration/plugins/sample_task_plugin/*"],
"@kbn/sample-task-plugin-mget": ["x-pack/test/task_manager_claimer_mget/plugins/sample_task_plugin_mget"],
"@kbn/sample-task-plugin-mget/*": ["x-pack/test/task_manager_claimer_mget/plugins/sample_task_plugin_mget/*"],
"@kbn/sample-task-plugin-update-by-query": ["x-pack/test/task_manager_claimer_update_by_query/plugins/sample_task_plugin_mget"],
"@kbn/sample-task-plugin-update-by-query/*": ["x-pack/test/task_manager_claimer_update_by_query/plugins/sample_task_plugin_mget/*"],
"@kbn/saved-object-export-transforms-plugin": ["test/plugin_functional/plugins/saved_object_export_transforms"],
"@kbn/saved-object-export-transforms-plugin/*": ["test/plugin_functional/plugins/saved_object_export_transforms/*"],
"@kbn/saved-object-import-warnings-plugin": ["test/plugin_functional/plugins/saved_object_import_warnings"],
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/task_manager/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('config validation', () => {
Object {
"allow_reading_invalid_state": true,
"auto_calculate_default_ech_capacity": false,
"claim_strategy": "mget",
"discovery": Object {
"active_nodes_lookback": "30s",
"interval": 10000,
Expand Down Expand Up @@ -44,7 +45,7 @@ describe('config validation', () => {
"warn_threshold": 80,
},
},
"poll_interval": 3000,
"poll_interval": 500,
"request_capacity": 1000,
"request_timeouts": Object {
"update_by_query": 30000,
Expand All @@ -66,7 +67,7 @@ describe('config validation', () => {
expect(() => {
configSchema.validate(config);
}).toThrowErrorMatchingInlineSnapshot(
`"The specified monitored_stats_required_freshness (100) is invalid, as it is below the poll_interval (3000)"`
`"The specified monitored_stats_required_freshness (100) is invalid, as it is below the poll_interval (500)"`
);
});

Expand All @@ -76,6 +77,7 @@ describe('config validation', () => {
Object {
"allow_reading_invalid_state": true,
"auto_calculate_default_ech_capacity": false,
"claim_strategy": "mget",
"discovery": Object {
"active_nodes_lookback": "30s",
"interval": 10000,
Expand Down Expand Up @@ -106,7 +108,7 @@ describe('config validation', () => {
"warn_threshold": 80,
},
},
"poll_interval": 3000,
"poll_interval": 500,
"request_capacity": 1000,
"request_timeouts": Object {
"update_by_query": 30000,
Expand Down Expand Up @@ -136,6 +138,7 @@ describe('config validation', () => {
Object {
"allow_reading_invalid_state": true,
"auto_calculate_default_ech_capacity": false,
"claim_strategy": "mget",
"discovery": Object {
"active_nodes_lookback": "30s",
"interval": 10000,
Expand Down Expand Up @@ -171,7 +174,7 @@ describe('config validation', () => {
"warn_threshold": 80,
},
},
"poll_interval": 3000,
"poll_interval": 500,
"request_capacity": 1000,
"request_timeouts": Object {
"update_by_query": 30000,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/task_manager/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const configSchema = schema.object(
max: 100,
min: 1,
}),
claim_strategy: schema.maybe(schema.string()),
claim_strategy: schema.string({ defaultValue: CLAIM_STRATEGY_MGET }),
request_timeouts: requestTimeoutsConfig,
auto_calculate_default_ech_capacity: schema.boolean({ defaultValue: false }),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe('switch task claiming strategies', () => {
jest.clearAllMocks();
});

it('should switch from default to mget and still claim tasks', async () => {
it('should switch from default to update_by_query and still claim tasks', async () => {
const setupResultDefault = await setupTestServers();
const esServer = setupResultDefault.esServer;
let kibanaServer = setupResultDefault.kibanaServer;
let taskClaimingOpts: TaskClaimingOpts = TaskClaimingMock.mock.calls[0][0];

expect(taskClaimingOpts.strategy).toBe('update_by_query');
expect(taskClaimingOpts.strategy).toBe('mget');

mockTaskTypeRunFn.mockImplementation(() => {
return { state: {} };
Expand Down Expand Up @@ -90,17 +90,17 @@ describe('switch task claiming strategies', () => {
await kibanaServer.stop();
}

const setupResultMget = await setupKibanaServer({
const setupResultUbq = await setupKibanaServer({
xpack: {
task_manager: {
claim_strategy: 'mget',
claim_strategy: 'update_by_query',
},
},
});
kibanaServer = setupResultMget.kibanaServer;
kibanaServer = setupResultUbq.kibanaServer;

taskClaimingOpts = TaskClaimingMock.mock.calls[1][0];
expect(taskClaimingOpts.strategy).toBe('mget');
expect(taskClaimingOpts.strategy).toBe('update_by_query');

// inject a task to run and ensure it is claimed and run
const id2 = uuidV4();
Expand Down Expand Up @@ -132,19 +132,19 @@ describe('switch task claiming strategies', () => {
}
});

it('should switch from mget to default and still claim tasks', async () => {
const setupResultMget = await setupTestServers({
it('should switch from update_by_query to default and still claim tasks', async () => {
const setupResultUbq = await setupTestServers({
xpack: {
task_manager: {
claim_strategy: 'mget',
claim_strategy: 'update_by_query',
},
},
});
const esServer = setupResultMget.esServer;
let kibanaServer = setupResultMget.kibanaServer;
const esServer = setupResultUbq.esServer;
let kibanaServer = setupResultUbq.kibanaServer;
let taskClaimingOpts: TaskClaimingOpts = TaskClaimingMock.mock.calls[0][0];

expect(taskClaimingOpts.strategy).toBe('mget');
expect(taskClaimingOpts.strategy).toBe('update_by_query');

mockTaskTypeRunFn.mockImplementation(() => {
return { state: {} };
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('switch task claiming strategies', () => {
kibanaServer = setupResultDefault.kibanaServer;

taskClaimingOpts = TaskClaimingMock.mock.calls[1][0];
expect(taskClaimingOpts.strategy).toBe('update_by_query');
expect(taskClaimingOpts.strategy).toBe('mget');

// inject a task to run and ensure it is claimed and run
const id2 = uuidV4();
Expand Down Expand Up @@ -212,13 +212,13 @@ describe('switch task claiming strategies', () => {
}
});

it('should switch from default to mget and claim tasks that were running during shutdown', async () => {
it('should switch from default to update_by_query and claim tasks that were running during shutdown', async () => {
const setupResultDefault = await setupTestServers();
const esServer = setupResultDefault.esServer;
let kibanaServer = setupResultDefault.kibanaServer;
let taskClaimingOpts: TaskClaimingOpts = TaskClaimingMock.mock.calls[0][0];

expect(taskClaimingOpts.strategy).toBe('update_by_query');
expect(taskClaimingOpts.strategy).toBe('mget');

mockTaskTypeRunFn.mockImplementation(async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down Expand Up @@ -252,17 +252,17 @@ describe('switch task claiming strategies', () => {
await kibanaServer.stop();
}

const setupResultMget = await setupKibanaServer({
const setupResultUbq = await setupKibanaServer({
xpack: {
task_manager: {
claim_strategy: 'mget',
claim_strategy: 'update_by_query',
},
},
});
kibanaServer = setupResultMget.kibanaServer;
kibanaServer = setupResultUbq.kibanaServer;

taskClaimingOpts = TaskClaimingMock.mock.calls[1][0];
expect(taskClaimingOpts.strategy).toBe('mget');
expect(taskClaimingOpts.strategy).toBe('update_by_query');

// task doc should still exist and be running
const task = await kibanaServer.coreStart.elasticsearch.client.asInternalUser.get<{
Expand Down Expand Up @@ -290,19 +290,19 @@ describe('switch task claiming strategies', () => {
}
});

it('should switch from mget to default and claim tasks that were running during shutdown', async () => {
const setupResultMget = await setupTestServers({
it('should switch from update_by_query to default and claim tasks that were running during shutdown', async () => {
const setupResultUbq = await setupTestServers({
xpack: {
task_manager: {
claim_strategy: 'mget',
claim_strategy: 'update_by_query',
},
},
});
const esServer = setupResultMget.esServer;
let kibanaServer = setupResultMget.kibanaServer;
const esServer = setupResultUbq.esServer;
let kibanaServer = setupResultUbq.kibanaServer;
let taskClaimingOpts: TaskClaimingOpts = TaskClaimingMock.mock.calls[0][0];

expect(taskClaimingOpts.strategy).toBe('mget');
expect(taskClaimingOpts.strategy).toBe('update_by_query');

mockTaskTypeRunFn.mockImplementation(async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('switch task claiming strategies', () => {
kibanaServer = setupResultDefault.kibanaServer;

taskClaimingOpts = TaskClaimingMock.mock.calls[1][0];
expect(taskClaimingOpts.strategy).toBe('update_by_query');
expect(taskClaimingOpts.strategy).toBe('mget');

// task doc should still exist and be running
const task = await kibanaServer.coreStart.elasticsearch.client.asInternalUser.get<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('task state validation', () => {

it('should fail the task run when setting allow_reading_invalid_state:false and reading an invalid state', async () => {
const logSpy = jest.spyOn(pollingLifecycleOpts.logger, 'warn');
const updateSpy = jest.spyOn(pollingLifecycleOpts.taskStore, 'bulkUpdate');
const updateSpy = jest.spyOn(pollingLifecycleOpts.taskStore, 'bulkPartialUpdate');

const id = uuidV4();
await injectTask(kibanaServer.coreStart.elasticsearch.client.asInternalUser, {
Expand All @@ -332,8 +332,7 @@ describe('task state validation', () => {
const found = calls.map((arr) => arr[0]).find((message) => message.match(expected) != null);
expect(found).toMatch(expected);
expect(updateSpy).toHaveBeenCalledWith(
expect.arrayContaining([expect.objectContaining({ id, taskType: 'fooType' })]),
{ validate: false }
expect.arrayContaining([expect.objectContaining({ id })])
);
});
});
Expand Down
Loading

0 comments on commit 8876584

Please sign in to comment.