Skip to content

Commit

Permalink
Use initialPromisePurity for prometheus range queries in DW
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Turley <[email protected]>
  • Loading branch information
mturley committed Mar 14, 2024
1 parent 29bb4be commit ef81fd9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions frontend/src/api/prometheus/distributedWorkloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const useDWWorkloadTrendMetrics = (
defaultResponsePredicate,
namespace || '',
'/api/prometheus/queryRange',
{ initialPromisePurity: true },
),
jobsInadmissibleTrend: useQueryRangeResourceData(
!!queries,
Expand All @@ -169,6 +170,7 @@ export const useDWWorkloadTrendMetrics = (
defaultResponsePredicate,
namespace || '',
'/api/prometheus/queryRange',
{ initialPromisePurity: true },
),
jobsPendingTrend: useQueryRangeResourceData(
!!queries,
Expand All @@ -178,6 +180,7 @@ export const useDWWorkloadTrendMetrics = (
defaultResponsePredicate,
namespace || '',
'/api/prometheus/queryRange',
{ initialPromisePurity: true },
),
};

Expand Down
4 changes: 3 additions & 1 deletion frontend/src/api/prometheus/usePrometheusQueryRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import axios from 'axios';

import useFetchState, {
FetchOptions,
FetchState,
FetchStateCallbackPromise,
NotReadyError,
Expand All @@ -26,6 +27,7 @@ const usePrometheusQueryRange = <T = PrometheusQueryRangeResultValue>(
step: number,
responsePredicate: ResponsePredicate<T>,
namespace: string,
fetchOptions?: Partial<FetchOptions>,
): [...FetchState<T[]>, boolean] => {
const pendingRef = React.useRef(active);
const fetchData = React.useCallback<FetchStateCallbackPromise<T[]>>(() => {
Expand Down Expand Up @@ -59,7 +61,7 @@ const usePrometheusQueryRange = <T = PrometheusQueryRangeResultValue>(
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [active, fetchData]);

return [...useFetchState<T[]>(fetchData, []), pendingRef.current];
return [...useFetchState<T[]>(fetchData, [], fetchOptions), pendingRef.current];
};

export const defaultResponsePredicate: ResponsePredicate = (data) => data.result?.[0]?.values || [];
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/api/prometheus/useQueryRangeResourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { TimeframeStep, TimeframeTimeRange } from '~/pages/modelServing/screens/const';
import { PrometheusQueryRangeResultValue } from '~/types';
import useRestructureContextResourceData from '~/utilities/useRestructureContextResourceData';
import { FetchOptions } from '~/utilities/useFetchState';
import { TimeframeTitle } from '~/pages/modelServing/screens/types';
import usePrometheusQueryRange, { ResponsePredicate } from './usePrometheusQueryRange';

Expand All @@ -14,6 +15,7 @@ const useQueryRangeResourceData = <T = PrometheusQueryRangeResultValue>(
responsePredicate: ResponsePredicate<T>,
namespace: string,
apiPath = '/api/prometheus/serving',
fetchOptions?: Partial<FetchOptions>,
): ReturnType<typeof useRestructureContextResourceData<T>> =>
useRestructureContextResourceData<T>(
usePrometheusQueryRange<T>(
Expand All @@ -25,6 +27,7 @@ const useQueryRangeResourceData = <T = PrometheusQueryRangeResultValue>(
TimeframeStep[timeframe],
responsePredicate,
namespace,
fetchOptions,
),
);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/concepts/distributedWorkloads/useWorkloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const useWorkloads = (namespace?: string, refreshRate = 0): FetchState<WorkloadK
return listWorkloads(namespace);
}, [dwEnabled, namespace]),
[],
{ refreshRate },
{ refreshRate, initialPromisePurity: true },
);
};

Expand Down

0 comments on commit ef81fd9

Please sign in to comment.