Skip to content

Conversation

@easwars
Copy link
Contributor

@easwars easwars commented Nov 21, 2025

Change in this PR:

  • Add a new ctor for StringMatcher that can be shared between test and non-test code. This will be used as part of an internal feature to support ext_authz.
  • Create new pointers to match strings instead of using the ones from the proto. This would ensure that the xDS proto structs (which are usually huge) can be garbage collected earlier that currently. This would also ensure that there is no requirement on users creating StringMatchers using arguments to keep those arguments immutable.
  • Fixes a bug involving the regex matcher, which should not be considering the ignore_case field, but was.

RELEASE NOTES:

  • xds: Fix a bug in StringMatcher where regexes would match incorrectly when ignore_case is set to true.

@easwars easwars requested review from arjan-bal and Copilot November 21, 2025 07:07
@easwars easwars added Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Bug labels Nov 21, 2025
@easwars easwars added this to the 1.78 Release milestone Nov 21, 2025
Copilot finished reviewing on behalf of easwars November 21, 2025 07:09
@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.17%. Comparing base (50c6321) to head (c23be55).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8723      +/-   ##
==========================================
- Coverage   83.21%   83.17%   -0.05%     
==========================================
  Files         419      419              
  Lines       32427    32423       -4     
==========================================
- Hits        26985    26968      -17     
- Misses       4054     4066      +12     
- Partials     1388     1389       +1     
Files with missing lines Coverage Δ
internal/xds/matcher/string_matcher.go 92.30% <100.00%> (-0.33%) ⬇️

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the StringMatcher API to make it usable outside of test code and fixes a bug where regex matchers incorrectly considered the ignore_case field. The key changes include:

  • Renaming StringMatcherForTesting to NewStringMatcher to expose it for general use
  • Creating new string pointers instead of reusing proto pointers to enable earlier garbage collection of large xDS proto structs
  • Fixing the regex matcher to correctly ignore the ignore_case field as documented

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/xds/matcher/string_matcher.go Refactored Match() to apply ignoreCase within each case block (fixing regex bug), added newStrPtr() helper for pointer allocation, and renamed StringMatcherForTesting to NewStringMatcher
internal/xds/matcher/string_matcher_test.go Added test cases to verify regex matchers correctly ignore the ignore_case field
internal/xds/xdsclient/xdsresource/unmarshal_cds_test.go Updated test calls from StringMatcherForTesting to NewStringMatcher
internal/credentials/xds/handshake_info_test.go Updated test calls from StringMatcherForTesting to NewStringMatcher
credentials/xds/xds_client_test.go Updated test calls from StringMatcherForTesting to NewStringMatcher

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +135 to 147
// NewStringMatcher is a helper function to create a StringMatcher based
// on the given arguments. At most one of exact, prefix, suffix, contains and
// regex should be non-nil.
func NewStringMatcher(exact, prefix, suffix, contains *string, regex *regexp.Regexp, ignoreCase bool) StringMatcher {
return StringMatcher{
exactMatch: newStrPtr(exact, ignoreCase),
prefixMatch: newStrPtr(prefix, ignoreCase),
suffixMatch: newStrPtr(suffix, ignoreCase),
containsMatch: newStrPtr(contains, ignoreCase),
regexMatch: regex,
containsMatch: contains,
ignoreCase: ignoreCase,
}
if ignoreCase {
switch {
case sm.exactMatch != nil:
*sm.exactMatch = strings.ToLower(*exact)
case sm.prefixMatch != nil:
*sm.prefixMatch = strings.ToLower(*prefix)
case sm.suffixMatch != nil:
*sm.suffixMatch = strings.ToLower(*suffix)
case sm.containsMatch != nil:
*sm.containsMatch = strings.ToLower(*contains)
}
}
return sm
}
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The documentation states "At most one of exact, prefix, suffix, contains and regex should be non-nil," but the function doesn't validate or enforce this constraint. Consider adding validation to return an error or panic if multiple match types are provided, or document that the behavior is undefined when multiple parameters are non-nil.

Since the Match() method uses a switch statement that checks in order (exact, prefix, suffix, contains, regex), if multiple parameters are provided, only the first non-nil one will be used, which could lead to confusing behavior.

Copilot uses AI. Check for mistakes.
suffixMatch: suffix,
// NewStringMatcher is a helper function to create a StringMatcher based
// on the given arguments. At most one of exact, prefix, suffix, contains and
// regex should be non-nil.
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation should clarify that the ignoreCase parameter has no effect when regex is provided, as stated in the StringMatcher struct comment (line 44-45). This would help users understand that setting ignoreCase=true with a regex matcher will not perform case-insensitive matching.

Suggested change
// regex should be non-nil.
// regex should be non-nil. The ignoreCase parameter has no effect when regex is provided.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants