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

Issue #446 Adding peername to PinInfo #531

Merged
merged 7 commits into from
Sep 26, 2018

Conversation

kishansagathiya
Copy link
Contributor

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

@ghost ghost assigned kishansagathiya Sep 8, 2018
@ghost ghost added the status/in-progress In progress label Sep 8, 2018
@coveralls
Copy link

coveralls commented Sep 8, 2018

Coverage Status

Coverage increased (+0.03%) to 65.172% when pulling c62c922 on kishansagathiya:issue_446 into 275a8b2 on ipfs:master.

Copy link
Contributor

@lanzafame lanzafame left a 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.

@@ -601,6 +601,7 @@ The filter only takes effect when listing all pins. The possible values are:
},
},
{
// This could be one
Copy link
Contributor

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?

@kishansagathiya
Copy link
Contributor Author

kishansagathiya commented Sep 12, 2018

Examples of relevant command runs

[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl status
QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S :
    > Peer cluster2 : PINNED | 2018-09-12T04:18:52Z
    > Peer cluser1 : PINNED | 2018-09-12T04:18:52Z
[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl status QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S
QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S :
    > Peer cluster2 : PINNED | 2018-09-12T04:18:52Z
    > Peer cluser1 : PINNED | 2018-09-12T04:18:52Z
[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl sync
[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl sync QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S
QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S :
    > Peer cluster2 : PINNED | 2018-09-12T04:18:52Z
    > Peer cluser1 : PINNED | 2018-09-12T04:18:52Z
[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl recover
An error occurred:
  Code: 400
  Message: only requests with parameter local=true are supported
[kishansagathiya@localhost ipfs-cluster]$ ipfs-cluster-ctl recover QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S
QmU6PQs58j4UieXg8qte9qdvckmts7sWiVkeHov86ZVW1S :
    > Peer cluster2 : PINNED | 2018-09-12T04:18:52Z
    > Peer cluser1 : PINNED | 2018-09-12T04:18:52Z
[kishansagathiya@localhost ipfs-cluster]$ git log

@hsanjuan @lanzafame
May be the output could be formatted for pipes to align with each other. Yet to write tests for this, but feel free to review so far.

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
Copy link
Contributor Author

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.

@kishansagathiya
Copy link
Contributor Author

kishansagathiya commented Sep 12, 2018

@lanzafame travis checks have passed, but somehow it still shows pending.

@kishansagathiya kishansagathiya added need/review Needs a review and removed status/in-progress In progress labels Sep 12, 2018
@lanzafame
Copy link
Contributor

lanzafame commented Sep 13, 2018

@kishansagathiya I restarted the job on travis and this time round it failed timed out. Not sure why it didn't move out of pending.

lanzafame
lanzafame previously approved these changes Sep 13, 2018
@lanzafame lanzafame dismissed their stale review September 13, 2018 02:01

Forgot to mention the addition of sharness test

@lanzafame
Copy link
Contributor

Final thing, since this directly affects the output of the cli tool, it would be great to add a sharness test, see the sharness directory. Have a look around the different test files for examples of testing the output of a command and the actual test would go in t0025-ctl-status-report-commands.sh. Thanks

@kishansagathiya
Copy link
Contributor Author

kishansagathiya commented Sep 15, 2018

@lanzafame Going through current sharness tests, I don't think proposed change would require us to modify or add to sharness tests.
Because the proposed change does not really change the output, but it makes it meaningful. But I wonder what can be added to these(sharness) tests regardless of this change.

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 peerName so that we can keep this output also well formatted.

@lanzafame
Copy link
Contributor

Because the proposed change does not really change the output, but it makes it meaningful. But I wonder what can be added to these(sharness) tests regardless of this change.

Good point. Nvm the sharness 👍

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 peerName so that we can keep this output also well formatted.

A naive approach would be to use a \t (tab) character between the peerName and the : in the formatting string, i.e.

- 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:

- 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.

@GitCop
Copy link

GitCop commented Sep 18, 2018

There were the following issues with your Pull Request

  • Commit: d0b1d51
  • Invalid signoff. Commit message must end with
    License: MIT
    Signed-off-by:

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

@GitCop
Copy link

GitCop commented Sep 18, 2018

There were the following issues with your Pull Request

  • Commit: 18576ab
  • Invalid signoff. Commit message must end with
    License: MIT
    Signed-off-by:

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

@kishansagathiya
Copy link
Contributor Author

@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.

@lanzafame lanzafame added RFM Ready for Merge and removed status/in-progress In progress need/review Needs a review labels Sep 18, 2018
Copy link
Collaborator

@hsanjuan hsanjuan left a 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
Copy link
Collaborator

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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move up

Copy link
Collaborator

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,
Copy link
Collaborator

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.

Copy link
Collaborator

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?

@@ -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))
Copy link
Collaborator

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.

Copy link
Contributor Author

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: "",
Copy link
Collaborator

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?

Copy link
Contributor Author

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!

@lanzafame lanzafame removed the RFM Ready for Merge label Sep 19, 2018
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>
Fixing errors and better code placement

License: MIT
Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
cluster.go Outdated
Error: e.Error(),
Cid: h,
Peer: members[i],
PeerName: string(members[i]),
Copy link
Collaborator

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).

Copy link
Contributor Author

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

Copy link
Collaborator

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>
@hsanjuan hsanjuan merged commit e941d6b into ipfs-cluster:master Sep 26, 2018
@ghost ghost removed the status/in-progress In progress label Sep 26, 2018
@hsanjuan
Copy link
Collaborator

really happy to have this

@hsanjuan hsanjuan mentioned this pull request Sep 26, 2018
@kishansagathiya kishansagathiya deleted the issue_446 branch November 6, 2019 15:38
@kishansagathiya kishansagathiya restored the issue_446 branch November 6, 2019 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants