Skip to content

Commit 94b02a7

Browse files
committed
fix(format): teach parseMemoryToBytes the Pi/Ei and P/E suffixes
The bar math learned the full suffix table but the labels next to it still went through the byte parser, which stopped at Ti and fell back to the bare number — a 1PiB aggregate rendered as "1 B". Extending the byte parser fixes every formatMemoryString consumer at once.
1 parent fe25cf5 commit 94b02a7

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

packages/k8s-ui/src/utils/format.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ describe('parseMemoryToBytes', () => {
3232
expect(parseMemoryToBytes('-1Ki')).toBe(-1024)
3333
expect(parseMemoryToBytes('1Ki')).toBe(1024)
3434
})
35+
36+
// Aggregate cluster memory reaches suffixes a single node never carries —
37+
// "1Pi" must not fall through to the bare-number fallback and read as 1 byte.
38+
it('parses the large suffixes an aggregate capacity can carry', () => {
39+
expect(parseMemoryToBytes('1Pi')).toBe(1024 ** 5)
40+
expect(parseMemoryToBytes('1Ei')).toBe(1024 ** 6)
41+
expect(parseMemoryToBytes('1P')).toBe(1000 ** 5)
42+
expect(parseMemoryToBytes('1E')).toBe(1000 ** 6)
43+
})
3544
})
3645

3746
describe('parseQuantityToNumber', () => {

packages/k8s-ui/src/utils/format.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ export function parseMemoryToBytes(memString: string): number {
126126
const num = parseFloat(match[1])
127127
const suffix = match[2]
128128

129-
// Binary suffixes (powers of 1024)
129+
// Binary suffixes (powers of 1024). Pi/Ei are real inputs at cluster scale —
130+
// an aggregate of a thousand 1TiB nodes serializes as "1Pi".
130131
const binarySuffixes: Record<string, number> = {
131132
'Ki': 1024,
132133
'Mi': 1024 ** 2,
133134
'Gi': 1024 ** 3,
134135
'Ti': 1024 ** 4,
136+
'Pi': 1024 ** 5,
137+
'Ei': 1024 ** 6,
135138
}
136139

137140
// Decimal suffixes (powers of 1000)
@@ -141,6 +144,8 @@ export function parseMemoryToBytes(memString: string): number {
141144
'M': 1000 ** 2,
142145
'G': 1000 ** 3,
143146
'T': 1000 ** 4,
147+
'P': 1000 ** 5,
148+
'E': 1000 ** 6,
144149
}
145150

146151
if (suffix in binarySuffixes) {

0 commit comments

Comments
 (0)