[8.x] [Alert details page] Fix exception in loading alert history stats (#208352) (#208544)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Alert details page] Fix exception in loading alert history stats
(#208352)](https://github.com/elastic/kibana/pull/208352)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"maryam.saeidi@elastic.co"},"sourceCommit":{"committedDate":"2025-01-28T14:11:34Z","message":"[Alert
details page] Fix exception in loading alert history stats
(#208352)\n\n## Summary\r\n\r\nThis PR fixes the following bug on the
alert details page, not sure what\r\nhas changed to cause this
issue:\r\n\r\n```\r\nError: Unable to retrieve alert details for alert
with id of \"undefined\" or with query
\"{\"bool\":{\"must\":[{\"term\":{\"kibana.alert.rule.uuid\":\"f90968a7-8723-4bf6-9472-1053a4e70ec1\"}},{\"term\":{\"kibana.alert.instance.id\":\"host-2\"}},{\"range\":{\"kibana.alert.time_range\":{\"from\":\"now-30d\",\"to\":\"now+1d\"}}}]}}\"
and operation find \r\nError: ResponseError:
x_content_parse_exception\r\n Caused by:\r\n x_content_parse_exception:
[1:333] [bool] failed to parse field [must]\r\n Root causes:\r\n
parsing_exception: [range] query does not support
[from]\r\n```\r\n\r\n|Before|After|\r\n|---|---|\r\n\r\n|![image](5490f768-06df-4b69-9d14-e6b9be7dc6fa)|","sha":"95a160ca94e45ffd063f1037bce6eb1a5c5dd372","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","v9.0.0","backport:prev-minor"],"title":"[Alert
details page] Fix exception in loading alert history
stats","number":208352,"url":"https://github.com/elastic/kibana/pull/208352","mergeCommit":{"message":"[Alert
details page] Fix exception in loading alert history stats
(#208352)\n\n## Summary\r\n\r\nThis PR fixes the following bug on the
alert details page, not sure what\r\nhas changed to cause this
issue:\r\n\r\n```\r\nError: Unable to retrieve alert details for alert
with id of \"undefined\" or with query
\"{\"bool\":{\"must\":[{\"term\":{\"kibana.alert.rule.uuid\":\"f90968a7-8723-4bf6-9472-1053a4e70ec1\"}},{\"term\":{\"kibana.alert.instance.id\":\"host-2\"}},{\"range\":{\"kibana.alert.time_range\":{\"from\":\"now-30d\",\"to\":\"now+1d\"}}}]}}\"
and operation find \r\nError: ResponseError:
x_content_parse_exception\r\n Caused by:\r\n x_content_parse_exception:
[1:333] [bool] failed to parse field [must]\r\n Root causes:\r\n
parsing_exception: [range] query does not support
[from]\r\n```\r\n\r\n|Before|After|\r\n|---|---|\r\n\r\n|![image](5490f768-06df-4b69-9d14-e6b9be7dc6fa)|","sha":"95a160ca94e45ffd063f1037bce6eb1a5c5dd372"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/208352","number":208352,"mergeCommit":{"message":"[Alert
details page] Fix exception in loading alert history stats
(#208352)\n\n## Summary\r\n\r\nThis PR fixes the following bug on the
alert details page, not sure what\r\nhas changed to cause this
issue:\r\n\r\n```\r\nError: Unable to retrieve alert details for alert
with id of \"undefined\" or with query
\"{\"bool\":{\"must\":[{\"term\":{\"kibana.alert.rule.uuid\":\"f90968a7-8723-4bf6-9472-1053a4e70ec1\"}},{\"term\":{\"kibana.alert.instance.id\":\"host-2\"}},{\"range\":{\"kibana.alert.time_range\":{\"from\":\"now-30d\",\"to\":\"now+1d\"}}}]}}\"
and operation find \r\nError: ResponseError:
x_content_parse_exception\r\n Caused by:\r\n x_content_parse_exception:
[1:333] [bool] failed to parse field [must]\r\n Root causes:\r\n
parsing_exception: [range] query does not support
[from]\r\n```\r\n\r\n|Before|After|\r\n|---|---|\r\n\r\n|![image](5490f768-06df-4b69-9d14-e6b9be7dc6fa)|","sha":"95a160ca94e45ffd063f1037bce6eb1a5c5dd372"}}]}]
BACKPORT-->

Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
This commit is contained in:
Kibana Machine 2025-01-29 02:58:30 +11:00 committed by GitHub
parent d5bcef977d
commit fdbc5baf63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -174,7 +174,7 @@ describe('useAlertsHistory', () => {
'{"size":0,"rule_type_ids":["apm"],"consumers":["foo"],"query":{"bool":{"must":[' +
'{"term":{"kibana.alert.rule.uuid":"cfd36e60-ef22-11ed-91eb-b7893acacfe2"}},' +
'{"term":{"kibana.alert.instance.id":"instance-1"}},' +
'{"range":{"kibana.alert.time_range":{"from":"2023-04-10T00:00:00.000Z","to":"2023-05-10T00:00:00.000Z"}}}]}},' +
'{"range":{"kibana.alert.time_range":{"gte":"2023-04-10T00:00:00.000Z","lte":"2023-05-10T00:00:00.000Z"}}}]}},' +
'"aggs":{"histogramTriggeredAlerts":{"date_histogram":{"field":"kibana.alert.start","fixed_interval":"1d",' +
'"extended_bounds":{"min":"2023-04-10T00:00:00.000Z","max":"2023-05-10T00:00:00.000Z"}}},' +
'"avgTimeToRecoverUS":{"filter":{"term":{"kibana.alert.status":"recovered"}},' +
@ -217,7 +217,7 @@ describe('useAlertsHistory', () => {
body:
'{"size":0,"rule_type_ids":["apm"],"query":{"bool":{"must":[' +
'{"term":{"kibana.alert.rule.uuid":"cfd36e60-ef22-11ed-91eb-b7893acacfe2"}},' +
'{"range":{"kibana.alert.time_range":{"from":"2023-04-10T00:00:00.000Z","to":"2023-05-10T00:00:00.000Z"}}}]}},' +
'{"range":{"kibana.alert.time_range":{"gte":"2023-04-10T00:00:00.000Z","lte":"2023-05-10T00:00:00.000Z"}}}]}},' +
'"aggs":{"histogramTriggeredAlerts":{"date_histogram":{"field":"kibana.alert.start","fixed_interval":"1d",' +
'"extended_bounds":{"min":"2023-04-10T00:00:00.000Z","max":"2023-05-10T00:00:00.000Z"}}},' +
'"avgTimeToRecoverUS":{"filter":{"term":{"kibana.alert.status":"recovered"}},' +

View file

@ -150,7 +150,10 @@ export async function fetchTriggeredAlertsHistory({
: []),
{
range: {
[ALERT_TIME_RANGE]: dateRange,
[ALERT_TIME_RANGE]: {
gte: dateRange.from,
lte: dateRange.to,
},
},
},
],