Skip to content

Commit

Permalink
[8.16][Task Manager] Honor config-provided poll_interval (#205064)
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo authored Dec 23, 2024
1 parent 68c891a commit 022f029
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
16 changes: 16 additions & 0 deletions x-pack/plugins/task_manager/server/lib/set_claim_strategy.test.ts
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) {
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;
}

0 comments on commit 022f029

Please sign in to comment.