-
Notifications
You must be signed in to change notification settings - Fork 0
add getter for clientcontext matchbounds #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Merging. Minor. |
There was a problem hiding this 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 adds getter methods for the MatchBounds configuration in both ClientContextInjector and ClientContextManager. It also renames the UpdateBounds method to SetBounds to follow getter/setter naming conventions and ensures the matchBounds field is properly maintained alongside the rule updates.
Key changes:
- Added
matchBoundsfield to both structs to store the original bounds configuration - Renamed
UpdateBoundstoSetBoundsfor consistent naming with the new getter - Added
MatchBounds()getter method with read-lock protection in both structs
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tracker/clientcontext/manager.go | Added matchBounds field storage, renamed UpdateBounds to SetBounds, and implemented thread-safe MatchBounds() getter for Manager |
| tracker/clientcontext/injector.go | Added matchBounds field storage, renamed UpdateBounds to SetBounds, and implemented thread-safe MatchBounds() getter for ClientContextInjector |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (m *Manager) MatchBounds() MatchBounds { | ||
| m.ruleMu.RLock() | ||
| defer m.ruleMu.RUnlock() | ||
| return m.matchBounds |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MatchBounds getter returns a struct containing slices (Inbound and Outbound). While the struct itself is copied, the slices reference the same underlying arrays. This can lead to race conditions if the caller modifies the returned slices or if SetBounds is called concurrently. Consider returning a deep copy of the MatchBounds with copied slices to prevent potential data races.
| return m.matchBounds | |
| // Return a deep copy so callers cannot mutate internal slice backing arrays. | |
| bounds := m.matchBounds | |
| if bounds.Inbound != nil { | |
| inboundCopy := make([]string, len(bounds.Inbound)) | |
| copy(inboundCopy, bounds.Inbound) | |
| bounds.Inbound = inboundCopy | |
| } | |
| if bounds.Outbound != nil { | |
| outboundCopy := make([]string, len(bounds.Outbound)) | |
| copy(outboundCopy, bounds.Outbound) | |
| bounds.Outbound = outboundCopy | |
| } | |
| return bounds |
| func (t *ClientContextInjector) MatchBounds() MatchBounds { | ||
| t.ruleMu.RLock() | ||
| defer t.ruleMu.RUnlock() | ||
| return t.matchBounds | ||
| } |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MatchBounds getter returns a struct containing slices (Inbound and Outbound). While the struct itself is copied, the slices reference the same underlying arrays. This can lead to race conditions if the caller modifies the returned slices or if SetBounds is called concurrently. Consider returning a deep copy of the MatchBounds with copied slices to prevent potential data races.
| m.inboundRule = newBoundsRule(bounds.Inbound) | ||
| m.outboundRule = newBoundsRule(bounds.Outbound) | ||
| m.matchBounds = bounds |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The matchBounds field is updated after creating the rules from the bounds parameter. For better consistency and to ensure the stored state matches the rules, consider updating matchBounds before creating the rules or at the beginning of the method. This ensures that if bounds is modified after being passed to SetBounds, the matchBounds field reflects the exact state used to create the rules.
| m.inboundRule = newBoundsRule(bounds.Inbound) | |
| m.outboundRule = newBoundsRule(bounds.Outbound) | |
| m.matchBounds = bounds | |
| m.matchBounds = bounds | |
| m.inboundRule = newBoundsRule(bounds.Inbound) | |
| m.outboundRule = newBoundsRule(bounds.Outbound) |
| t.inboundRule = newBoundsRule(bounds.Inbound) | ||
| t.outboundRule = newBoundsRule(bounds.Outbound) | ||
| t.matchBounds = bounds |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The matchBounds field is updated after creating the rules from the bounds parameter. For better consistency and to ensure the stored state matches the rules, consider updating matchBounds before creating the rules or at the beginning of the method. This ensures that if bounds is modified after being passed to SetBounds, the matchBounds field reflects the exact state used to create the rules.
| t.inboundRule = newBoundsRule(bounds.Inbound) | |
| t.outboundRule = newBoundsRule(bounds.Outbound) | |
| t.matchBounds = bounds | |
| t.matchBounds = bounds | |
| t.inboundRule = newBoundsRule(bounds.Inbound) | |
| t.outboundRule = newBoundsRule(bounds.Outbound) |
This just adds getters to the
ClientContextInjectorandClientContextManagerfor theMatchBounds.