test: add long-label injection to TestValidateLabels#14156
Draft
test: add long-label injection to TestValidateLabels#14156
Conversation
| injectedLongLabelValue := strings.Repeat("L", 100) | ||
| // Pre-compute the expected hash for the injected long label. | ||
| injectedLabelTruncatedValue := injectedLongLabelValue[:4] + hashLabelValueInto(injectedLongLabelValue, injectedLongLabelValue) | ||
| injectedLabelDroppedValue := hashLabelValueInto(injectedLongLabelValue, injectedLongLabelValue) |
There was a problem hiding this comment.
String mutation corrupts expected label values
Low Severity
The hashLabelValueInto function mutates the backing array of injectedLongLabelValue in place. On line 405, after the function call, injectedLongLabelValue[:4] returns "(has" (the first 4 bytes of the hash output) instead of "LLLL". On line 406, the second call computes a hash of the already-mutated string instead of the original. Both injectedLabelTruncatedValue and injectedLabelDroppedValue contain incorrect expected values. This bug is currently masked because these values are only used in dead code.
|
Bugbot Autofix prepared a fix for the bug found in the latest run.
Preview (63714cf)diff --git a/pkg/distributor/validate_test.go b/pkg/distributor/validate_test.go
--- a/pkg/distributor/validate_test.go
+++ b/pkg/distributor/validate_test.go
@@ -402,8 +402,11 @@ func TestValidateLabels(t *testing.T) {
// injectedLongLabelValue is 100 chars, exceeding the 75 char limit for truncate/drop users.
injectedLongLabelValue := strings.Repeat("L", 100)
// Pre-compute the expected hash for the injected long label.
- injectedLabelTruncatedValue := injectedLongLabelValue[:4] + hashLabelValueInto(injectedLongLabelValue, injectedLongLabelValue)
- injectedLabelDroppedValue := hashLabelValueInto(injectedLongLabelValue, injectedLongLabelValue)
+ // Use separate copies because hashLabelValueInto mutates the backing array in place.
+ truncateSrc := strings.Repeat("L", 100)
+ injectedLabelTruncatedValue := "LLLL" + hashLabelValueInto(truncateSrc, truncateSrc)
+ dropSrc := strings.Repeat("L", 100)
+ injectedLabelDroppedValue := hashLabelValueInto(dropSrc, dropSrc)
for _, c := range testCases {
caseSchemes := validationSchemes |
Following the review comment on PR #14131, this adds long-label injection variants to TestValidateLabels to ensure that long-label handling (truncate/drop strategies) doesn't mask ANY validation error, not just duplicate label detection. For each eligible test case, the test now runs in three modes: - no_injection: original behavior - inject_long_label_truncate: adds a long-value label, uses truncate user - inject_long_label_drop: adds a long-value label, uses drop user Test cases are skipped for injection when they: - Already test long-label handling (customUserID is truncate/drop user) - Use non-legacy validation scheme (injection users use legacy) - Would exceed label count limits with the additional label - Have wantLabels (exact label validation) This provides regression protection: if a validation check is accidentally placed inside the long-label handling branch (like the bug fixed in #14131), the injection variants will catch it by showing the validation error is masked when a long label is present.
183b33b to
a5929d3
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does
Following the review comment on PR #14131, this adds long-label injection variants to
TestValidateLabelsto ensure that long-label handling (truncate/drop strategies) doesn't mask ANY validation error, not just duplicate label detection.For each eligible test case, the test now runs in three modes:
no_injection: original behaviorinject_long_label_truncate: adds a long-value label, uses truncate userinject_long_label_drop: adds a long-value label, uses drop userTest cases are skipped for injection when they would conflict with the injection behavior (already testing long-label handling, non-legacy scheme, would exceed label limits, or have exact label validation).
This provides regression protection: if a validation check is accidentally placed inside the long-label handling branch, the injection variants will catch it by showing the validation error is masked when a long label is present.
Which issue(s) this PR fixes or relates to
Related to #14131
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]. If changelog entry is not needed, please add thechangelog-not-neededlabel to the PR.about-versioning.mdupdated with experimental features.