Skip to content

Commit

Permalink
chore: added service name and time params for top level operations (#…
Browse files Browse the repository at this point in the history
…5552)

* chore: added service name and time params for top level operations

* fix: build issues

* chore: update the useTopLevelOpertions to send start and end time

* chore: added extra checks to not send the param when undefined

* chore: added extra checks to not send the param when undefined

---------

Co-authored-by: Srikanth Chekuri <[email protected]>
  • Loading branch information
vikrantgupta25 and srikanthccv authored Aug 1, 2024
1 parent 3783ffd commit 08a4150
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
17 changes: 15 additions & 2 deletions frontend/src/api/metrics/getTopLevelOperations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import axios from 'api';
import { isNil } from 'lodash-es';

const getTopLevelOperations = async (): Promise<ServiceDataProps> => {
const response = await axios.post(`/service/top_level_operations`);
interface GetTopLevelOperationsProps {
service?: string;
start?: number;
end?: number;
}

const getTopLevelOperations = async (
props: GetTopLevelOperationsProps,
): Promise<ServiceDataProps> => {
const response = await axios.post(`/service/top_level_operations`, {
start: !isNil(props.start) ? `${props.start}` : undefined,
end: !isNil(props.end) ? `${props.end}` : undefined,
service: props.service,
});
return response.data;
};

Expand Down
18 changes: 15 additions & 3 deletions frontend/src/container/MetricsApplication/Tabs/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import { OnClickPluginOpts } from 'lib/uPlotLib/plugins/onClickPlugin';
import { defaultTo } from 'lodash-es';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useQuery } from 'react-query';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { useLocation, useParams } from 'react-router-dom';
import { UpdateTimeInterval } from 'store/actions';
import { AppState } from 'store/reducers';
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { EQueryType } from 'types/common/dashboard';
import { GlobalReducer } from 'types/reducer/globalTime';
import { v4 as uuid } from 'uuid';

import { GraphTitle, SERVICE_CHART_ID } from '../constant';
Expand All @@ -52,6 +54,11 @@ import {
function Application(): JSX.Element {
const { servicename: encodedServiceName } = useParams<IServiceName>();
const servicename = decodeURIComponent(encodedServiceName);

const { maxTime, minTime } = useSelector<AppState, GlobalReducer>(
(state) => state.globalTime,
);

const [selectedTimeStamp, setSelectedTimeStamp] = useState<number>(0);
const { search, pathname } = useLocation();
const { queries } = useResourceAttribute();
Expand Down Expand Up @@ -105,8 +112,13 @@ function Application(): JSX.Element {
isLoading: topLevelOperationsIsLoading,
isError: topLevelOperationsIsError,
} = useQuery<ServiceDataProps>({
queryKey: [servicename],
queryFn: getTopLevelOperations,
queryKey: [servicename, minTime, maxTime],
queryFn: (): Promise<ServiceDataProps> =>
getTopLevelOperations({
service: servicename || '',
start: minTime,
end: maxTime,
}),
});

const selectedTraceTags: string = JSON.stringify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function ServicesUsingMetrics(): JSX.Element {
selectedTags,
globalSelectedInterval,
];
const { data, isLoading, isError } = useGetTopLevelOperations(queryKey);
const { data, isLoading, isError } = useGetTopLevelOperations(queryKey, {
start: minTime,
end: maxTime,
});

const [skipOnboarding, setSkipOnboarding] = useState(
localStorageGet(SKIP_ONBOARDING) === 'true',
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/hooks/useGetTopLevelOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import getTopLevelOperations, {
} from 'api/metrics/getTopLevelOperations';
import { QueryKey, useQuery, UseQueryResult } from 'react-query';

interface UseGetTopLevelOperationsParams {
start: number;
end: number;
}

type UseGetTopLevelOperations = (
queryKey: QueryKey,
params: UseGetTopLevelOperationsParams,
) => UseQueryResult<ServiceDataProps>;

const useGetTopLevelOperations: UseGetTopLevelOperations = (queryKey) =>
const useGetTopLevelOperations: UseGetTopLevelOperations = (queryKey, params) =>
useQuery<ServiceDataProps>({
queryKey,
queryFn: getTopLevelOperations,
queryFn: (): Promise<ServiceDataProps> =>
getTopLevelOperations({ start: params.start, end: params.end }),
});

export default useGetTopLevelOperations;

0 comments on commit 08a4150

Please sign in to comment.