Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.16][Task Manager] Honor config-provided poll_interval #205064

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ describe('setClaimStrategy', () => {
expect(logger.info).not.toHaveBeenCalled();
});

test(`should honor config-provided poll_interval`, () => {
const config = { ...getConfigWithoutClaimStrategy(), poll_interval: 120000 };
const returnedConfig = setClaimStrategy({
config,
logger,
isCloud: false,
isElasticStaffOwned: false,
isServerless: false,
});

expect(returnedConfig.claim_strategy).toBe(CLAIM_STRATEGY_UPDATE_BY_QUERY);
expect(returnedConfig.poll_interval).toBe(120000);

expect(logger.info).not.toHaveBeenCalled();
});

test(`should set claim strategy to update_by_query if cloud and not serverless with undefined deploymentId`, () => {
const config = getConfigWithoutClaimStrategy();
const returnedConfig = setClaimStrategy({
Expand Down
23 changes: 21 additions & 2 deletions x-pack/plugins/task_manager/server/lib/set_claim_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,32 @@ export function setClaimStrategy(opts: SetClaimStrategyOpts): TaskManagerConfig
return {
...opts.config,
claim_strategy: CLAIM_STRATEGY_MGET,
poll_interval: MGET_DEFAULT_POLL_INTERVAL,
poll_interval: maybeSetDefaultInterval(opts.config, MGET_DEFAULT_POLL_INTERVAL),
};
}

return {
...opts.config,
claim_strategy: CLAIM_STRATEGY_UPDATE_BY_QUERY,
poll_interval: DEFAULT_POLL_INTERVAL,
poll_interval: maybeSetDefaultInterval(opts.config, DEFAULT_POLL_INTERVAL),
};
}

/**
* If the poll interval is not overridden by the user, return the specified default.
*
* @param config Current config
* @param defaultPollInterval Default to set
*/
function maybeSetDefaultInterval(config: TaskManagerConfig, defaultPollInterval: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I was looking at how this function differs to letting the poll_interval overwrite completely (opts.config.poll_interval ?? DEFAULT_POLL_INTERVAL).

From looking at the function, it seems if ever the user sets xpack.task_manager.poll_interval: 3000 in their yml and their deployment is auto enrolled to the mget task claiming strategy, we're going to discard the 3000 and set 500 as the value. I guess this is the current behaviour on 8.16, was your intent to preserve this as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this method returns the default only if the user didn't provide it (which, in case they didn't set "mget" in their kibana.yml is DEFAULT_POLL_INTERVAL).

I don't think that the a/b decision logic in this file affects it (at least, that was not my intention).

In case they set "mget" in their kibana.yml, this method is not called because there's an early return at the top of this file.

if (config.claim_strategy) {
return config.poll_interval;
}

// Our default when there's no claim_strategy is DEFAULT_POLL_INTERVAL
if (config.poll_interval === DEFAULT_POLL_INTERVAL) {
return defaultPollInterval;
}

return config.poll_interval;
}
Loading