forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Synthetics] Fix monitor status rule for empty kql query results !! (e…
…lastic#208922) ## Summary Fixes elastic#208915 !! Fix monitor status rule for empty kql query results !! 1. Made sure if kql filter return no configs ids, rule break early to not cover all monitors ### Testing Create a synthetics rule with a kql filter which matches no monitors and make sure rule doesn't trigger for other down monitors in the system <img width="661" alt="image" src="https://github.com/user-attachments/assets/ed0b3a1f-e8d1-4e22-a77d-1237ce557ac5" /> ### Before Create a rule and you can observe that rule would get triggered for all monitors down in the system with matching condition criteria
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
...ability/plugins/synthetics/server/alert_rules/status_rule/queries/filter_monitors.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,80 @@ | ||
/* | ||
* 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 { getFilters } from './filter_monitors'; | ||
|
||
describe('getFilters', () => { | ||
it('returns an empty array when all parameters are empty', () => { | ||
const ruleParams = { monitorTypes: [], locations: [], tags: [], projects: [] }; | ||
expect(getFilters(ruleParams)).toEqual([]); | ||
}); | ||
|
||
it('creates a terms filter for monitorTypes', () => { | ||
const ruleParams = { monitorTypes: ['http', 'tcp'], locations: [], tags: [], projects: [] }; | ||
expect(getFilters(ruleParams)).toEqual([{ terms: { 'monitor.type': ['http', 'tcp'] } }]); | ||
}); | ||
|
||
it('creates a terms filter for locations', () => { | ||
const ruleParams = { | ||
monitorTypes: [], | ||
locations: ['us-east', 'us-west'], | ||
tags: [], | ||
projects: [], | ||
}; | ||
expect(getFilters(ruleParams)).toEqual([ | ||
{ terms: { 'observer.name': ['us-east', 'us-west'] } }, | ||
]); | ||
}); | ||
|
||
it('creates a bool must filter for tags', () => { | ||
const ruleParams = { monitorTypes: [], locations: [], tags: ['tag1', 'tag2'], projects: [] }; | ||
expect(getFilters(ruleParams)).toEqual([ | ||
{ | ||
terms: { tags: ['tag1', 'tag2'] }, | ||
}, | ||
]); | ||
}); | ||
|
||
it('creates a terms filter for projects', () => { | ||
const ruleParams = { monitorTypes: [], locations: [], tags: [], projects: ['proj1', 'proj2'] }; | ||
expect(getFilters(ruleParams)).toEqual([ | ||
{ terms: { 'monitor.project.id': ['proj1', 'proj2'] } }, | ||
]); | ||
}); | ||
|
||
it('handles all filters together', () => { | ||
const ruleParams = { | ||
monitorTypes: ['http'], | ||
locations: ['us-east'], | ||
tags: ['tag1', 'tag2'], | ||
projects: ['proj1'], | ||
}; | ||
expect(getFilters(ruleParams)).toEqual([ | ||
{ terms: { 'monitor.type': ['http'] } }, | ||
{ terms: { 'observer.name': ['us-east'] } }, | ||
{ | ||
terms: { tags: ['tag1', 'tag2'] }, | ||
}, | ||
{ terms: { 'monitor.project.id': ['proj1'] } }, | ||
]); | ||
}); | ||
|
||
it('ignores undefined fields', () => { | ||
const ruleParams = { | ||
monitorTypes: undefined, | ||
locations: undefined, | ||
tags: undefined, | ||
projects: undefined, | ||
}; | ||
expect(getFilters(ruleParams)).toEqual([]); | ||
}); | ||
|
||
it('ignores empty values in an otherwise valid object', () => { | ||
const ruleParams = { monitorTypes: [], locations: ['us-east'], tags: [], projects: [] }; | ||
expect(getFilters(ruleParams)).toEqual([{ terms: { 'observer.name': ['us-east'] } }]); | ||
}); | ||
}); |
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