poc(related) alerts custom score query#214017
Conversation
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
| export function RelatedAlertsView({ alert }: Props) { | ||
| const { services } = useKibana(); | ||
|
|
||
| const esQuery = useBuildRelatedAlertsQuery({ alert }); |
There was a problem hiding this comment.
💬 Add the user's specified weights & filters in the mix
tveasey
left a comment
There was a problem hiding this comment.
Overall I like the approach (and it is really crafty to do it with custom scoring function 👍. I proposed some potential small tweaks. Happy to discuss these offline.
| script: { | ||
| source: dedent(` | ||
| double jaccardSimilarity(Set a, Set b) { | ||
| if (a.size() == 0 || b.size() == 0) return 0.0; |
There was a problem hiding this comment.
If either set is empty or the intersect is empty we'll never get a match (the score is forced to zero). I'm not sure this is desirable.
For example, if
If both alerts have instances and there is no match I'm not sure, but I would we be inclined to think it should still be possible to match on other attributes. Perhaps though this should actively count against matching, i.e. multiplicative boost should be < 1.
One option which achieves all this is the following function:
Here,
| script_score: { | ||
| script: { | ||
| source: dedent(` | ||
| double jaccardSimilarity(Set a, Set b) { |
There was a problem hiding this comment.
A similar comment applies regarding no matching tags to no matching instances.
| exp: { | ||
| [ALERT_START]: { | ||
| origin: startDate.toISOString(), | ||
| scale: '10m', | ||
| offset: '10m', | ||
| decay: 0.5, | ||
| }, | ||
| }, | ||
| weight: 10, | ||
| }, | ||
| ...(endDate | ||
| ? [ | ||
| { | ||
| exp: { | ||
| [ALERT_END]: { | ||
| origin: endDate.toISOString(), | ||
| scale: '10m', | ||
| offset: '10m', | ||
| decay: 0.5, | ||
| }, | ||
| }, | ||
| weight: 10, | ||
| }, | ||
| ] | ||
| : []), |
There was a problem hiding this comment.
I feel like exponential decay is reasonable. I think this should be based on the interval distance though (so might need script score). Specifically, if alerts have intervals
This calculates the distance between the intervals if they don't overlap and is otherwise 0.
On efficiency grounds one should probably add some filter conditions as well, i.e. must not "end time of one alert" << "start time of other". This will allow Lucene to skip many candidate matches and only run the script scoring on the remainder.
## Summary Copying most of #214017 !! Fixes #214372 ### Implementation We are now using response ops alerts table with custom score querying based on tags/groups matches and Jaccard similarity on documents !! <img width="1728" alt="image" src="https://github.com/user-attachments/assets/b3a69280-c05d-4100-be6a-2c8dadcc051d" /> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co> Co-authored-by: Kevin Delemme <kevin.delemme@elastic.co>
…218664) # Backport This will backport the following commits from `main` to `8.x`: - [[Observability] Related alerts based on scoring !! (#215673)](#215673) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2025-04-14T15:35:40Z","message":"[Observability] Related alerts based on scoring !! (#215673)\n\n## Summary\n\nCopying most of #214017 !!\n\nFixes https://github.com/elastic/kibana/issues/214372\n\n### Implementation\nWe are now using response ops alerts table with custom score querying\nbased on tags/groups matches and Jaccard similarity on documents !!\n\n\n<img width=\"1728\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b3a69280-c05d-4100-be6a-2c8dadcc051d\"\n/>\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Dominique Clarke <dominique.clarke@elastic.co>\nCo-authored-by: Kevin Delemme <kevin.delemme@elastic.co>","sha":"760106eb8611a934d10157fb021979637d49dae4","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0"],"title":"[Observability] Related alerts based on scoring !!","number":215673,"url":"https://github.com/elastic/kibana/pull/215673","mergeCommit":{"message":"[Observability] Related alerts based on scoring !! (#215673)\n\n## Summary\n\nCopying most of #214017 !!\n\nFixes https://github.com/elastic/kibana/issues/214372\n\n### Implementation\nWe are now using response ops alerts table with custom score querying\nbased on tags/groups matches and Jaccard similarity on documents !!\n\n\n<img width=\"1728\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b3a69280-c05d-4100-be6a-2c8dadcc051d\"\n/>\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Dominique Clarke <dominique.clarke@elastic.co>\nCo-authored-by: Kevin Delemme <kevin.delemme@elastic.co>","sha":"760106eb8611a934d10157fb021979637d49dae4"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215673","number":215673,"mergeCommit":{"message":"[Observability] Related alerts based on scoring !! (#215673)\n\n## Summary\n\nCopying most of #214017 !!\n\nFixes https://github.com/elastic/kibana/issues/214372\n\n### Implementation\nWe are now using response ops alerts table with custom score querying\nbased on tags/groups matches and Jaccard similarity on documents !!\n\n\n<img width=\"1728\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b3a69280-c05d-4100-be6a-2c8dadcc051d\"\n/>\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Dominique Clarke <dominique.clarke@elastic.co>\nCo-authored-by: Kevin Delemme <kevin.delemme@elastic.co>","sha":"760106eb8611a934d10157fb021979637d49dae4"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This PoC reuses the alert query hook and a custom table to display the results.
The query is currently not configurable by the user, but ideally we would offer some weight configuration on the different heuristics we use, as well as some more "on/off" filter, like on the alert status, alert start date, etc...
Ideally we could add to existing/new cases, and go to the alert details (or open in flyout)