2022-08-16 09:01:57 -05:00
|
|
|
import { BaseQueryFn, createApi } from '@reduxjs/toolkit/query/react';
|
|
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
|
|
|
|
|
import { BackendSrvRequest, getBackendSrv } from '@grafana/runtime';
|
|
|
|
|
2022-10-31 09:55:47 -05:00
|
|
|
import { logInfo } from '../Analytics';
|
|
|
|
|
2022-12-21 07:46:55 -06:00
|
|
|
export const backendSrvBaseQuery = (): BaseQueryFn<BackendSrvRequest> => async (requestOptions) => {
|
2022-08-16 09:01:57 -05:00
|
|
|
try {
|
2022-10-31 09:55:47 -05:00
|
|
|
const requestStartTs = performance.now();
|
|
|
|
|
2022-08-16 09:01:57 -05:00
|
|
|
const { data, ...meta } = await lastValueFrom(getBackendSrv().fetch(requestOptions));
|
|
|
|
|
2022-10-31 09:55:47 -05:00
|
|
|
logInfo('Request finished', {
|
|
|
|
loadTimeMs: (performance.now() - requestStartTs).toFixed(0),
|
|
|
|
url: requestOptions.url,
|
|
|
|
method: requestOptions.method ?? '',
|
|
|
|
responseStatus: meta.statusText,
|
|
|
|
});
|
|
|
|
|
2022-08-16 09:01:57 -05:00
|
|
|
return { data, meta };
|
|
|
|
} catch (error) {
|
|
|
|
return { error };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const alertingApi = createApi({
|
|
|
|
reducerPath: 'alertingApi',
|
|
|
|
baseQuery: backendSrvBaseQuery(),
|
2023-09-06 05:33:35 -05:00
|
|
|
tagTypes: ['AlertmanagerChoice', 'AlertmanagerConfiguration', 'OnCallIntegrations'],
|
2022-08-16 09:01:57 -05:00
|
|
|
endpoints: () => ({}),
|
|
|
|
});
|