signoz/frontend/src/lib/dashboard/getQueryResults.ts
Sahil Khan 02f3dfefb9
feat: api monitoring domain details (#7308)
* feat: basic scaffolding for api monitoring & page level components added

* feat: added hardcoded attribute keys in querybuildersearcv2

* feat: added utils for formatting

* feat: api monitoring dashboard - 0

* feat: refactored the domain list

* feat: domain details drawer with all functionality added

* fix: minor eslint revert

* feat: adding ui styling to domain list table

* feat: adding pagination and minor styling to domain list table

* feat: added ui for domain details drawer all endpoints tab

* feat: added ui for domain details drawer all endpoints table with groupby

* feat: endpoint details tab ui revamped

* feat: endpoint details tab zero state styling

* fix: syntax error fixed

* feat: added conditional rendering of dep service and fixed graphs

* feat: added status code charts

* feat: added error states and loading states

* feat: added groupby persistence for endpoints

* feat: added domain navigation in the domain details drawer

* feat: added domain navigation in the domain details drawer - fix

* feat: isolated endpoint details zerostate

* feat: Implemented series aggregation with charts

* feat: ui for domain list table

* feat: react query keys added and basic pr comments resolved

* feat: fixed types

* feat: light mode fixed

* feat: empty states and light mode styling

* fix: bug with the endpoint filters

* feat: added port column and isolated endpoint in domain details

* feat: added port column and isolated endpoint in domain details - minor cleanup

* fix: minor type fix

* fix: pr comments incorporated - 0

* fix: pr comments incorporated - 1

---------

Co-authored-by: Sahil <sahil@Sahils-MacBook-Pro.local>
2025-03-24 18:01:39 +05:30

107 lines
3.2 KiB
TypeScript

/* eslint-disable */
// @ts-ignore
// @ts-nocheck
import { getMetricsQueryRange } from 'api/metrics/getQueryRange';
import { PANEL_TYPES } from 'constants/queryBuilder';
import { timePreferenceType } from 'container/NewWidget/RightContainer/timeItems';
import { Time } from 'container/TopNav/DateTimeSelection/config';
import {
CustomTimeType,
Time as TimeV2,
} from 'container/TopNav/DateTimeSelectionV2/config';
import { Pagination } from 'hooks/queryPagination';
import { convertNewDataToOld } from 'lib/newQueryBuilder/convertNewDataToOld';
import { isEmpty } from 'lodash-es';
import { SuccessResponse } from 'types/api';
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { prepareQueryRangePayload } from './prepareQueryRangePayload';
export async function GetMetricQueryRange(
props: GetQueryResultsProps,
version: string,
signal?: AbortSignal,
headers?: Record<string, string>,
isInfraMonitoring?: boolean,
): Promise<SuccessResponse<MetricRangePayloadProps>> {
const { legendMap, queryPayload } = prepareQueryRangePayload(props);
const response = await getMetricsQueryRange(
queryPayload,
version || 'v3',
signal,
headers,
);
if (response.statusCode >= 400) {
let error = `API responded with ${response.statusCode} - ${response.error} status: ${response.message}`;
if (response.body && !isEmpty(response.body)) {
error = `${error}, errors: ${response.body}`;
}
throw new Error(error);
}
if (props.formatForWeb) {
return response;
}
if (response.payload?.data?.result) {
const v2Range = convertNewDataToOld(response.payload);
response.payload = v2Range;
response.payload.data.result = response.payload.data.result.map(
(queryData) => {
const newQueryData = queryData;
newQueryData.legend = legendMap[queryData.queryName]; // Adds the legend if it is already defined by the user.
// If metric names is an empty object
if (isEmpty(queryData.metric)) {
// 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;
}
}
return newQueryData;
},
);
}
if (response.payload?.data?.newResult?.data?.resultType === 'anomaly') {
response.payload.data.newResult.data.result = response.payload.data.newResult.data.result.map(
(queryData) => {
if (legendMap[queryData.queryName]) {
queryData.legend = legendMap[queryData.queryName];
}
return queryData;
},
);
}
return response;
}
export interface GetQueryResultsProps {
query: Query;
graphType: PANEL_TYPES;
selectedTime: timePreferenceType;
globalSelectedInterval?: Time | TimeV2 | CustomTimeType;
variables?: Record<string, unknown>;
params?: Record<string, unknown>;
fillGaps?: boolean;
formatForWeb?: boolean;
tableParams?: {
pagination?: Pagination;
selectColumns?: any;
};
start?: number;
end?: number;
step?: number;
}