-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
peer and metadata: Implement the Stringer interface for Peer and Metadata #7137
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>
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 change overall looks good to me. I took a pass at it. please take a look
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 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>
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, go test
std library already does something similar by replacing \s
s with _
s.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
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 |
@@ -90,6 +90,21 @@ func Pairs(kv ...string) MD { | |||
return md | |||
} | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Peer
properly.Instead of printing with
%v
as:contexts containing a peer will now print as:
This is also satisfying Stringer interface for
Metadata
, allowing to print them easily too. SinceMetadata
are basically a map, notice thatString
output is not stable. I could change it to print it in alphabetical order if you prefer.RELEASE NOTES: