fix: Pod metrics matching missing namespace (#4927)#4933
fix: Pod metrics matching missing namespace (#4927)#4933Utkarshpandey0001 wants to merge 1 commit intokubernetes-sigs:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Utkarshpandey0001 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
Welcome @Utkarshpandey0001! |
ff529c0 to
b6f0e35
Compare
There was a problem hiding this comment.
Pull request overview
Fixes incorrect pod CPU/memory metrics attribution in the Pods list when multiple pods share the same name across namespaces, by tightening the frontend’s metrics-to-pod matching logic.
Changes:
- Update pod metrics lookup in
PodListRendererto match by both pod name and namespace. - Update Storybook mock PodMetrics data to include the namespace field.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| frontend/src/components/pod/List.tsx | Adjusts PodMetrics matching logic used to compute CPU/memory columns. |
| frontend/src/components/pod/PodList.stories.tsx | Updates MSW metrics mock to include metadata.namespace so the story continues to show metrics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const metric = metrics?.find( | ||
| it => it.getName() === pod.getName() && it.getNamespace() === pod.getNamespace() | ||
| ); |
There was a problem hiding this comment.
Metrics lookup still isn’t fully disambiguated in multi-cluster mode. Pod.useList() / PodMetrics.useList() can return items from multiple clusters (note the cluster column), so matching only by name+namespace can still attach the wrong metrics when the same pod name/namespace exists in different clusters. Include cluster in the predicate as well (e.g., compare it.cluster with pod.cluster).
| const metric = metrics?.find( | ||
| it => it.getName() === pod.getName() && it.getNamespace() === pod.getNamespace() | ||
| ); |
There was a problem hiding this comment.
Same issue as CPU lookup: to avoid cross-cluster collisions, the metrics match should include cluster in addition to name+namespace (both lists can span multiple clusters). Otherwise memory metrics can be taken from another cluster that has the same pod name/namespace.
Fixes issue #4927
Changes:
This PR fixes a bug where Headlamp displays incorrect CPU and memory metrics for pods that share the same name across different namespaces (e.g., in the Workloads > Pods view).
Previously, the
getCpuUsage and getMemoryUsage functions in List.tsx matched metrics to pods using only the pod name (it.getName() === pod.getName()). This caused all pods with the same name to display the metrics of the first matched pod.
This fix updates the lookup logic to also compare the namespace (it.getNamespace() === pod.getNamespace()), ensuring each pod correctly displays its own individual metrics.