-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting] Remove defaultRuleTaskTimeout and set ruleType specific ti…
…meout from kibana.yml (#128294) Read ruleTaskTimeout from kibana.yml
- Loading branch information
1 parent
ca81ce8
commit c9aad65
Showing
10 changed files
with
146 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/alerting/server/lib/get_rule_task_timeout.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getRuleTaskTimeout } from './get_rule_task_timeout'; | ||
import { RulesConfig } from '../config'; | ||
|
||
const ruleTypeId = 'test-rule-type-id'; | ||
const config = { | ||
minimumScheduleInterval: { | ||
value: '2m', | ||
enforce: false, | ||
}, | ||
execution: { | ||
timeout: '1m', | ||
actions: { max: 1000 }, | ||
}, | ||
} as RulesConfig; | ||
|
||
const configWithRuleType = { | ||
...config, | ||
execution: { | ||
...config.execution, | ||
ruleTypeOverrides: [ | ||
{ | ||
id: ruleTypeId, | ||
timeout: '10m', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const configWithoutTimeout = { | ||
...config, | ||
execution: { | ||
actions: { max: 1000 }, | ||
}, | ||
}; | ||
|
||
describe('get rule task timeout', () => { | ||
test('returns the rule type specific timeout', () => { | ||
expect(getRuleTaskTimeout({ config: configWithRuleType, ruleTypeId })).toBe('10m'); | ||
}); | ||
|
||
test('returns the timeout that applies all the rule types', () => { | ||
expect(getRuleTaskTimeout({ config, ruleTypeId })).toBe('1m'); | ||
}); | ||
|
||
test('returns the timeout passed by the plugin', () => { | ||
expect( | ||
getRuleTaskTimeout({ config: configWithoutTimeout, ruleTaskTimeout: '20m', ruleTypeId }) | ||
).toBe('20m'); | ||
}); | ||
|
||
test('returns the default timeout', () => { | ||
expect(getRuleTaskTimeout({ config: configWithoutTimeout, ruleTypeId })).toBe('5m'); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/alerting/server/lib/get_rule_task_timeout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { RulesConfig } from '../config'; | ||
|
||
const DEFAULT_EXECUTION_TIMEOUT = '5m'; | ||
|
||
export const getRuleTaskTimeout = ({ | ||
config, | ||
ruleTaskTimeout, | ||
ruleTypeId, | ||
}: { | ||
config: RulesConfig; | ||
ruleTaskTimeout?: string; | ||
ruleTypeId: string; | ||
}): string => { | ||
const ruleTypeConfig = config.execution.ruleTypeOverrides?.find( | ||
(ruleType) => ruleTypeId === ruleType.id | ||
); | ||
|
||
// First, rule type specific timeout config (ruleTypeOverrides) is applied if it's set in kibana.yml | ||
// if not, then timeout for all the rule types is applied if it's set in kibana.yml | ||
// if not, ruleTaskTimeout is applied that is passed from the rule type registering plugin | ||
// if none of above is set, DEFAULT_EXECUTION_TIMEOUT is applied | ||
return ( | ||
ruleTypeConfig?.timeout || | ||
config.execution.timeout || | ||
ruleTaskTimeout || | ||
DEFAULT_EXECUTION_TIMEOUT | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters