2022-06-28 17:32:02 +05:30
|
|
|
/* eslint-disable */
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
// @ts-nocheck
|
|
|
|
|
|
2022-06-24 15:00:21 +05:30
|
|
|
import { getMetricsQueryRange } from 'api/metrics/getQueryRange';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
2021-09-23 15:43:43 +05:30
|
|
|
import { timePreferenceType } from 'container/NewWidget/RightContainer/timeItems';
|
2022-06-24 15:00:21 +05:30
|
|
|
import { Time } from 'container/TopNav/DateTimeSelection/config';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { Pagination } from 'hooks/queryPagination';
|
2023-06-28 15:19:52 +05:30
|
|
|
import { convertNewDataToOld } from 'lib/newQueryBuilder/convertNewDataToOld';
|
2022-06-24 15:00:21 +05:30
|
|
|
import { isEmpty } from 'lodash-es';
|
2023-06-07 15:27:33 +03:00
|
|
|
import { SuccessResponse } from 'types/api';
|
2022-06-24 15:00:21 +05:30
|
|
|
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
|
2023-06-28 15:19:52 +05:30
|
|
|
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
2023-10-08 23:21:17 +05:30
|
|
|
|
2023-08-29 15:23:22 +03:00
|
|
|
import { prepareQueryRangePayload } from './prepareQueryRangePayload';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2023-08-29 15:23:22 +03:00
|
|
|
export async function GetMetricQueryRange(
|
|
|
|
|
props: GetQueryResultsProps,
|
|
|
|
|
): Promise<SuccessResponse<MetricRangePayloadProps>> {
|
|
|
|
|
const { legendMap, queryPayload } = prepareQueryRangePayload(props);
|
2022-06-28 17:32:02 +05:30
|
|
|
|
2023-08-29 15:23:22 +03:00
|
|
|
const response = await getMetricsQueryRange(queryPayload);
|
2023-06-19 15:57:58 +03:00
|
|
|
|
2022-06-24 15:00:21 +05:30
|
|
|
if (response.statusCode >= 400) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`API responded with ${response.statusCode} - ${response.error}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-05-02 17:08:03 +03:00
|
|
|
|
2022-06-24 15:00:21 +05:30
|
|
|
if (response.payload?.data?.result) {
|
2023-05-02 17:08:03 +03:00
|
|
|
const v2Range = convertNewDataToOld(response.payload);
|
|
|
|
|
|
|
|
|
|
response.payload = v2Range;
|
|
|
|
|
|
2022-06-24 15:00:21 +05:30
|
|
|
response.payload.data.result = response.payload.data.result.map(
|
|
|
|
|
(queryData) => {
|
|
|
|
|
const newQueryData = queryData;
|
2022-06-29 16:24:49 +05:30
|
|
|
newQueryData.legend = legendMap[queryData.queryName]; // Adds the legend if it is already defined by the user.
|
|
|
|
|
// If metric names is an empty object
|
2022-06-24 15:00:21 +05:30
|
|
|
if (isEmpty(queryData.metric)) {
|
2022-06-29 16:24:49 +05:30
|
|
|
// If metrics list is empty && the user haven't defined a legend then add the legend equal to the name of the query.
|
|
|
|
|
if (!newQueryData.legend) {
|
|
|
|
|
newQueryData.legend = queryData.queryName;
|
|
|
|
|
}
|
|
|
|
|
// If name of the query and the legend if inserted is same then add the same to the metrics object.
|
|
|
|
|
if (queryData.queryName === newQueryData.legend) {
|
|
|
|
|
newQueryData.metric[queryData.queryName] = queryData.queryName;
|
|
|
|
|
}
|
2022-06-24 15:00:21 +05:30
|
|
|
}
|
2023-05-02 17:08:03 +03:00
|
|
|
|
2022-06-29 16:24:49 +05:30
|
|
|
return newQueryData;
|
2022-06-24 15:00:21 +05:30
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
export interface GetQueryResultsProps {
|
2022-06-28 17:32:02 +05:30
|
|
|
query: Query;
|
2023-08-29 15:23:22 +03:00
|
|
|
graphType: PANEL_TYPES;
|
2023-06-07 15:27:33 +03:00
|
|
|
selectedTime: timePreferenceType;
|
|
|
|
|
globalSelectedInterval: Time;
|
|
|
|
|
variables?: Record<string, unknown>;
|
2023-06-19 15:57:58 +03:00
|
|
|
params?: Record<string, unknown>;
|
2023-07-04 08:24:34 +03:00
|
|
|
tableParams?: {
|
|
|
|
|
pagination?: Pagination;
|
|
|
|
|
selectColumns?: any;
|
|
|
|
|
};
|
2021-09-23 15:43:43 +05:30
|
|
|
}
|