Skip to content

Commit f9fe4e4

Browse files
committed
feat(FR-833): Improve metric label formatting in user session history page (#3500)
resolves #3499 (FR-833) <!-- replace NNN, MMM with the GitHub issue number and the corresponding Jira issue number. --> ### Modify the mertric label formatting for proper notation. <!-- Please precisely, concisely, and concretely describe what this PR changes, the rationale behind codes, and how it affects the users and other developers. --> **Checklist:** (if applicable) - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after
1 parent 1aa4a9b commit f9fe4e4

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

react/src/components/SessionMetricGraph.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
convertBinarySizeUnit,
33
toFixedFloorWithoutTrailingZeros,
44
} from '../helper';
5+
import { useResourceSlotsDetails } from '../hooks/backendai';
56
import BAICard from './BAICard';
67
import {
78
SessionMetricGraphQuery,
@@ -68,6 +69,7 @@ const SessionMetricGraph: React.FC<PrometheusMetricGraphProps> = ({
6869
}) => {
6970
const { token } = theme.useToken();
7071
const { styles } = useStyle();
72+
const { mergedResourceSlots } = useResourceSlotsDetails();
7173

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

147+
const getMetricTitle = () => {
148+
const [key, ...rest] = _.split(metricName, '_');
149+
const restLabel = _.startCase(rest.join(' '));
150+
151+
if (_.has(mergedResourceSlots, key)) {
152+
return `${mergedResourceSlots[key]?.human_readable_name} ${restLabel}`;
153+
}
154+
if (_.includes(metricName, 'io')) {
155+
return `${_.upperCase(key)} ${restLabel}`;
156+
}
157+
return `${_.startCase(metricName.replaceAll('_', ' '))}`;
158+
};
159+
145160
return (
146161
<BAICard
147-
title={_.startCase(metricName.replaceAll('_', ' '))}
162+
title={getMetricTitle()}
148163
type="inner"
149164
styles={{
150165
body: {

react/src/pages/StatisticsPage.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import React, { Suspense } from 'react';
88
import { useTranslation } from 'react-i18next';
99
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
1010

11-
type TabKey = 'allocation-history' | 'prometheus-metrics';
12-
1311
interface ResourcesPageProps {}
1412

1513
const tabParam = withDefault(StringParam, 'allocation-history');
@@ -26,14 +24,14 @@ const ResourcesPage: React.FC<ResourcesPageProps> = (props) => {
2624
return (
2725
<BAICard
2826
activeTabKey={curTabKey}
29-
onTabChange={(key) => setCurTabKey(key as TabKey)}
27+
onTabChange={(key) => setCurTabKey(key)}
3028
tabList={filterEmptyItem([
3129
{
3230
key: 'allocation-history',
3331
tab: t('webui.menu.UsageHistory'),
3432
},
3533
baiClient?.supports('user-metrics') && {
36-
key: 'prometheus-metrics',
34+
key: 'user-session-history',
3735
tab: t('webui.menu.UserSessionHistory'),
3836
},
3937
])}
@@ -57,7 +55,7 @@ const ResourcesPage: React.FC<ResourcesPageProps> = (props) => {
5755
<AllocationHistory />
5856
</Suspense>
5957
) : null}
60-
{curTabKey === 'prometheus-metrics' ? (
58+
{curTabKey === 'user-session-history' ? (
6159
<Suspense
6260
fallback={
6361
<Skeleton

0 commit comments

Comments
 (0)