Skip to content

Commit

Permalink
Fix getAlertSummary returning 400 (Bad Request) (#199116)
Browse files Browse the repository at this point in the history
Fixes #190126
Fixes #184649

## Summary

This PR fixes alert summary API returning 400 when there is no featured
by only sending this request when featureId is available, otherwise
showing a default state as shown below:

#### Alert details page

|With featureId | Without featureId (intermediate state)|
|---|---|

|![image](https://github.com/user-attachments/assets/d4b4be5a-43be-4365-bd28-66c9dd53d979)|![image](https://github.com/user-attachments/assets/be437052-7c94-4d89-9238-b63264a812c8)|

#### Rule details page
|With featureId | Without featureId|
|---|---|

|![image](https://github.com/user-attachments/assets/28ff4ac5-ffc7-4c9e-8087-408f2ccff98e)|![image](https://github.com/user-attachments/assets/b82f530e-a27c-44e5-a241-c179bc8f1f46)|
  • Loading branch information
maryam-saeidi authored Nov 7, 2024
1 parent d25a2b4 commit ed2626f
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 ed2626f

Please sign in to comment.