-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Print clusterID, memberID and leaseID in hexdecimal #14208
Conversation
@liggitt @dims @neolit123 do you have any concerns from K8s perspective? |
Codecov Report
@@ Coverage Diff @@
## main #14208 +/- ##
==========================================
- Coverage 75.49% 75.09% -0.41%
==========================================
Files 455 455
Lines 36859 36908 +49
==========================================
- Hits 27828 27715 -113
- Misses 7299 7441 +142
- Partials 1732 1752 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Given the discrepancy is exposed to the user on the CLI it might make sense to make it possible for them opt out with a flag for a transitional period until the the behavior is consistent accross the CLI commands. In terms of hex vs decimal for IDs - it depends. Decimal makes it easier to process / human parse IDs in e.g. scripts. |
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 agree it would be better to introduce this in more backward compatible way.
The fastest path I see:
- Introduce flag in 3.6 defaulting to 'hex'
- Backport the PR to 3.5, but change the flag there to
decimal
. In 3.5, when the flag is unset, there should be a warning about behavioral change in 3.6 - Remove the flag in 3.7 (or 4).
} | ||
|
||
func (p *fieldsPrinter) hdr(h *pb.ResponseHeader) { | ||
fmt.Println(`"ClusterID" :`, h.ClusterId) |
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.
Can we cast it to types.Id
to benefit from the common stringer implementation:
(
Lines 22 to 24 in 53bfdc1
type ID uint64 | |
func (i ID) String() string { |
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 @ptabor . It makes sense. But only memberID
and clusterID
are uint64, and LeaseID
is int64. So I only cast memberID
and clusterID
to types.ID
.
Storing this as typed integer saves a few bytes but caries risk of `signed vs. unsigned' mismatch and overflow. As we don't compare this values for inequality I think that hex are steering users towards safer code where they would script them as 'strings'. |
ClusterID, memberID and leaseID are just identifies, so it doesn't make sense to print them in decimal. Instead, we should always print them in hexdecimal. Signed-off-by: Benjamin Wang <wachao@vmware.com>
Thanks @neolit123 and @ptabor for the feedback, which basically makes sense to me. Actually I thought about backward compatible, the reason I did not do it was that there is no any change on JSON output which should be the most common case for programmatically parsing the output. But anyway, I updated this PR and leverage the existing flag
PTAL @ptabor @neolit123 @serathius @spzala thx |
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.
@ahrtr extending the current flag that's used for json seems good approach! I have tested it my env to verify. I think we should add Changelog and also how about adding a test? It's okay to add it in a separate PR if you want. Thanks!
Thanks @spzala for the review comment, which basically makes sense to me. Points from my side:
|
@ahrtr thank you, and both the points you mentioned sounds good to me. I will be happy to share work on adding unit test coverage. |
Thanks @spzala . Actually this PR should be a small and safe change because there is no any change on the JSON output so far, so let me merge it. |
ClusterID, memberID and leaseID are just identities, so it doesn't make sense to print them in decimal. Instead, we should always print them in hexadecimal.
Please note the existing behavior isn't consistent. Sometimes etcdctl prints them in hexdecimal (such as
etcdctl endpoint status -w table
), but sometimes in decimal (such asetctctl endpoint status -w fields
).Previous output
New output
Signed-off-by: Benjamin Wang wachao@vmware.com