mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-19 01:17:18 +02:00
fix: try to make the network overview stable (#3036)
## About the changes
Use `useMemo` as in NetworkTraffic:
6ad27c2e9c/frontend/src/component/admin/network/NetworkTraffic/NetworkTraffic.tsx (L173-L176)
Hopefully this should help getting rid of the flakiness of the UI
This commit is contained in:
parent
ab9712812a
commit
a0e4f54b9a
@ -4,6 +4,8 @@ import { useInstanceMetrics } from 'hooks/api/getters/useInstanceMetrics/useInst
|
|||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { Alert, styled } from '@mui/material';
|
import { Alert, styled } from '@mui/material';
|
||||||
import { unknownify } from 'utils/unknownify';
|
import { unknownify } from 'utils/unknownify';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { RequestsPerSecondSchema } from 'openapi';
|
||||||
import logoIcon from 'assets/icons/logoBg.svg';
|
import logoIcon from 'assets/icons/logoBg.svg';
|
||||||
import { formatAssetPath } from 'utils/formatPath';
|
import { formatAssetPath } from 'utils/formatPath';
|
||||||
|
|
||||||
@ -27,37 +29,34 @@ interface INetworkApp {
|
|||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const toGraphData = (metrics?: RequestsPerSecondSchema) => {
|
||||||
|
const results = metrics?.data?.result;
|
||||||
|
return (
|
||||||
|
results
|
||||||
|
?.map(result => {
|
||||||
|
const values = (result.values || []) as ResultValue[];
|
||||||
|
const data = values.filter(value => isRecent(value)) || [];
|
||||||
|
let reqs = 0;
|
||||||
|
if (data.length) {
|
||||||
|
reqs = parseFloat(data[data.length - 1][1]);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
label: unknownify(result.metric?.appName),
|
||||||
|
reqs: reqs.toFixed(2),
|
||||||
|
type: unknownify(result.metric?.endpoint?.split('/')[2]),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(app => app.label !== 'unknown')
|
||||||
|
.filter(app => app.reqs !== '0.00') ?? []
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const NetworkOverview = () => {
|
export const NetworkOverview = () => {
|
||||||
usePageTitle('Network - Overview');
|
usePageTitle('Network - Overview');
|
||||||
const { metrics } = useInstanceMetrics();
|
const { metrics } = useInstanceMetrics();
|
||||||
const results = metrics?.data?.result;
|
const apps: INetworkApp[] = useMemo(() => {
|
||||||
|
return toGraphData(metrics);
|
||||||
const apps: INetworkApp[] = [];
|
}, [metrics]);
|
||||||
|
|
||||||
if (results) {
|
|
||||||
apps.push(
|
|
||||||
...(
|
|
||||||
results
|
|
||||||
?.map(result => {
|
|
||||||
const values = (result.values || []) as ResultValue[];
|
|
||||||
const data =
|
|
||||||
values.filter(value => isRecent(value)) || [];
|
|
||||||
let reqs = 0;
|
|
||||||
if (data.length) {
|
|
||||||
reqs = parseFloat(data[data.length - 1][1]);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
label: unknownify(result.metric?.appName),
|
|
||||||
reqs: reqs.toFixed(2),
|
|
||||||
type: unknownify(
|
|
||||||
result.metric?.endpoint?.split('/')[2]
|
|
||||||
),
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter(app => app.label !== 'unknown') || []
|
|
||||||
).filter(app => app.reqs !== '0.00')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const graph = `
|
const graph = `
|
||||||
graph TD
|
graph TD
|
||||||
|
Loading…
Reference in New Issue
Block a user