Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types on f/mserving-metrics branch #1670

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions frontend/src/api/prometheus/serving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import useQueryRangeResourceData from './useQueryRangeResourceData';

export const useModelServingMetrics = (
type: PerformanceMetricType,
queries: Record<ServerMetricType, string> | Record<ModelMetricType, string>,
queries: { [key in ModelMetricType]: string } | { [key in ServerMetricType]: string },
timeframe: TimeframeTitle,
lastUpdateTime: number,
setLastUpdateTime: (time: number) => void,
Expand All @@ -49,7 +49,7 @@ export const useModelServingMetrics = (

const serverRequestCount = useQueryRangeResourceData(
performanceMetricsEnabled && type === PerformanceMetricType.SERVER,
queries[ServerMetricType.REQUEST_COUNT],
(queries as { [key in ServerMetricType]: string })[ServerMetricType.REQUEST_COUNT],
end,
timeframe,
QueryTimeframeStep[ServerMetricType.REQUEST_COUNT],
Expand All @@ -59,7 +59,7 @@ export const useModelServingMetrics = (
const serverAverageResponseTime =
useQueryRangeResourceData<PrometheusQueryRangeResponseDataResult>(
performanceMetricsEnabled && type === PerformanceMetricType.SERVER,
queries[ServerMetricType.AVG_RESPONSE_TIME],
(queries as { [key in ServerMetricType]: string })[ServerMetricType.AVG_RESPONSE_TIME],
end,
timeframe,
QueryTimeframeStep[ServerMetricType.AVG_RESPONSE_TIME],
Expand All @@ -68,7 +68,7 @@ export const useModelServingMetrics = (

const serverCPUUtilization = useQueryRangeResourceData(
performanceMetricsEnabled && type === PerformanceMetricType.SERVER,
queries[ServerMetricType.CPU_UTILIZATION],
(queries as { [key in ServerMetricType]: string })[ServerMetricType.CPU_UTILIZATION],
end,
timeframe,
QueryTimeframeStep[ServerMetricType.CPU_UTILIZATION],
Expand All @@ -77,7 +77,7 @@ export const useModelServingMetrics = (

const serverMemoryUtilization = useQueryRangeResourceData(
performanceMetricsEnabled && type === PerformanceMetricType.SERVER,
queries[ServerMetricType.MEMORY_UTILIZATION],
(queries as { [key in ServerMetricType]: string })[ServerMetricType.MEMORY_UTILIZATION],
end,
timeframe,
QueryTimeframeStep[ServerMetricType.MEMORY_UTILIZATION],
Expand All @@ -86,7 +86,7 @@ export const useModelServingMetrics = (

const modelRequestSuccessCount = useQueryRangeResourceData(
performanceMetricsEnabled && type === PerformanceMetricType.MODEL,
queries[ModelMetricType.REQUEST_COUNT_SUCCESS],
(queries as { [key in ModelMetricType]: string })[ModelMetricType.REQUEST_COUNT_SUCCESS],
end,
timeframe,
QueryTimeframeStep[ModelMetricType.REQUEST_COUNT_SUCCESS],
Expand All @@ -95,7 +95,7 @@ export const useModelServingMetrics = (

const modelRequestFailedCount = useQueryRangeResourceData(
performanceMetricsEnabled && type === PerformanceMetricType.MODEL,
queries[ModelMetricType.REQUEST_COUNT_FAILED],
(queries as { [key in ModelMetricType]: string })[ModelMetricType.REQUEST_COUNT_FAILED],
end,
timeframe,
QueryTimeframeStep[ModelMetricType.REQUEST_COUNT_FAILED],
Expand All @@ -104,7 +104,7 @@ export const useModelServingMetrics = (

const modelTrustyAISPD = useQueryRangeResourceData(
biasMetricsEnabled && type === PerformanceMetricType.MODEL,
queries[ModelMetricType.TRUSTY_AI_SPD],
(queries as { [key in ModelMetricType]: string })[ModelMetricType.TRUSTY_AI_SPD],
end,
timeframe,
QueryTimeframeStep[ModelMetricType.TRUSTY_AI_SPD],
Expand All @@ -114,7 +114,7 @@ export const useModelServingMetrics = (

const modelTrustyAIDIR = useQueryRangeResourceData(
biasMetricsEnabled && type === PerformanceMetricType.MODEL,
queries[ModelMetricType.TRUSTY_AI_DIR],
(queries as { [key in ModelMetricType]: string })[ModelMetricType.TRUSTY_AI_DIR],
end,
timeframe,
QueryTimeframeStep[ModelMetricType.TRUSTY_AI_DIR],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const useTrustyAIAPIRoute = (hasCR: boolean, namespace: string): FetchState<Stat

const hasData = !!data;
React.useEffect(() => {
let interval;
let interval: ReturnType<typeof setTimeout>;
if (!hasData) {
interval = setInterval(refresh, FAST_POLL_INTERVAL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const useTrustyAIAPIState = (
hostPath: string | null,
): [apiState: TrustyAPIState, refreshAPIState: () => void] => {
const createAPI = React.useCallback(
(path) => ({
(path: string) => ({
createDirRequest: createDirRequest(path),
createSpdRequest: createSpdRequest(path),
deleteDirRequest: deleteDirRequest(path),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const usePipelineAPIState = (
hostPath: string | null,
): [apiState: PipelineAPIState, refreshAPIState: () => void] => {
const createAPI = React.useCallback(
(path) => ({
(path: string) => ({
createExperiment: createExperiment(path),
createPipelineRun: createPipelineRun(path),
createPipelineRunJob: createPipelineRunJob(path),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ const BiasConfigurationTable: React.FC<BiasConfigurationTableProps> = ({
// TODO: decide what we want to search
// Or should we reuse the complex filter search
const searchTypes = React.useMemo(
() =>
Object.keys(SearchType).filter(
(key) =>
SearchType[key] === SearchType.NAME ||
SearchType[key] === SearchType.METRIC ||
SearchType[key] === SearchType.PROTECTED_ATTRIBUTE ||
SearchType[key] === SearchType.OUTPUT,
),
() => [SearchType.NAME, SearchType.METRIC, SearchType.PROTECTED_ATTRIBUTE, SearchType.OUTPUT],
[],
);
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Bullseye, PageSectionVariants, Spinner } from '@patternfly/react-core';
import { AxiosError } from 'axios';
import UnauthorizedError from '~/pages/UnauthorizedError';
import {
ModelMetricType,
Expand All @@ -22,12 +23,12 @@ const EnsureMetricsAvailable: React.FC<EnsureMetricsAvailableProps> = ({
accessDomain = DEFAULT_ACCESS_DOMAIN,
}) => {
const { data } = React.useContext(ModelServingMetricsContext);
let error;
let error: AxiosError | undefined;
let readyCount = 0;

metrics.forEach((metric) => {
if (data[metric].error) {
error = data[metric].error;
error = data[metric].error as AxiosError;
}
data[metric].loaded && readyCount++;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const MetricsChart: React.FC<MetricsChartProps> = ({
containerComponent = (
<CursorVoronoiContainer
cursorDimension="x"
labels={({ datum }) => (tooltipDisabled ? 'No data' : datum.y)}
labels={({ datum }: { datum: { y: number } }) => (tooltipDisabled ? 'No data' : datum.y)}
labelComponent={<ChartLegendTooltip legendData={legendData} title={tooltipTitle} />}
onCursorChange={handleCursorChange}
mouseFollowTooltips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ModelMetricType,
ModelServingMetricsContext,
} from '~/pages/modelServing/screens/metrics/ModelServingMetricsContext';
import { ContextResourceData, PrometheusQueryRangeResultValue } from '~/types';
import { per100 } from './utils';

const ModelGraphs: React.FC = () => {
Expand All @@ -17,12 +18,16 @@ const ModelGraphs: React.FC = () => {
metrics={[
{
name: 'Success http requests (x100)',
metric: data[ModelMetricType.REQUEST_COUNT_SUCCESS],
metric: data[
ModelMetricType.REQUEST_COUNT_SUCCESS
] as ContextResourceData<PrometheusQueryRangeResultValue>,
translatePoint: per100,
},
{
name: 'Failed http requests (x100)',
metric: data[ModelMetricType.REQUEST_COUNT_FAILED],
metric: data[
ModelMetricType.REQUEST_COUNT_FAILED
] as ContextResourceData<PrometheusQueryRangeResultValue>,
translatePoint: per100,
},
]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react';
import { useModelServingMetrics } from '~/api';
import { ContextResourceData, PrometheusQueryRangeResultValue } from '~/types';
import {
ContextResourceData,
PrometheusQueryRangeResponseDataResult,
PrometheusQueryRangeResultValue,
} from '~/types';
import { DEFAULT_CONTEXT_DATA } from '~/utilities/const';
import {
PerformanceMetricType,
Expand All @@ -25,8 +29,8 @@ export enum ModelMetricType {

type ModelServingMetricsContext = {
data: Record<
ModelMetricType & ServerMetricType,
ContextResourceData<PrometheusQueryRangeResultValue>
ModelMetricType | ServerMetricType,
ContextResourceData<PrometheusQueryRangeResultValue | PrometheusQueryRangeResponseDataResult>
>;
currentTimeframe: TimeframeTitle;
setCurrentTimeframe: (timeframe: TimeframeTitle) => void;
Expand Down Expand Up @@ -60,7 +64,7 @@ export const ModelServingMetricsContext = React.createContext<ModelServingMetric
type ModelServingMetricsProviderProps = {
children: React.ReactNode;
/** Prometheus query strings computed and ready to use */
queries: Record<ServerMetricType, string> | Record<ModelMetricType, string>;
queries: { [key in ModelMetricType]: string } | { [key in ServerMetricType]: string };
type: PerformanceMetricType;
};

Expand Down
31 changes: 26 additions & 5 deletions frontend/src/pages/modelServing/screens/metrics/ServerGraphs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {
per100,
toPercentage,
} from '~/pages/modelServing/screens/metrics/utils';
import {
ContextResourceData,
PrometheusQueryRangeResponseDataResult,
PrometheusQueryRangeResultValue,
} from '~/types';
import { NamedMetricChartLine } from './types';

const ServerGraphs: React.FC = () => {
Expand All @@ -19,16 +24,25 @@ const ServerGraphs: React.FC = () => {
<Stack hasGutter>
<StackItem>
<MetricsChart
metrics={{ metric: data[ServerMetricType.REQUEST_COUNT], translatePoint: per100 }}
metrics={{
metric: data[
ServerMetricType.REQUEST_COUNT
] as ContextResourceData<PrometheusQueryRangeResultValue>,
translatePoint: per100,
}}
color="blue"
title="Http requests (x100)"
/>
</StackItem>
<StackItem>
<MetricsChart
metrics={data[ServerMetricType.AVG_RESPONSE_TIME].data.map(
metrics={(
data[
ServerMetricType.AVG_RESPONSE_TIME
] as ContextResourceData<PrometheusQueryRangeResponseDataResult>
).data.map(
(line): NamedMetricChartLine => ({
name: line.metric.pod,
name: line.metric.pod || '',
metric: {
...data[ServerMetricType.AVG_RESPONSE_TIME],
data: convertPrometheusNaNToZero(line.values),
Expand All @@ -42,7 +56,12 @@ const ServerGraphs: React.FC = () => {
</StackItem>
<StackItem>
<MetricsChart
metrics={{ metric: data[ServerMetricType.CPU_UTILIZATION], translatePoint: toPercentage }}
metrics={{
metric: data[
ServerMetricType.CPU_UTILIZATION
] as ContextResourceData<PrometheusQueryRangeResultValue>,
translatePoint: toPercentage,
}}
color="purple"
title="CPU utilization %"
domain={() => ({
Expand All @@ -53,7 +72,9 @@ const ServerGraphs: React.FC = () => {
<StackItem>
<MetricsChart
metrics={{
metric: data[ServerMetricType.MEMORY_UTILIZATION],
metric: data[
ServerMetricType.MEMORY_UTILIZATION
] as ContextResourceData<PrometheusQueryRangeResultValue>,
translatePoint: toPercentage,
}}
color="orange"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModelServingMetricsContext } from '~/pages/modelServing/screens/metrics
import { BiasMetricConfig } from '~/concepts/explainability/types';
import { createChartThresholds } from '~/pages/modelServing/screens/metrics/utils';
import { BIAS_CHART_CONFIGS } from '~/pages/modelServing/screens/metrics/const';
import { PrometheusQueryRangeResponseDataResult } from '~/types';

export type TrustyChartProps = {
biasMetricConfig: BiasMetricConfig;
Expand All @@ -18,9 +19,9 @@ const TrustyChart: React.FC<TrustyChartProps> = ({ biasMetricConfig }) => {
BIAS_CHART_CONFIGS[metricType];

const metric = React.useMemo(() => {
const metricData = data[modelMetricKey].data;
const metricData = data[modelMetricKey].data as PrometheusQueryRangeResponseDataResult[];

const values = metricData.find((x) => x.metric.request === id)?.values;
const values = metricData.find((x) => x.metric.request === id)?.values || [];

return {
...data[modelMetricKey],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ const MetricTypeField: React.FC<MetricTypeFieldProps> = ({ fieldId, value, onCha
menuAppendTo="parent"
>
{Object.keys(BiasMetricType).map((type) => (
<SelectOption key={type} value={type} description={METRIC_TYPE_DESCRIPTION[type]}>
{METRIC_TYPE_DISPLAY_NAME[type]}
<SelectOption
key={type}
value={type}
description={METRIC_TYPE_DESCRIPTION[type as keyof typeof BiasMetricType]}
>
{METRIC_TYPE_DISPLAY_NAME[type as keyof typeof BiasMetricType]}
</SelectOption>
))}
</Select>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/pages/modelServing/screens/metrics/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const isModelMetricsEnabled = (
export const getServerMetricsQueries = (
server: ServingRuntimeKind,
currentTimeframe: TimeframeTitle,
): Record<ServerMetricType, string> => {
): { [key in ServerMetricType]: string } => {
const namespace = server.metadata.namespace;
const name = server.metadata.name;
const responseTimeStep = QueryTimeframeStep[ServerMetricType.AVG_RESPONSE_TIME][currentTimeframe];
Expand All @@ -54,7 +54,7 @@ export const getServerMetricsQueries = (
export const getModelMetricsQueries = (
model: InferenceServiceKind,
currentTimeframe: TimeframeTitle,
): Record<ModelMetricType, string> => {
): { [key in ModelMetricType]: string } => {
const namespace = model.metadata.namespace;
const name = model.metadata.name;

Expand Down Expand Up @@ -332,5 +332,7 @@ export const convertConfigurationRequestType = (
export const getThresholdDefaultDelta = (metricType?: BiasMetricType) =>
metricType && BIAS_CHART_CONFIGS[metricType].defaultDelta;

export const convertPrometheusNaNToZero = (data: PrometheusQueryRangeResultValue[]) =>
export const convertPrometheusNaNToZero = (
data: PrometheusQueryRangeResultValue[],
): PrometheusQueryRangeResultValue[] =>
data.map((value) => [value[0], isNaN(Number(value[1])) ? '0' : value[1]]);
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ const ServingRuntimeTableRow: React.FC<ServingRuntimeTableRowProps> = ({

const [performanceMetricsEnabled] = usePerformanceMetricsEnabled();

const onToggle = (_, __, colIndex: ServingRuntimeTableTabs) => {
setExpandedColumn(expandedColumn === colIndex ? undefined : colIndex);
};

const compoundExpandParams = (
col: ServingRuntimeTableTabs,
isDisabled: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ const ProjectListView: React.FC<ProjectListViewProps> = ({ allowCreate }) => {
setSearch('');
};

const searchTypes = Object.keys(SearchType).filter(
(key) =>
SearchType[key] === SearchType.NAME ||
SearchType[key] === SearchType.PROJECT ||
SearchType[key] === SearchType.USER,
const searchTypes = React.useMemo(
() => [SearchType.NAME, SearchType.PROJECT, SearchType.USER],
[],
);

const [deleteData, setDeleteData] = React.useState<ProjectKind | undefined>();
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Common types, should be kept up to date with backend types
*/

import { AxiosError } from 'axios';
import { ServingRuntimeSize } from '~/pages/modelServing/screens/types';
import { EnvironmentFromVariable } from '~/pages/projects/types';
import { ImageStreamKind, ImageStreamSpecTagType } from './k8sTypes';
Expand All @@ -18,8 +19,10 @@ export type PrometheusQueryResponse = {
};

export type PrometheusQueryRangeResponseDataResult = {
// not used -- see https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries for more info
metric: unknown;
metric: {
request?: string;
pod?: string;
};
values: PrometheusQueryRangeResultValue[];
};
export type PrometheusQueryRangeResponseData = {
Expand Down Expand Up @@ -731,7 +734,7 @@ export type GPUInfo = {
export type ContextResourceData<T> = {
data: T[];
loaded: boolean;
error?: Error;
error?: Error | AxiosError;
refresh: () => void;
};

Expand Down
Loading