File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ const mockedPodMetrics: PodMetricsList = {
29
29
} ,
30
30
timestamp : '2021-09-26T11:57:21Z' ,
31
31
window : '30s' ,
32
- containers : [ { name : 'nginx' , usage : { cpu : '5000000n ' , memory : '3912Ki' } } ] ,
32
+ containers : [ { name : 'nginx' , usage : { cpu : '50000000n ' , memory : '3912Ki' } } ] ,
33
33
} ,
34
34
{
35
35
metadata : {
@@ -42,7 +42,7 @@ const mockedPodMetrics: PodMetricsList = {
42
42
window : '30s' ,
43
43
containers : [
44
44
{ name : 'nginx' , usage : { cpu : '0' , memory : '4012Ki' } } ,
45
- { name : 'sidecar' , usage : { cpu : '140000000n ' , memory : '3012Ki' } } ,
45
+ { name : 'sidecar' , usage : { cpu : '1400000000n ' , memory : '3012Ki' } } ,
46
46
] ,
47
47
} ,
48
48
] ,
Original file line number Diff line number Diff line change @@ -28,9 +28,33 @@ export function quantityToScalar(quantity: string): number | bigint {
28
28
}
29
29
switch ( suffix ) {
30
30
case 'n' :
31
- return Number ( quantity . substr ( 0 , quantity . length - 1 ) ) . valueOf ( ) / 100_000_000.0 ;
31
+ return Number ( quantity . substr ( 0 , quantity . length - 1 ) ) . valueOf ( ) / 1_000_000_000.0 ;
32
+ case 'u' :
33
+ return Number ( quantity . substr ( 0 , quantity . length - 1 ) ) . valueOf ( ) / 1_000_000.0 ;
32
34
case 'm' :
33
35
return Number ( quantity . substr ( 0 , quantity . length - 1 ) ) . valueOf ( ) / 1000.0 ;
36
+ case 'k' :
37
+ return BigInt ( quantity . substr ( 0 , quantity . length - 1 ) ) * BigInt ( 1000 ) ;
38
+ case 'M' :
39
+ return BigInt ( quantity . substr ( 0 , quantity . length - 1 ) ) * BigInt ( 1000 * 1000 ) ;
40
+ case 'G' :
41
+ return BigInt ( quantity . substr ( 0 , quantity . length - 1 ) ) * BigInt ( 1000 * 1000 * 1000 ) ;
42
+ case 'T' :
43
+ return (
44
+ BigInt ( quantity . substr ( 0 , quantity . length - 1 ) ) * BigInt ( 1000 * 1000 * 1000 ) * BigInt ( 1000 )
45
+ ) ;
46
+ case 'P' :
47
+ return (
48
+ BigInt ( quantity . substr ( 0 , quantity . length - 1 ) ) *
49
+ BigInt ( 1000 * 1000 * 1000 ) *
50
+ BigInt ( 1000 * 1000 )
51
+ ) ;
52
+ case 'E' :
53
+ return (
54
+ BigInt ( quantity . substr ( 0 , quantity . length - 1 ) ) *
55
+ BigInt ( 1000 * 1000 * 1000 ) *
56
+ BigInt ( 1000 * 1000 * 1000 )
57
+ ) ;
34
58
case 'Ki' :
35
59
return BigInt ( quantity . substr ( 0 , quantity . length - 2 ) ) * BigInt ( 1024 ) ;
36
60
case 'Mi' :
Original file line number Diff line number Diff line change @@ -54,11 +54,21 @@ describe('Utils', () => {
54
54
it ( 'should parse quantities' , ( ) => {
55
55
expect ( quantityToScalar ( '' ) ) . to . equal ( 0 ) ;
56
56
57
+ expect ( quantityToScalar ( '2n' ) ) . to . equal ( 2 / 1_000_000_000 ) ;
58
+ expect ( quantityToScalar ( '3u' ) ) . to . equal ( 3 / 1_000_000 ) ;
57
59
expect ( quantityToScalar ( '100m' ) ) . to . equal ( 0.1 ) ;
60
+ expect ( quantityToScalar ( '3k' ) ) . to . equal ( BigInt ( 3000 ) ) ;
61
+ expect ( quantityToScalar ( '3M' ) ) . to . equal ( BigInt ( 3 * 1000 * 1000 ) ) ;
62
+ expect ( quantityToScalar ( '3G' ) ) . to . equal ( BigInt ( 3 * 1000 * 1000 * 1000 ) ) ;
63
+ expect ( quantityToScalar ( '5T' ) ) . to . equal ( BigInt ( 5 * 1000 * 1000 * 1000 ) * BigInt ( 1000 ) ) ;
64
+ expect ( quantityToScalar ( '3P' ) ) . to . equal ( BigInt ( 3 * 1000 * 1000 * 1000 ) * BigInt ( 1000 * 1000 ) ) ;
65
+ expect ( quantityToScalar ( '14E' ) ) . to . equal (
66
+ BigInt ( 14 * 1000 * 1000 * 1000 ) * BigInt ( 1000 * 1000 * 1000 ) ,
67
+ ) ;
68
+
58
69
expect ( quantityToScalar ( '0.2' ) ) . to . equal ( 0.2 ) ;
59
70
expect ( quantityToScalar ( '1976m' ) ) . to . equal ( 1.976 ) ;
60
71
61
- expect ( quantityToScalar ( '1024' ) ) . to . equal ( 1024 ) ;
62
72
expect ( quantityToScalar ( '1024' ) ) . to . equal ( 1024 ) ;
63
73
expect ( quantityToScalar ( '10e3' ) ) . to . equal ( 10000 ) ;
64
74
You can’t perform that action at this time.
0 commit comments