-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* CPU utilization should be whole numbers * Forgive me for my Typescript sins * Type fixes * Even simpler * as const avoids TS error while still checking the value * move static object construction out of render cycle * by jove, it works without any * we don't need `as QueryKey` anymore, not sure why * rework mergeSiloMetrics and write tests * Fix double header styling issues * Add missing brace * Fix incorrect label * Make tabs full-width * Fixing e2e tests * Unit styling * The Gang Goes Overboard * take Capacity out of system utilization page header * epic test * Usage -> Summary --------- Co-authored-by: David Crespo <[email protected]>
- Loading branch information
1 parent
8978e07
commit a50777c
Showing
15 changed files
with
349 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import { expect, test } from 'vitest' | ||
|
||
import type { SystemMetricName } from '@oxide/api' | ||
|
||
import type { MetricsResult } from './metrics-util' | ||
import { tabularizeSiloMetrics } from './metrics-util' | ||
|
||
function makeResult( | ||
silo: string, | ||
metricName: SystemMetricName, | ||
value: number | ||
): MetricsResult { | ||
return { | ||
data: { | ||
items: [ | ||
{ | ||
datum: { type: 'i64', datum: value }, | ||
timestamp: new Date(), | ||
}, | ||
], | ||
params: { query: { silo }, path: { metricName } }, | ||
}, | ||
} | ||
} | ||
|
||
test('tabularizeSiloMetrics', () => { | ||
expect(tabularizeSiloMetrics([])).toEqual([]) | ||
expect( | ||
tabularizeSiloMetrics([ | ||
makeResult('a', 'virtual_disk_space_provisioned', 1), | ||
makeResult('b', 'virtual_disk_space_provisioned', 2), | ||
makeResult('a', 'cpus_provisioned', 3), | ||
makeResult('b', 'cpus_provisioned', 4), | ||
makeResult('a', 'ram_provisioned', 5), | ||
makeResult('b', 'ram_provisioned', 6), | ||
// here to make sure it gets ignored and doesn't break anything | ||
// @ts-expect-error | ||
{ error: 'whoops' }, | ||
]) | ||
).toEqual([ | ||
{ | ||
siloName: 'a', | ||
metrics: { | ||
virtual_disk_space_provisioned: 1, | ||
cpus_provisioned: 3, | ||
ram_provisioned: 5, | ||
}, | ||
}, | ||
{ | ||
siloName: 'b', | ||
metrics: { | ||
virtual_disk_space_provisioned: 2, | ||
cpus_provisioned: 4, | ||
ram_provisioned: 6, | ||
}, | ||
}, | ||
]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
import type { | ||
MeasurementResultsPage, | ||
SystemMetricName, | ||
SystemMetricPathParams, | ||
SystemMetricQueryParams, | ||
} from '@oxide/api' | ||
import { groupBy } from '@oxide/util' | ||
|
||
export type MetricsResult = { | ||
data?: MeasurementResultsPage & { | ||
params: { | ||
path: SystemMetricPathParams | ||
query?: SystemMetricQueryParams | ||
} | ||
} | ||
} | ||
|
||
type SiloMetric = { | ||
siloName: string | ||
metrics: Record<SystemMetricName, number> | ||
} | ||
|
||
/** | ||
* Turn the big list of query results into something we can display in a table. | ||
* See the tests for an example. | ||
*/ | ||
export function tabularizeSiloMetrics(results: MetricsResult[]): SiloMetric[] { | ||
const processed = results | ||
// filter mostly to ensure we don't try to pull data off an error response | ||
.filter((r) => r.data?.params.query?.silo) | ||
.map((r) => { | ||
const metricName = r.data!.params.path.metricName | ||
const value = r.data!.items[0].datum.datum as number | ||
return { | ||
siloName: r.data!.params.query!.silo!, | ||
metrics: { [metricName]: value }, | ||
} | ||
}) | ||
|
||
return groupBy(processed, (r) => r.siloName).map(([siloName, results]) => { | ||
return { siloName, metrics: Object.assign({}, ...results.map((r) => r.metrics)) } | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.