Merge pull request #31065 from koalaty-code/kubernetes-pod-cpu-metrics

fix(kubernetes): fixes calculation of pod cpu utilization
This commit is contained in:
Fredrik Adelöw
2025-09-29 22:56:08 +02:00
committed by GitHub
4 changed files with 9 additions and 12 deletions
@@ -74,7 +74,7 @@ describe('PodsTable', () => {
limitTotal: '134217728',
},
cpu: {
currentUsage: 0.4966115,
currentUsage: 0.0496,
requestTotal: 0.05,
limitTotal: 0.05,
},
@@ -42,7 +42,7 @@ describe('pod', () => {
const result = podStatusToCpuUtil({
cpu: {
// ~50m
currentUsage: 0.4966115,
currentUsage: 0.0496,
// 50m
requestTotal: 0.05,
// 100m
+2 -10
View File
@@ -139,22 +139,14 @@ export const currentToDeclaredResourceToPerc = (
export const podStatusToCpuUtil = (podStatus: ClientPodStatus): ReactNode => {
const cpuUtil = podStatus.cpu;
let currentUsage: number | string = cpuUtil.currentUsage;
// current usage number for CPU is a different unit than request/limit total
// this might be a bug in the k8s library
if (typeof cpuUtil.currentUsage === 'number') {
currentUsage = cpuUtil.currentUsage / 10;
}
return (
<SubvalueCell
value={`requests: ${currentToDeclaredResourceToPerc(
currentUsage,
cpuUtil.currentUsage,
cpuUtil.requestTotal,
)} of ${formatMillicores(cpuUtil.requestTotal)}`}
subvalue={`limits: ${currentToDeclaredResourceToPerc(
currentUsage,
cpuUtil.currentUsage,
cpuUtil.limitTotal,
)} of ${formatMillicores(cpuUtil.limitTotal)}`}
/>