fix: order-dependent metric loss from header dedupe#2866
fix: order-dependent metric loss from header dedupe#2866jfremy-openai wants to merge 1 commit intokubernetes:mainfrom
Conversation
Custom resource metrics could disappear depending on metric declaration order when consecutive duplicate headers were sanitized. The old SanitizeHeaders implementation removed duplicate header entries from the header slice, but metric family byte slices remained indexed at their original positions. WriteAll zips headers and families by index, so deleting headers caused index drift and could skip later metric families entirely. This was especially visible when one duplicate family emitted no samples (e.g. missing nested paths), but the root cause is header/family misalignment and can occur even without empty families. Fix: preserve positional alignment by blanking duplicate/empty headers instead of removing them. WriteAll already skips empty headers naturally, so output remains deduplicated while family indices stay stable. Tests: add two regressions in metrics_writer_test - duplicate header + empty middle family still preserves later family output - duplicate headers without empty families still preserve later family output Also update TestSanitizeHeaders expectations for index-preserving blanking behavior.
|
|
|
This issue is currently awaiting triage. If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the The DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Welcome @jfremy-openai! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jfremy-openai 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 |
|
/easycla |
What this PR does / why we need it:
Custom resource metrics could disappear depending on metric declaration order when consecutive duplicate headers were sanitized. The old SanitizeHeaders implementation removed duplicate header entries from the header slice, but metric family byte slices remained indexed at their original positions. WriteAll zips headers and families by index, so deleting headers caused index drift and could skip later metric families entirely.
This was especially visible when one duplicate family emitted no samples (e.g. missing nested paths), but the root cause is header/family misalignment and can occur even without empty families.
Fix: preserve positional alignment by blanking duplicate/empty headers instead of removing them. WriteAll already skips empty headers naturally, so output remains deduplicated while family indices stay stable.
Tests: add two regressions in metrics_writer_test
Also update TestSanitizeHeaders expectations for index-preserving blanking behavior.
How does this change affect the cardinality of KSM: does not change cardinality