Skip to content

Commit fa375f9

Browse files
committed
replace getUnit with explicit unit prop
1 parent f448a0a commit fa375f9

File tree

6 files changed

+14
-19
lines changed

6 files changed

+14
-19
lines changed

app/components/oxql-metrics/OxqlMetric.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
composeOxqlData,
3131
getBytesChartProps,
3232
getCountChartProps,
33-
getUnit,
3433
getUtilizationChartProps,
3534
type OxqlQuery,
3635
} from './util'
@@ -47,9 +46,10 @@ export async function loader({ params }: LoaderFunctionArgs) {
4746
export type OxqlMetricProps = OxqlQuery & {
4847
title: string
4948
description?: string
49+
unit: 'Bytes' | '%' | 'Count'
5050
}
5151

52-
export function OxqlMetric({ title, description, ...queryObj }: OxqlMetricProps) {
52+
export function OxqlMetric({ title, description, unit, ...queryObj }: OxqlMetricProps) {
5353
// only start reloading data once an intial dataset has been loaded
5454
const { setIsIntervalPickerEnabled } = useMetricsContext()
5555
const query = toOxqlStr(queryObj)
@@ -67,7 +67,6 @@ export function OxqlMetric({ title, description, ...queryObj }: OxqlMetricProps)
6767
}, [metrics, setIsIntervalPickerEnabled])
6868
const { startTime, endTime } = queryObj
6969
const { chartData, timeseriesCount } = useMemo(() => composeOxqlData(metrics), [metrics])
70-
const unit = getUnit(title)
7170
const { data, label, unitForSet, yAxisTickFormatter } = useMemo(() => {
7271
if (unit === 'Bytes') return getBytesChartProps(chartData)
7372
if (unit === 'Count') return getCountChartProps(chartData)

app/components/oxql-metrics/util.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
getMaxExponent,
1616
getMeanWithinSeconds,
1717
getTimePropsForOxqlQuery,
18-
getUnit,
1918
getUtilizationChartProps,
2019
oxqlTimestamp,
2120
sumValues,
@@ -117,13 +116,6 @@ test('yAxisLabelForCountChart', () => {
117116
expect(yAxisLabelForCountChart(10 ** 12 + 1, 4)).toEqual('1T')
118117
})
119118

120-
test('getUnit', () => {
121-
expect(getUnit('CPU Utilization')).toEqual('%')
122-
expect(getUnit('Bytes Read')).toEqual('Bytes')
123-
expect(getUnit('Disk reads')).toEqual('Count')
124-
expect(getUnit('Anything else')).toEqual('Count')
125-
})
126-
127119
test('getLargestValue', () => {
128120
const sampleData = [
129121
{ timestamp: 1739232000000, value: 5 },

app/components/oxql-metrics/util.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ export const sumValues = (timeseries: Timeseries[], arrLen: number): (number | n
122122
)
123123
)
124124

125-
type ChartUnitType = 'Bytes' | '%' | 'Count'
126-
export const getUnit = (title: string): ChartUnitType => {
127-
if (title.includes('Bytes')) return 'Bytes'
128-
if (title.includes('Utilization')) return '%'
129-
return 'Count'
130-
}
131-
132125
// Take the OxQL Query Result and return the data in a format that the chart can use
133126
// We'll do this by creating two arrays: one for the timestamps and one for the values
134127
// We'll then combine these into an array of objects, each with a timestamp and a value

app/pages/project/instances/instance/tabs/MetricsTab/CpuMetricsTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default function CpuMetricsTab() {
3636
type CpuChartType = OxqlVcpuState | 'all'
3737

3838
const queryBase = {
39+
unit: '%' as const,
3940
metricName: 'virtual_machine:vcpu_usage' as const,
4041
startTime,
4142
endTime,
@@ -96,7 +97,7 @@ export default function CpuMetricsTab() {
9697
title="CPU Utilization: Waiting"
9798
eqFilters={{ instance_id: instanceData.id, state: 'waiting' }}
9899
{...queryBase}
99-
/>{' '}
100+
/>
100101
</MetricRow>
101102
</>
102103
) : (

app/pages/project/instances/instance/tabs/MetricsTab/DiskMetricsTab.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ function DiskMetrics({ disks, instance }: { disks: Disk[]; instance: Instance })
118118
title="Disk Reads"
119119
description="Total number of read operations from the disk"
120120
metricName="virtual_disk:reads"
121+
unit="Count"
121122
{...queryBase}
122123
/>
123124
<OxqlMetric
124125
title="Disk Writes"
125126
description="Total number of write operations to the disk"
126127
metricName="virtual_disk:writes"
128+
unit="Count"
127129
{...queryBase}
128130
/>
129131
</MetricRow>
@@ -133,12 +135,14 @@ function DiskMetrics({ disks, instance }: { disks: Disk[]; instance: Instance })
133135
title="Bytes Read"
134136
description="Number of bytes read from the disk"
135137
metricName="virtual_disk:bytes_read"
138+
unit="Bytes"
136139
{...queryBase}
137140
/>
138141
<OxqlMetric
139142
title="Bytes Written"
140143
description="Number of bytes written to the disk"
141144
metricName="virtual_disk:bytes_written"
145+
unit="Bytes"
142146
{...queryBase}
143147
/>
144148
</MetricRow>
@@ -148,6 +152,7 @@ function DiskMetrics({ disks, instance }: { disks: Disk[]; instance: Instance })
148152
title="Disk Flushes"
149153
description="Total number of flush operations on the disk"
150154
metricName="virtual_disk:flushes"
155+
unit="Count"
151156
{...queryBase}
152157
/>
153158
</MetricRow>

app/pages/project/instances/instance/tabs/MetricsTab/NetworkMetricsTab.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ function NetworkMetrics({ nics }: { nics: InstanceNetworkInterface[] }) {
115115
title="Bytes Sent"
116116
description="Number of bytes sent on the link"
117117
metricName="instance_network_interface:bytes_sent"
118+
unit="Bytes"
118119
{...queryBase}
119120
/>
120121
<OxqlMetric
121122
title="Bytes Received"
122123
description="Number of bytes received on the link"
123124
metricName="instance_network_interface:bytes_received"
125+
unit="Bytes"
124126
{...queryBase}
125127
/>
126128
</MetricRow>
@@ -129,19 +131,22 @@ function NetworkMetrics({ nics }: { nics: InstanceNetworkInterface[] }) {
129131
title="Packets Sent"
130132
description="Number of packets sent on the link"
131133
metricName="instance_network_interface:packets_sent"
134+
unit="Count"
132135
{...queryBase}
133136
/>
134137
<OxqlMetric
135138
title="Packets Received"
136139
description="Number of packets received on the link"
137140
metricName="instance_network_interface:packets_received"
141+
unit="Count"
138142
{...queryBase}
139143
/>
140144
</MetricRow>
141145
<MetricRow>
142146
<OxqlMetric
143147
title="Packets Dropped"
144148
metricName="instance_network_interface:packets_dropped"
149+
unit="Count"
145150
{...queryBase}
146151
/>
147152
</MetricRow>

0 commit comments

Comments
 (0)