Skip to content

Commit

Permalink
[8.x] Fix getAlertSummary returning 400 (Bad Request) (#199116) (#199281
Browse files Browse the repository at this point in the history
)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Fix getAlertSummary returning 400 (Bad Request)
(#199116)](#199116)

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

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

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-07T10:03:56Z","message":"Fix
getAlertSummary returning 400 (Bad Request) (#199116)\n\nFixes
#190126\r\nFixes #184649\r\n\r\n## Summary\r\n\r\nThis PR fixes alert
summary API returning 400 when there is no featured\r\nby only sending
this request when featureId is available, otherwise\r\nshowing a default
state as shown below:\r\n\r\n#### Alert details page\r\n\r\n|With
featureId | Without featureId (intermediate
state)|\r\n|---|---|\r\n\r\n|![image](https://github.com/user-attachments/assets/d4b4be5a-43be-4365-bd28-66c9dd53d979)|![image](https://github.com/user-attachments/assets/be437052-7c94-4d89-9238-b63264a812c8)|\r\n\r\n####
Rule details page\r\n|With featureId | Without
featureId|\r\n|---|---|\r\n\r\n|![image](https://github.com/user-attachments/assets/28ff4ac5-ffc7-4c9e-8087-408f2ccff98e)|![image](https://github.com/user-attachments/assets/b82f530e-a27c-44e5-a241-c179bc8f1f46)|","sha":"ed2626f980455b9215f8d1097e5b61838aa3e44c","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","Team:obs-ux-management"],"title":"Fix
getAlertSummary returning 400 (Bad
Request)","number":199116,"url":"https://github.com/elastic/kibana/pull/199116","mergeCommit":{"message":"Fix
getAlertSummary returning 400 (Bad Request) (#199116)\n\nFixes
#190126\r\nFixes #184649\r\n\r\n## Summary\r\n\r\nThis PR fixes alert
summary API returning 400 when there is no featured\r\nby only sending
this request when featureId is available, otherwise\r\nshowing a default
state as shown below:\r\n\r\n#### Alert details page\r\n\r\n|With
featureId | Without featureId (intermediate
state)|\r\n|---|---|\r\n\r\n|![image](https://github.com/user-attachments/assets/d4b4be5a-43be-4365-bd28-66c9dd53d979)|![image](https://github.com/user-attachments/assets/be437052-7c94-4d89-9238-b63264a812c8)|\r\n\r\n####
Rule details page\r\n|With featureId | Without
featureId|\r\n|---|---|\r\n\r\n|![image](https://github.com/user-attachments/assets/28ff4ac5-ffc7-4c9e-8087-408f2ccff98e)|![image](https://github.com/user-attachments/assets/b82f530e-a27c-44e5-a241-c179bc8f1f46)|","sha":"ed2626f980455b9215f8d1097e5b61838aa3e44c"}},"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/199116","number":199116,"mergeCommit":{"message":"Fix
getAlertSummary returning 400 (Bad Request) (#199116)\n\nFixes
#190126\r\nFixes #184649\r\n\r\n## Summary\r\n\r\nThis PR fixes alert
summary API returning 400 when there is no featured\r\nby only sending
this request when featureId is available, otherwise\r\nshowing a default
state as shown below:\r\n\r\n#### Alert details page\r\n\r\n|With
featureId | Without featureId (intermediate
state)|\r\n|---|---|\r\n\r\n|![image](https://github.com/user-attachments/assets/d4b4be5a-43be-4365-bd28-66c9dd53d979)|![image](https://github.com/user-attachments/assets/be437052-7c94-4d89-9238-b63264a812c8)|\r\n\r\n####
Rule details page\r\n|With featureId | Without
featureId|\r\n|---|---|\r\n\r\n|![image](https://github.com/user-attachments/assets/28ff4ac5-ffc7-4c9e-8087-408f2ccff98e)|![image](https://github.com/user-attachments/assets/b82f530e-a27c-44e5-a241-c179bc8f1f46)|","sha":"ed2626f980455b9215f8d1097e5b61838aa3e44c"}}]}]
BACKPORT-->

Co-authored-by: Maryam Saeidi <[email protected]>
  • Loading branch information
kibanamachine and maryam-saeidi authored Nov 7, 2024
1 parent 3265ee8 commit ce0e63b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function useAlertsHistory({
http,
instanceId,
}: Props): UseAlertsHistory {
const enabled = !!featureIds.length;
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({
queryKey: ['useAlertsHistory'],
queryFn: async ({ signal }) => {
Expand All @@ -71,10 +72,11 @@ export function useAlertsHistory({
});
},
refetchOnWindowFocus: false,
enabled,
});
return {
data: isInitialLoading ? EMPTY_ALERTS_HISTORY : data ?? EMPTY_ALERTS_HISTORY,
isLoading: isInitialLoading || isLoading || isRefetching,
isLoading: enabled && (isInitialLoading || isLoading || isRefetching),
isSuccess,
isError,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ async function fetchAlertSummary({
timeRange: AlertSummaryTimeRange;
filter?: estypes.QueryDslQueryContainer;
}): Promise<AlertSummary> {
const res = await http.post<AsApiContract<any>>(`${BASE_RAC_ALERTS_API_PATH}/_alert_summary`, {
signal,
body: JSON.stringify({
fixed_interval: fixedInterval,
gte: utcFrom,
lte: utcTo,
featureIds,
filter: [filter],
}),
});
const res = featureIds.length
? await http.post<AsApiContract<any>>(`${BASE_RAC_ALERTS_API_PATH}/_alert_summary`, {
signal,
body: JSON.stringify({
fixed_interval: fixedInterval,
gte: utcFrom,
lte: utcTo,
featureIds,
filter: [filter],
}),
})
: {};

const activeAlertCount = res?.activeAlertCount ?? 0;
const activeAlerts = res?.activeAlerts ?? [];
Expand Down

0 comments on commit ce0e63b

Please sign in to comment.