Skip to content

Commit

Permalink
feat: added the start and end time in query payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkeswani101 committed Sep 11, 2024
1 parent 065d362 commit 2e6219a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ENTITY_VERSION_V4 } from 'constants/app';
import dayjs from 'dayjs';
import { useIsDarkMode } from 'hooks/useDarkMode';
import { useResizeObserver } from 'hooks/useDimensions';
import useUrlQuery from 'hooks/useUrlQuery';
import { GetMetricQueryRange } from 'lib/dashboard/getQueryResults';
import { getUPlotChartOptions } from 'lib/uPlotLib/getUplotChartOptions';
import { getUPlotChartData } from 'lib/uPlotLib/utils/getUplotChartData';
Expand All @@ -32,10 +31,6 @@ function NodeMetrics({
hostName: string;
logLineTimestamp: string;
}): JSX.Element {
const queryParams = useUrlQuery();
const globalSelectedInterval = queryParams.get('relativeTime')
? '6h'
: 'custom';
const { start, end, verticalLineTimestamp } = useMemo(() => {
const logTimestamp = dayjs(logLineTimestamp);
const now = dayjs();
Expand All @@ -54,24 +49,17 @@ function NodeMetrics({

const queryPayloads = useMemo(() => {
if (nodeName) {
return getNodeQueryPayload(clusterName, nodeName, globalSelectedInterval);
return getNodeQueryPayload(clusterName, nodeName, start, end);
}
return getHostQueryPayload(hostName, globalSelectedInterval);
}, [nodeName, hostName, globalSelectedInterval, clusterName]);
return getHostQueryPayload(hostName, start, end);
}, [nodeName, hostName, clusterName, start, end]);

const widgetInfo = nodeName ? nodeWidgetInfo : hostWidgetInfo;
const extendedEnd = !queryParams.get('relative');
const queries = useQueries(
queryPayloads.map((payload) => ({
queryKey: ['metrics', payload, ENTITY_VERSION_V4, 'NODE'],
queryFn: (): Promise<SuccessResponse<MetricRangePayloadProps>> =>
GetMetricQueryRange(
payload,
ENTITY_VERSION_V4,
undefined,
undefined,
extendedEnd,
),
GetMetricQueryRange(payload, ENTITY_VERSION_V4),
enabled: !!payload,
})),
);
Expand Down
19 changes: 3 additions & 16 deletions frontend/src/container/LogDetailedView/InfraMetrics/PodMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ENTITY_VERSION_V4 } from 'constants/app';
import dayjs from 'dayjs';
import { useIsDarkMode } from 'hooks/useDarkMode';
import { useResizeObserver } from 'hooks/useDimensions';
import useUrlQuery from 'hooks/useUrlQuery';
import { GetMetricQueryRange } from 'lib/dashboard/getQueryResults';
import { getUPlotChartOptions } from 'lib/uPlotLib/getUplotChartOptions';
import { getUPlotChartData } from 'lib/uPlotLib/utils/getUplotChartData';
Expand All @@ -25,10 +24,6 @@ function PodMetrics({
clusterName: string;
logLineTimestamp: string;
}): JSX.Element {
const queryParams = useUrlQuery();
const globalSelectedInterval = queryParams.get('relativeTime')
? '6h'
: 'custom';
const { start, end, verticalLineTimestamp } = useMemo(() => {
const logTimestamp = dayjs(logLineTimestamp);
const now = dayjs();
Expand All @@ -44,23 +39,15 @@ function PodMetrics({
verticalLineTimestamp: logTimestamp.unix(),
};
}, [logLineTimestamp]);
console.log(start, end, verticalLineTimestamp, logLineTimestamp);
const queryPayloads = useMemo(
() => getPodQueryPayload(clusterName, podName, globalSelectedInterval),
[clusterName, globalSelectedInterval, podName],
() => getPodQueryPayload(clusterName, podName, start, end),
[clusterName, end, podName, start],
);
const extendedEnd = !queryParams.get('relative');
const queries = useQueries(
queryPayloads.map((payload) => ({
queryKey: ['metrics', payload, ENTITY_VERSION_V4, 'POD'],
queryFn: (): Promise<SuccessResponse<MetricRangePayloadProps>> =>
GetMetricQueryRange(
payload,
ENTITY_VERSION_V4,
undefined,
undefined,
extendedEnd,
),
GetMetricQueryRange(payload, ENTITY_VERSION_V4),
enabled: !!payload,
})),
);
Expand Down
Loading

0 comments on commit 2e6219a

Please sign in to comment.