Skip to content
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
17 changes: 16 additions & 1 deletion react/src/components/SessionMetricGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
convertBinarySizeUnit,
toFixedFloorWithoutTrailingZeros,
} from '../helper';
import { useResourceSlotsDetails } from '../hooks/backendai';
import BAICard from './BAICard';
import {
SessionMetricGraphQuery,
Expand Down Expand Up @@ -68,6 +69,7 @@ const SessionMetricGraph: React.FC<PrometheusMetricGraphProps> = ({
}) => {
const { token } = theme.useToken();
const { styles } = useStyle();
const { mergedResourceSlots } = useResourceSlotsDetails();

const { capacity_metric, current_metric } =
useLazyLoadQuery<SessionMetricGraphQuery>(
Expand Down Expand Up @@ -142,9 +144,22 @@ const SessionMetricGraph: React.FC<PrometheusMetricGraphProps> = ({
dayDiff < 7 ? '5m' : dayDiff < 30 ? '1h' : '1d',
);

const getMetricTitle = () => {
const [key, ...rest] = _.split(metricName, '_');
const restLabel = _.startCase(rest.join(' '));

if (_.has(mergedResourceSlots, key)) {
return `${mergedResourceSlots[key]?.human_readable_name} ${restLabel}`;
}
if (_.includes(metricName, 'io')) {
return `${_.upperCase(key)} ${restLabel}`;
}
return `${_.startCase(metricName.replaceAll('_', ' '))}`;
};

return (
<BAICard
title={_.startCase(metricName.replaceAll('_', ' '))}
title={getMetricTitle()}
type="inner"
styles={{
body: {
Expand Down
8 changes: 3 additions & 5 deletions react/src/pages/StatisticsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import React, { Suspense } from 'react';
import { useTranslation } from 'react-i18next';
import { StringParam, useQueryParam, withDefault } from 'use-query-params';

type TabKey = 'allocation-history' | 'prometheus-metrics';

interface ResourcesPageProps {}

const tabParam = withDefault(StringParam, 'allocation-history');
Expand All @@ -26,14 +24,14 @@ const ResourcesPage: React.FC<ResourcesPageProps> = (props) => {
return (
<BAICard
activeTabKey={curTabKey}
onTabChange={(key) => setCurTabKey(key as TabKey)}
onTabChange={(key) => setCurTabKey(key)}
tabList={filterEmptyItem([
{
key: 'allocation-history',
tab: t('webui.menu.UsageHistory'),
},
baiClient?.supports('user-metrics') && {
key: 'prometheus-metrics',
key: 'user-session-history',
tab: t('webui.menu.UserSessionHistory'),
},
])}
Expand All @@ -57,7 +55,7 @@ const ResourcesPage: React.FC<ResourcesPageProps> = (props) => {
<AllocationHistory />
</Suspense>
) : null}
{curTabKey === 'prometheus-metrics' ? (
{curTabKey === 'user-session-history' ? (
<Suspense
fallback={
<Skeleton
Expand Down