-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ResponseOps][Alerts] Fix muted alerts query using wrong filter #204182
Merged
umbopepato
merged 12 commits into
elastic:main
from
umbopepato:fix-muted-alerts-query-filter
Dec 18, 2024
+150
−2
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d8dce9e
Fix muted alerts query using wrong filter
umbopepato 98827f8
Add muted alerts api integration test
umbopepato f467f7c
Merge branch 'main' of github.com:elastic/kibana into fix-muted-alert…
umbopepato bb7509b
Fix test order
umbopepato 9188138
Merge branch 'main' of github.com:elastic/kibana into fix-muted-alert…
umbopepato e25dd19
Fix type errors
umbopepato 7978a31
Merge branch 'main' of github.com:elastic/kibana into fix-muted-alert…
umbopepato 1733b16
Fix type error
umbopepato c695fc2
Merge branch 'main' of github.com:elastic/kibana into fix-muted-alert…
umbopepato d65d908
Add test case with multiple rule ids
umbopepato e5a4e37
Merge branch 'main' of github.com:elastic/kibana into fix-muted-alert…
umbopepato 2c5cd4c
Merge branch 'main' into fix-muted-alerts-query-filter
umbopepato 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 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
122 changes: 122 additions & 0 deletions
122
x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/muted_alerts.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,122 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
import { ES_TEST_INDEX_NAME } from '@kbn/alerting-api-integration-helpers'; | ||
import { ALERT_INSTANCE_ID, ALERT_RULE_UUID, ALERT_STATUS } from '@kbn/rule-data-utils'; | ||
import { nodeBuilder } from '@kbn/es-query'; | ||
import { Spaces } from '../../../scenarios'; | ||
import { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib'; | ||
|
||
const alertAsDataIndex = '.internal.alerts-observability.test.alerts.alerts-default-000001'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function createDisableRuleTests({ getService }: FtrProviderContext) { | ||
const es = getService('es'); | ||
const retry = getService('retry'); | ||
const supertest = getService('supertest'); | ||
|
||
describe('mutedAlerts', () => { | ||
const objectRemover = new ObjectRemover(supertest); | ||
|
||
const createRule = async () => { | ||
const { body: createdRule } = await supertest | ||
.post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) | ||
.set('kbn-xsrf', 'foo') | ||
.send( | ||
getTestRuleData({ | ||
rule_type_id: 'test.always-firing-alert-as-data', | ||
schedule: { interval: '24h' }, | ||
throttle: undefined, | ||
notify_when: undefined, | ||
params: { | ||
index: ES_TEST_INDEX_NAME, | ||
reference: 'test', | ||
}, | ||
}) | ||
) | ||
.expect(200); | ||
|
||
objectRemover.add(Spaces.space1.id, createdRule.id, 'rule', 'alerting'); | ||
return createdRule.id; | ||
}; | ||
|
||
const getAlerts = async () => { | ||
const { | ||
hits: { hits: alerts }, | ||
} = await es.search({ | ||
index: alertAsDataIndex, | ||
body: { query: { match_all: {} } }, | ||
}); | ||
|
||
return alerts; | ||
}; | ||
|
||
afterEach(async () => { | ||
await es.deleteByQuery({ | ||
index: alertAsDataIndex, | ||
query: { | ||
match_all: {}, | ||
}, | ||
conflicts: 'proceed', | ||
ignore_unavailable: true, | ||
}); | ||
await objectRemover.removeAll(); | ||
}); | ||
|
||
it('should reflect muted alert instance ids in rule', async () => { | ||
const createdRule1 = await createRule(); | ||
const createdRule2 = await createRule(); | ||
|
||
let alerts: any[] = []; | ||
|
||
await retry.try(async () => { | ||
alerts = await getAlerts(); | ||
|
||
expect(alerts.length).greaterThan(2); | ||
alerts.forEach((activeAlert: any) => { | ||
expect(activeAlert._source[ALERT_STATUS]).eql('active'); | ||
}); | ||
}); | ||
|
||
const alertFromRule1 = alerts.find( | ||
(alert: any) => | ||
alert._source[ALERT_STATUS] === 'active' && | ||
alert._source[ALERT_RULE_UUID] === createdRule1 | ||
); | ||
|
||
await supertest | ||
.post( | ||
`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule/${encodeURIComponent( | ||
createdRule1 | ||
)}/alert/${encodeURIComponent(alertFromRule1._source['kibana.alert.instance.id'])}/_mute` | ||
) | ||
.set('kbn-xsrf', 'foo') | ||
.expect(204); | ||
|
||
const ruleUuids = [createdRule1, createdRule2]; | ||
|
||
const filterNode = nodeBuilder.or( | ||
ruleUuids.map((id) => nodeBuilder.is('alert.id', `alert:${id}`)) | ||
); | ||
const { body: rules } = await supertest | ||
.post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rules/_find`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
filter: JSON.stringify(filterNode), | ||
fields: ['id', 'mutedInstanceIds'], | ||
page: 1, | ||
per_page: ruleUuids.length, | ||
}); | ||
|
||
expect(rules.data.length).to.be(2); | ||
const mutedRule = rules.data.find((rule: { id: string }) => rule.id === createdRule1); | ||
expect(mutedRule.muted_alert_ids).to.contain(alertFromRule1._source[ALERT_INSTANCE_ID]); | ||
}); | ||
}); | ||
} |
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.
The snapshot in the tests will fail. Could you also add a test where there are multiple
ruleIds
? The current one only testsruleIds: ['foo']
.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.
Done! 🙂