Fix: kubernetes statistics not respecting selector#5199
Merged
Conversation
tombatossals
pushed a commit
to tombatossals/homepage
that referenced
this pull request
Apr 21, 2025
Contributor
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion for related concerns. See our contributing guidelines for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
After upgrading to v1, I noticed that my Kubernetes widgets were reporting invalid statistics:
This clearly can't be correct, since
kubectl topreports that it only uses about 1.5gb of memory:This issue can be reproduced with the following configuration:
Instead of showing the statistics of the pods in
podSelector, homepage will show the statistics of the entire namespace multiplied by the amount of pods found in the podSelector. This is because.getPodMetrics(namespace, pod.items)is returning the metrics for the entire namespace, as it does not accept a second argument.This pull requests fixes the issue by filtering the metrics by the pods found in the namespace. Since
.getPodMetricscan only filter by namespace, I also pull the fetch outside to reduce the number of calls from the amount of matched pods to just one. I considered using a simple filter per pod for a minimal diff, but I believe using a Set is the better choice here, in case there are a lot of selected pods, to avoid aO(n^2)time complexity.Here is the same entry, with the fixes applied:
Type of change
Checklist: