Skip to content
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

etcdctl member list should return member IDs in a consistent format #9535

Closed
omkensey opened this issue Apr 5, 2018 · 4 comments
Closed

Comments

@omkensey
Copy link

omkensey commented Apr 5, 2018

When I run etcdctl member list, i get the member ID back as a hex string. However, when I run etcdctl member list -w json, I get the member IDs as decimal strings. This is especially unfortunate when using jq to parse the output as jq mangles anything that looks like a large integer to a double-size int, meaning that the etcd member ID breaks (and this has been raised with the jq team and they insist the behavior of jq is allowed, see for example jqlang/jq#369).

Using --hex=true or --hex=false seems to have no effect on the etcdctl output.

etcdctl should return the member ID in a consistent number format regardless of the output format. Ideally it should always default to hex strings since that gets around the jq number-parsing issue.

@omkensey
Copy link
Author

omkensey commented Apr 6, 2018

Also, the member ID probably should be quoted as a string rather than left bare as a number, even if in decimal form.

@gyuho
Copy link
Contributor

gyuho commented Apr 6, 2018

Member ID is defined as uint64 in proto, and etcdctl printer just outputs marshalled JSON value of any struct, so this won't be changed for sake of backward compatibilities. Doesn't etcdctl member list (just simple printer) work for you?

@omkensey
Copy link
Author

omkensey commented Apr 6, 2018

We can get the member ID from the text listing, but we have to treat it as unstructured data (apart from comma-separation) rather than having a nice solid jq pipeline for it. Other JSON parsers exist but jq is pretty universal so we'd like to be able to use it for this too instead of using a different tool just for this one thing. It also makes things harder in this specific instance because what we're doing is parsing out the member ID based on the endpoint URL using jq, and then using that member ID to operate on the peer in question. If the member ID gets mangled by jq then we can't do that in one step like we could otherwise.

Just to throw out some ideas:

  • Can --hex be made to work here?
  • Maybe a new CLI flag like --ids-as-strings can be introduced for JSON output to trigger id-quoting behavior?
  • Can "short ID" support be added to etcd (with a flag like --short-ids to enable the behavior), like what Docker allows with container IDs or git allows with commit hashes? Numbers less than 2^53 won't be mangled by jq, so if the ID can be output and input as a number less than that value then it'll work fine.

@gyuho
Copy link
Contributor

gyuho commented Sep 15, 2018

Moving discussion to #9975.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants