mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
Fix: don't show an error when receiver status is not available (#58638)
This commit is contained in:
parent
6625f6f0c8
commit
88a829e103
@ -1,19 +1,20 @@
|
||||
import { ContactPointsState, ReceiversStateDTO } from 'app/types';
|
||||
import { ContactPointsState } from 'app/types';
|
||||
|
||||
import { CONTACT_POINTS_STATE_INTERVAL_MS } from '../utils/constants';
|
||||
import { getDatasourceAPIUid } from '../utils/datasource';
|
||||
|
||||
import { alertingApi } from './alertingApi';
|
||||
import { contactPointsStateDtoToModel } from './grafana';
|
||||
import { fetchContactPointsState } from './grafana';
|
||||
|
||||
export const receiversApi = alertingApi.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
contactPointsState: build.query<ContactPointsState, string>({
|
||||
query: (amSourceName) => ({
|
||||
url: `/api/alertmanager/${getDatasourceAPIUid(amSourceName)}/config/api/v1/receivers`,
|
||||
}),
|
||||
transformResponse: (receivers: ReceiversStateDTO[]) => {
|
||||
return contactPointsStateDtoToModel(receivers);
|
||||
contactPointsState: build.query<ContactPointsState, { amSourceName: string }>({
|
||||
queryFn: async ({ amSourceName }) => {
|
||||
try {
|
||||
const contactPointsState = await fetchContactPointsState(amSourceName);
|
||||
return { data: contactPointsState };
|
||||
} catch (error) {
|
||||
return { error: error };
|
||||
}
|
||||
},
|
||||
}),
|
||||
}),
|
||||
@ -21,9 +22,12 @@ export const receiversApi = alertingApi.injectEndpoints({
|
||||
|
||||
export const useGetContactPointsState = (alertManagerSourceName: string) => {
|
||||
const contactPointsStateEmpty: ContactPointsState = { receivers: {}, errorCount: 0 };
|
||||
const { currentData: contactPointsState } = receiversApi.useContactPointsStateQuery(alertManagerSourceName ?? '', {
|
||||
skip: !alertManagerSourceName,
|
||||
pollingInterval: CONTACT_POINTS_STATE_INTERVAL_MS,
|
||||
});
|
||||
const { currentData: contactPointsState } = receiversApi.useContactPointsStateQuery(
|
||||
{ amSourceName: alertManagerSourceName ?? '' },
|
||||
{
|
||||
skip: !alertManagerSourceName,
|
||||
pollingInterval: CONTACT_POINTS_STATE_INTERVAL_MS,
|
||||
}
|
||||
);
|
||||
return contactPointsState ?? contactPointsStateEmpty;
|
||||
};
|
||||
|
@ -117,13 +117,13 @@ function ReceiverHealth({ errorsByReceiver, someWithNoAttempt }: ReceiverHealthP
|
||||
<Badge color={noErrorsColor} text={noErrorsText} tooltip="" />
|
||||
);
|
||||
}
|
||||
|
||||
const useContactPointsState = (alertManagerName: string) => {
|
||||
const contactPointsState = useGetContactPointsState(alertManagerName ?? '');
|
||||
const contactPointsState = useGetContactPointsState(alertManagerName);
|
||||
const receivers: ReceiversState = contactPointsState?.receivers ?? {};
|
||||
const errorStateAvailable = Object.keys(receivers).length > 0; // this logic can change depending on how we implement this in the BE
|
||||
const errorStateAvailable = Object.keys(receivers).length > 0;
|
||||
return { contactPointsState, errorStateAvailable };
|
||||
};
|
||||
|
||||
interface ReceiverItem {
|
||||
name: string;
|
||||
types: string[];
|
||||
|
Loading…
Reference in New Issue
Block a user