-
Notifications
You must be signed in to change notification settings - Fork 282
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
Issue #446 Adding peername to PinInfo #531
Conversation
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, there are just stray comments.
ipfs-cluster-ctl/main.go
Outdated
@@ -601,6 +601,7 @@ The filter only takes effect when listing all pins. The possible values are: | |||
}, | |||
}, | |||
{ | |||
// This could be one |
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.
@kishansagathiya Are these comments still required?
Examples of relevant command runs
@hsanjuan @lanzafame |
rpc_api.go
Outdated
@@ -134,6 +134,7 @@ func (rpcapi *RPCAPI) Status(ctx context.Context, in api.PinSerial, out *api.Glo | |||
func (rpcapi *RPCAPI) StatusLocal(ctx context.Context, in api.PinSerial, out *api.PinInfoSerial) error { | |||
c := in.ToPin().Cid | |||
pinfo := rpcapi.c.StatusLocal(c) | |||
pinfo.PeerName = rpcapi.c.config.Peername |
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 would get rid off this. It should work without this.
0c32b4f
to
115e42b
Compare
@lanzafame travis checks have passed, but somehow it still shows pending. |
@kishansagathiya I restarted the job on travis and this time round it |
Forgot to mention the addition of sharness test
Final thing, since this directly affects the output of the cli tool, it would be great to add a sharness test, see the |
@lanzafame Going through current sharness tests, I don't think proposed change would require us to modify or add to sharness tests. One more thing, earlier output was well formatted since the hash had a fixed size. I was thinking we should put some size limit to |
Good point. Nvm the sharness 👍
A naive approach would be to use a - fmt.Printf(" > Peer %s : %s", v.PeerName, strings.ToUpper(v.Status))
+ fmt.Printf(" > Peer %s\t: %s", v.PeerName, strings.ToUpper(v.Status)) The other option is to use the padding syntax of - fmt.Printf(" > Peer %s : %s", v.PeerName, strings.ToUpper(v.Status))
+ fmt.Printf(" > Peer %-10s: %s", v.PeerName, strings.ToUpper(v.Status)) The padding value, 10, is just an example, not sure what the ideal would be in terms of best looking output. I will leave the choice between to the two approaches up to you. For now, I would rather not limit the size of the string and just go with ugly output if someone use a really long peer name. |
There were the following issues with your Pull Request
Code contribution guidelines for IPFS Cluster are available at https://cluster.ipfs.io/developer/contribute/#code-contribution-guidelines This message was auto-generated by https://gitcop.com |
d0b1d51
to
18576ab
Compare
There were the following issues with your Pull Request
Code contribution guidelines for IPFS Cluster are available at https://cluster.ipfs.io/developer/contribute/#code-contribution-guidelines This message was auto-generated by https://gitcop.com |
18576ab
to
93a8301
Compare
@lanzafame One travis run is failing. I tried to replicate failure locally, but I couldn't. I think if we re-run travis check, it will pass. |
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 @kishansagathiya . This looks very good. Mostly cosmetic changes needed.
api/types.go
Outdated
Status TrackerStatus | ||
TS time.Time | ||
Error string | ||
PeerName 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.
Pedantic but could you move up PeerName
under Peer
?
api/types.go
Outdated
Status string `json:"status"` | ||
TS string `json:"timestamp"` | ||
Error string `json:"error"` | ||
PeerName string `json:"peername"` |
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.
Move up
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.
Here and in the other places below.
cluster.go
Outdated
Status: api.TrackerStatusClusterError, | ||
TS: time.Now(), | ||
Error: e.Error(), | ||
PeerName: c.config.Peername, |
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 think we should not set PeerName here. You are setting the local peer's name, but the PinInfo object may belong to any other peer.
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.
So maybe set it to members[i]
instead?
ipfs-cluster-ctl/formatters.go
Outdated
@@ -147,7 +147,7 @@ func textFormatPrintGPInfo(obj *api.GlobalPinInfoSerial) { | |||
|
|||
for _, k := range peers { | |||
v := obj.PeerMap[k] | |||
fmt.Printf(" > Peer %s : %s", k, strings.ToUpper(v.Status)) | |||
fmt.Printf(" > Peer %-10s : %s", v.PeerName, strings.ToUpper(v.Status)) |
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.
If v.PeerName
is set it should show the PeerName, otherwise it should show the peer ID. Depends on how comment above is resolved.
We can remove the Peer
part. I think it's understood and saves some space. We can increase padding to 15. I'd like to see an example of the output though.
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.
Sample output
[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl status
QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S :
> cluster2 : PINNED | 2018-09-24T17:20:56Z
> cluser1 : PINNED | 2018-09-24T17:20:56Z
Status: api.TrackerStatusUnpinned, | ||
TS: time.Now(), | ||
Error: "", | ||
PeerName: "", |
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 believe opt.peerName
is usable here?
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.
my bad! operation is nil and not opt!
This commit adds peername to PinInfo and GlobalPinInfo so that we have a nicer and more meaningfull output for queries like `ipfs-cluster-ctl status` License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
This commit adds peername to PinInfo and GlobalPinInfo so that we have a nicer and more meaningfull output for `ipfs-cluster-ctl` queries like `status`, `sync` and `recover` License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Removed comments and code used for debugging License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Removed unnecessary peername assignment Modified tests according to the changes made to add peername to PinInfo License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Formatted output License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
93a8301
to
0580fd5
Compare
Fixing errors and better code placement License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
0580fd5
to
2cd4420
Compare
cluster.go
Outdated
Error: e.Error(), | ||
Cid: h, | ||
Peer: members[i], | ||
PeerName: string(members[i]), |
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.
This should be members[i].String()
or members[i].Pretty()
(leaning towards the first) . Unfortunately casting a peer.ID to string directly is a bad thing to do (been there, done that).
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.
Makes sense. I was able to find a nice article explaining why.
https://stackoverflow.com/questions/4167304/why-should-casting-be-avoided
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.
Actually, the reason here is that a peer ID is internally a string
but that string is just holding a byte slice (a multihash actually) and the string representation we use for peer IDs is the B58 encoded version of that byte slice. https://godoc.org/github.com/libp2p/go-libp2p-peer#IDB58Encode . The reason why a Peer ID is a string
and not a []byte
probably comes to the slightly smaller footprint and immutability of strings (https://syslog.ravelin.com/byte-vs-string-in-go-d645b67ca7ff). In any case, the right way to get a string is to IDB58Encode it.
Avoid typecasting License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
really happy to have this |
This commit adds peername to PinInfo and GlobalPinInfo so that we have
a nicer and more meaningfull output for queries like
ipfs-cluster-ctl status
So far this is a naive attempt. Quite a few things remaining here to add and to change.
Fixes #446