-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Alerting V2] [ResponseOps] Recovery delay is configurable and persisted even when it has no effect on execution #288802
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
Merged
doakalexi
merged 18 commits into
elastic:main
from
doakalexi:alerting-v2/update-validation-for-recovery-delay
Sep 11, 2026
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cb02bad
Updating validation for recovery delay
doakalexi bce43cc
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi a5aa772
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi 00f662b
Addressing PR comments
doakalexi 9b736cc
Adding UI changes
doakalexi 06a7cd9
Merge branch 'alerting-v2/update-validation-for-recovery-delay' of gi…
doakalexi 57e01b6
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi d5f8df3
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi 1eff571
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi d34739c
Fixing check after merge with main
doakalexi a3eeb71
Merge branch 'alerting-v2/update-validation-for-recovery-delay' of gi…
doakalexi 7a88ad9
Merge branch 'main' of github.com:elastic/kibana into alerting-v2/upd…
doakalexi f26d7c5
Fixing test failures
doakalexi 350a627
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi e95a043
Removing comments
doakalexi c6ea536
Update x-pack/platform/plugins/shared/alerting_v2/server/lib/errors/e…
doakalexi 684bc24
Update x-pack/platform/plugins/shared/alerting_v2/test/scout_alerting…
doakalexi 11eae65
Merge branch 'main' into alerting-v2/update-validation-for-recovery-d…
doakalexi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { RUNBOOK_ARTIFACT_TYPE, RUNBOOK_CONTENT_LIMIT } from '@kbn/alerting-v2-c | |
| import { | ||
| createRuleDataBaseSchema, | ||
| createRuleDataSchema, | ||
| isRecoveryDelayAllowed, | ||
| updateRuleDataSchema, | ||
| IMMUTABLE_RULE_FIELDS, | ||
| getBreachEsqlQuery, | ||
|
|
@@ -55,6 +56,7 @@ describe('createRuleDataSchema', () => { | |
| metadata: { name: 'test rule', owner: 'team-a', tags: ['label-1', 'label-2'] }, | ||
| time_field: 'event.created', | ||
| schedule: { every: '5m', lookback: '10m' }, | ||
| recovery_strategy: 'no_breach', | ||
| grouping: { fields: ['host.name'] }, | ||
| state_transition: { | ||
| pending_operator: 'AND', | ||
|
|
@@ -72,6 +74,7 @@ describe('createRuleDataSchema', () => { | |
| metadata: { name: 'test rule', owner: 'team-a', tags: ['label-1', 'label-2'] }, | ||
| time_field: 'event.created', | ||
| schedule: { every: '5m', lookback: '10m' }, | ||
| recovery_strategy: 'no_breach', | ||
| grouping: { fields: ['host.name'] }, | ||
| state_transition: { | ||
| pending_operator: 'AND', | ||
|
|
@@ -702,6 +705,7 @@ describe('createRuleDataSchema', () => { | |
| it('accepts state_transition with only recovering fields', () => { | ||
| const result = createRuleDataSchema.parse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'no_breach', | ||
| state_transition: { | ||
| recovering_operator: 'OR', | ||
| recovering_count: 5, | ||
|
|
@@ -863,6 +867,83 @@ describe('createRuleDataSchema', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('recovery delay allowed', () => { | ||
| it('rejects a recovering_count when recovery_strategy is unset', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| state_transition: { pending_count: 0, recovering_count: 2 }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects a recovering_count when recovery_strategy is "none"', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'none', | ||
| state_transition: { recovering_count: 2 }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects a recovering_timeframe when recovery is disabled', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'none', | ||
| state_transition: { recovering_timeframe: '5m' }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects an inert recovery delay even when no_data_strategy is "recover"', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'none', | ||
| no_data_strategy: 'recover', | ||
| query: { | ||
| format: 'standalone', | ||
| breach: { query: 'FROM logs-* | LIMIT 1' }, | ||
| no_data: { query: 'FROM logs-* | STATS c = COUNT(*)' }, | ||
| }, | ||
| state_transition: { recovering_count: 2 }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(false); | ||
| }); | ||
|
|
||
| it('accepts recovering_count of 0 when recovery is disabled', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'none', | ||
| state_transition: { pending_count: 0, recovering_count: 0 }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts pending-only state_transition when recovery is disabled', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'none', | ||
| state_transition: { pending_count: 3 }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts a recovering delay when recovery_strategy is "no_breach"', () => { | ||
| const result = createRuleDataSchema.safeParse({ | ||
| ...validCreateData, | ||
| recovery_strategy: 'no_breach', | ||
| state_transition: { recovering_count: 2, recovering_timeframe: '5m' }, | ||
| }); | ||
|
|
||
| expect(result.success).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('artifacts envelope', () => { | ||
| const parseWithArtifact = (artifact: Record<string, unknown>) => | ||
| createRuleDataSchema.safeParse({ ...validCreateData, artifacts: [artifact] }); | ||
|
|
@@ -1677,3 +1758,52 @@ describe('tagsResponseSchema', () => { | |
| expect(() => tagsResponseSchema.parse({})).toThrow(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isRecoveryDelayAllowed', () => { | ||
| it('returns true when recovery is enabled, regardless of recovering delay', () => { | ||
| expect( | ||
| isRecoveryDelayAllowed({ | ||
| recovery_strategy: 'no_breach', | ||
| state_transition: { recovering_count: 3, recovering_timeframe: '5m' }, | ||
| }) | ||
| ).toBe(true); | ||
| expect( | ||
| isRecoveryDelayAllowed({ | ||
| recovery_strategy: 'query', | ||
| state_transition: { recovering_count: 3 }, | ||
| }) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true when recovery is disabled but no recovering delay is set', () => { | ||
| expect(isRecoveryDelayAllowed({ recovery_strategy: 'none' })).toBe(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in this commit, 00f662b |
||
| expect(isRecoveryDelayAllowed({ recovery_strategy: null })).toBe(true); | ||
| expect(isRecoveryDelayAllowed({})).toBe(true); | ||
| expect(isRecoveryDelayAllowed({ recovery_strategy: 'none', state_transition: {} })).toBe(true); | ||
| }); | ||
|
|
||
| it('treats recovering_count 0 as no delay even when recovery is disabled', () => { | ||
| expect( | ||
| isRecoveryDelayAllowed({ | ||
| recovery_strategy: 'none', | ||
| state_transition: { recovering_count: 0 }, | ||
| }) | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for a positive recovering delay when recovery is disabled', () => { | ||
| expect( | ||
| isRecoveryDelayAllowed({ | ||
| recovery_strategy: 'none', | ||
| state_transition: { recovering_count: 1 }, | ||
| }) | ||
| ).toBe(false); | ||
| expect( | ||
| isRecoveryDelayAllowed({ | ||
| recovery_strategy: null, | ||
| state_transition: { recovering_timeframe: '5m' }, | ||
| }) | ||
| ).toBe(false); | ||
| expect(isRecoveryDelayAllowed({ state_transition: { recovering_count: 2 } })).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iiiinteresting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change this if needed, it is kind of weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to minimize the disruption from adding the new validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might create some drift since I plan to hide the ui field entirely, we'll see. I want to avoid over-engineering the mapper if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay yeah that makes sense, I can remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in this commit, 00f662b