grpclb/state, attributes: implement Stringer for grpclb keyType and document <%p> rationale - #9383
grpclb/state, attributes: implement Stringer for grpclb keyType and document <%p> rationale#9383pefoley2 wants to merge 1 commit into
Conversation
Avoid formatting errors (%!p(...)) on value types and pointers when formatting attributes, while preserving full type and value information.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9383 +/- ##
==========================================
+ Coverage 87.54% 87.58% +0.03%
==========================================
Files 429 429
Lines 30622 30624 +2
==========================================
+ Hits 26807 26821 +14
+ Misses 3814 3802 -12
Partials 1 1
🚀 New features to boost your workflow:
|
|
Thanks for working on this PR! However, we cannot accept this change because using This was previously investigated and fixed in #6664. At the time, In PR #6664, we intentionally switched the fallback to Changing the fallback to
While the So, closing this PR. |
|
Thanks for the feedback and context around #6664! I have reworked the changes:
Could you please reopen this PR (or let me know if you would prefer a fresh PR for this)? |
Description
balancer/grpclb/state: Implementsfmt.StringeronkeyType(func (k keyType) String() string { return string(k) }). This ensures that grpclb state attributes format cleanly as"grpc.grpclb.state"instead of falling back to<%!p(state.keyType=grpc.grpclb.state)>(due tostate.keyTypebeing a distinct named type that fails directx.(string)interface assertions).attributes: Adds documentation tostr()explaining why<%p>is used for pointer/arbitrary types and why%v/%#vmust be avoided to prevent unsynchronized field reads and data races on mutex-protected structs (as documented in attributes: avoid the use of %#v formatting verb #6664).Tests
TestStateAttributesStringinbalancer/grpclb/state/state_test.go.attributesandbalancer/grpclb/statepackages.