Skip to content

Commit

Permalink
Yet another fix for computation of resource usage quota ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Aug 14, 2024
1 parent e1c5c51 commit 44051b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 5 additions & 2 deletions web/src/core/tools/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ export function toBytes(str: string) {
return "0b";
}

if (/^\d+$/.test(s)) {
return s + "b";
}

if (s.endsWith("B")) {
//return s.slice(0, -1) + ;
return s;
return s.toLowerCase();
}

if (s.endsWith("Ki") || s.endsWith("K")) {
Expand Down
18 changes: 13 additions & 5 deletions web/src/core/usecases/viewQuotas/utils/computeQuotaUsageRatio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export function computeQuotaUsageRatio(params: {
break cpu_resource_unit;
}

if (!cpuResourceUnit.test(used)) {
console.warn(`Invalid used: ${used} for total: ${total}`);
return undefined;
}

const parseCpuResourceUnit = (value: string) => {
const match = value.match(cpuResourceUnit)!;

Expand All @@ -38,6 +33,19 @@ export function computeQuotaUsageRatio(params: {
return match[2].toLowerCase() === "m" ? n / 1000 : n;
};

if (
!total.endsWith("m") &&
!used.endsWith("m") &&
parseCpuResourceUnit(total) > 1024
) {
break cpu_resource_unit;
}

if (!cpuResourceUnit.test(used)) {
console.warn(`Invalid used: ${used} for total: ${total}`);
return undefined;
}

return parseCpuResourceUnit(used) / parseCpuResourceUnit(total);
}

Expand Down

0 comments on commit 44051b3

Please sign in to comment.