peer and metadata: Implement the Stringer interface for Peer and Metadata#7137
peer and metadata: Implement the Stringer interface for Peer and Metadata#7137zasweq merged 9 commits intogrpc:masterfrom AnomalRoil:master
Conversation
Effectively allowing to print context containing Peers properly Also enabling logging of Metadata in an easier way RELEASE NOTES: - peer/peer: implement the Stringer interface for pretty-printing Peers - metadata/metadata: implement the Stringer interface for pretty printing metadata Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
…fication of which SubConn is used Protect access to curAddr with ac.mutex Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
…n identification of which SubConn is used" This reverts commit 001f394. Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
arvindbr8
left a comment
There was a problem hiding this comment.
The change overall looks good to me. I took a pass at it. please take a look
arvindbr8
left a comment
There was a problem hiding this comment.
The change overall looks good to me. I took a pass at it. please take a look
Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
arvindbr8
left a comment
There was a problem hiding this comment.
Thanks, I've responded to our conversations here. Please take a look
Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
| want string | ||
| }{ | ||
| { | ||
| name: "+Addr-LocalAddr+ValidAuth", |
There was a problem hiding this comment.
Just FYI, go test std library already does something similar by replacing \ss with _s.
There was a problem hiding this comment.
I was trying to convey information about whether the test case included + or didn't include - that specific field.
There was a problem hiding this comment.
The use of + and - to convey the presence or absence of certain fields within the Peer isn't very readable. How about the following:
- withAddrAndValidAuth
- withAddrLocalAddrAndValidAuth
- withAddrAndEmptyAuth
- withAddrLocalAddrAndEmptyAuth
- nilPeer
The above names in the test output are more readable I feel.
|
Per policy we need one more review before we can check this in. I will ping a co-maintainer to take a look at this. |
zasweq
left a comment
There was a problem hiding this comment.
LGTM. Thank you for the contribution.
|
Making |
|
@serathius @zasweq the following patch to make the string deterministic solves our issue: |
|
Context why deterministic Etcd uses grpc metadata to change properties of the bi-directional watch stream. Example of that is |
| } | ||
|
|
||
| // String implements the Stringer interface for pretty-printing a MD. | ||
| // Ordering of the values is non-deterministic as it ranges over a map. |
There was a problem hiding this comment.
What do you think about sorting the keys before generating the string representation and ensuring that the output is deterministic. This will also make the unit test much simpler than what it is currently.
| var sb strings.Builder | ||
| fmt.Fprintf(&sb, "MD{") | ||
| for k, v := range md { | ||
| if sb.Len() > 3 { |
There was a problem hiding this comment.
How about defining a bool first and using that as the conditional here, instead of this magic check which took me sometime to understand.
| want string | ||
| }{ | ||
| { | ||
| name: "+Addr-LocalAddr+ValidAuth", |
There was a problem hiding this comment.
The use of + and - to convey the presence or absence of certain fields within the Peer isn't very readable. How about the following:
- withAddrAndValidAuth
- withAddrLocalAddrAndValidAuth
- withAddrAndEmptyAuth
- withAddrLocalAddrAndEmptyAuth
- nilPeer
The above names in the test output are more readable I feel.
|
Phew.... Didn't realize that the PR was already approved and merged. |
Effectively allowing to print contextes containing a
Peerproperly.Instead of printing with
%vas:contexts containing a peer will now print as:
This is also satisfying Stringer interface for
Metadata, allowing to print them easily too. SinceMetadataare basically a map, notice thatStringoutput is not stable. I could change it to print it in alphabetical order if you prefer.RELEASE NOTES: