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: [M3-7758] - Linode Network Graph Tooltip - Incorrect Units #10197

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
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10197-fixed-1708020473057.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

Linode Network Graph Tooltip - Incorrect Units ([#10197](https://github.com/linode/manager/pull/10197))
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Stats } from '@linode/api-v4/lib/linodes';
import Grid from '@mui/material/Unstable_Grid2';
import { Theme, styled, useTheme } from '@mui/material/styles';
import { map, pathOr } from 'ramda';
import * as React from 'react';

import { AreaChart } from 'src/components/AreaChart/AreaChart';
Expand All @@ -13,14 +12,10 @@ import {
formatBitsPerSecond,
formatNetworkTooltip,
generateNetworkUnits,
NetworkUnit,
} from 'src/features/Longview/shared/utilities';
import { useFlags } from 'src/hooks/useFlags';
import {
Metrics,
getMetrics,
getTotalTraffic,
} from 'src/utilities/statMetrics';
import { readableBytes } from 'src/utilities/unitConversions';
import { Metrics, getMetrics } from 'src/utilities/statMetrics';

import { StatsPanel } from './StatsPanel';

Expand All @@ -30,9 +25,6 @@ export interface TotalTrafficProps {
outTraffic: string;
}

const formatTotalTraffic = (value: number) =>
readableBytes(value, { base10: true }).formatted;

export interface ChartProps {
height: number;
loading: boolean;
Expand Down Expand Up @@ -64,7 +56,7 @@ interface NetworkStats {
const _getMetrics = (data: NetworkStats) => {
return {
privateIn: getMetrics(data.privateIn),
privateOut: getMetrics(data.privateOut ?? []),
privateOut: getMetrics(data.privateOut),
publicIn: getMetrics(data.publicIn),
publicOut: getMetrics(data.publicOut),
};
Expand All @@ -77,42 +69,22 @@ export const NetworkGraphs = (props: Props) => {
const flags = useFlags();

const v4Data: NetworkStats = {
privateIn: pathOr([], ['data', 'netv4', 'private_in'], stats),
privateOut: pathOr([], ['data', 'netv4', 'private_out'], stats),
publicIn: pathOr([], ['data', 'netv4', 'in'], stats),
publicOut: pathOr([], ['data', 'netv4', 'out'], stats),
privateIn: stats?.data.netv4.private_in ?? [],
privateOut: stats?.data.netv4.private_out ?? [],
publicIn: stats?.data.netv4.in ?? [],
publicOut: stats?.data.netv4.out ?? [],
};

const v6Data: NetworkStats = {
privateIn: pathOr([], ['data', 'netv6', 'private_in'], stats),
privateOut: pathOr([], ['data', 'netv6', 'private_out'], stats),
publicIn: pathOr([], ['data', 'netv6', 'in'], stats),
publicOut: pathOr([], ['data', 'netv6', 'out'], stats),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you ❀️

privateIn: stats?.data.netv6.private_in ?? [],
privateOut: stats?.data.netv6.private_out ?? [],
publicIn: stats?.data.netv6.in ?? [],
publicOut: stats?.data.netv6.out ?? [],
};

const v4Metrics = _getMetrics(v4Data);
const v6Metrics = _getMetrics(v6Data);

const v4totalTraffic: TotalTrafficProps = map(
formatTotalTraffic,
getTotalTraffic(
v4Metrics.publicIn.total,
v4Metrics.publicOut.total,
v4Data.publicIn.length,
v6Metrics.publicIn.total,
v6Metrics.publicOut.total
)
);

const v6totalTraffic: TotalTrafficProps = map(
formatTotalTraffic,
getTotalTraffic(
v6Metrics.publicIn.total,
v6Metrics.publicOut.total,
v6Metrics.publicIn.length
)
);

// Convert to bytes, which is what generateNetworkUnits expects.
const maxV4InBytes =
Math.max(
Expand Down Expand Up @@ -150,7 +122,6 @@ export const NetworkGraphs = (props: Props) => {
ariaLabel="IPv4 Network Traffic Graph"
data={v4Data}
metrics={v4Metrics}
totalTraffic={v4totalTraffic}
unit={v4Unit}
{...commonGraphProps}
/>
Expand All @@ -166,7 +137,6 @@ export const NetworkGraphs = (props: Props) => {
ariaLabel="IPv6 Network Traffic Graph"
data={v6Data}
metrics={v6Metrics}
totalTraffic={v6totalTraffic}
unit={v6Unit}
{...commonGraphProps}
/>
Expand All @@ -187,8 +157,7 @@ interface GraphProps {
rangeSelection: string;
theme: Theme;
timezone: string;
totalTraffic: TotalTrafficProps;
unit: string;
unit: NetworkUnit;
xAxisTickFormat: string;
}

Expand All @@ -210,7 +179,7 @@ const Graph = (props: GraphProps) => {
const format = formatBitsPerSecond;

const convertNetworkData = (value: number) => {
return convertNetworkToUnit(value, unit as any);
return convertNetworkToUnit(value, unit);
};

/**
Expand Down Expand Up @@ -298,7 +267,7 @@ const Graph = (props: GraphProps) => {
height={420}
showLegend
timezone={timezone}
unit={' Kb/s'}
unit={` ${unit}/s`}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the primary fix. We now pass the unit instead of using the hardcoded Kb/s unit.

/>
</Box>
);
Expand Down
Loading