Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #260: Add REST API client and use it in ipfs-cluster-ctl #263

Merged
merged 7 commits into from
Dec 7, 2017

Conversation

hsanjuan
Copy link
Collaborator

@hsanjuan hsanjuan commented Dec 6, 2017

This adds the pakage api/rest/client which implements a go-client
for the REST API component. It also update the ipfs-cluster-ctl
tool to rely on it.

Originally, I wanted this to live it in it's own separate repository,
but the api client uses /api/types.go, which is part of cluster.

Therefore it would need to import all of cluster as a dependency.
ipfs-cluster-ctl would also need to import go-ipfs-cluster-api-client
as a dependency, creating circular gx deps which would be a mess to
maintain.

Only the splitting of cluster in multiple repositories (at least for
api, rest, ipfs-cluster-ctl, rest/client and test) would allow better
dependency management by allowing rest/client and the ctl tool
to only import what is needed, but this is something which brings
maintenance costs and can probably wait a bit until cluster is more stable.

License: MIT
Signed-off-by: Hector Sanjuan code@hector.link

@hsanjuan hsanjuan self-assigned this Dec 6, 2017
@hsanjuan hsanjuan requested a review from ZenGround0 December 6, 2017 12:38
@ghost ghost added the status/in-progress In progress label Dec 6, 2017
@hsanjuan hsanjuan mentioned this pull request Dec 6, 2017
This adds the pakage api/rest/client which implements a go-client
for the REST API component. It also update the ipfs-cluster-ctl
tool to rely on it.

Originally, I wanted this to live it in it's own separate repository,
but the api client uses /api/types.go, which is part of cluster.

Therefore it would need to import all of cluster as a dependency.
ipfs-cluster-ctl would also need to import go-ipfs-cluster-api-client
as a dependency, creating circular gx deps which would be a mess to
maintain.

Only the splitting of cluster in multiple repositories (at least for
api, rest, ipfs-cluster-ctl, rest/client and test) would allow better
dependency management by allowing rest/client and the ctl tool
to only import what is needed, but this is something which brings
maintenance costs and can probably wait a bit until cluster is more stable.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
@hsanjuan hsanjuan force-pushed the feat/260-api-client branch from 3ad0cbd to e0e3202 Compare December 6, 2017 19:13
@hsanjuan
Copy link
Collaborator Author

hsanjuan commented Dec 6, 2017

Had to fix some golints from locker PR in order for tests to pass and ended up un-exporting the Locker thing.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 72.686% when pulling e0e3202 on feat/260-api-client into bde7b4e on master.

Copy link
Collaborator

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

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

A few minor questions, but mostly looks good.

}
urlPrefix += host

if lvl := cfg.LogLevel; lvl != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have a default level in the case lvl == ""?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, addressed.

t.Fatal("should be able to create a new Api: ", err)
}

// No keep alive! Otherwise tests hang with
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this comment still valid? If not maybe we can remove it. If so, shouldn't we still disable keepalives?

defer api.Shutdown()
c, _ = NewClient(&Config{})
ids, err := c.Peers()
if err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Am I correct that this will not error if the machine running tests is also running ipfs-cluster-service on the default listening address? If so, is it ok for us to assume that cluster is not running externally in the tests?

* Set default logging facility
* Remove old keep-alive comment in tests
* Use a port for TestPeersWithErrors which is not default

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
ZenGround0
ZenGround0 previously approved these changes Dec 7, 2017
Copy link
Collaborator

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

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

LGTM, apart from the sharness failures

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
This allows taking advantage of connection keep alive by having the
api client re-use the same connection. Additionally, an option
to close connections after every request is provided.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 72.903% when pulling 7b9ef11 on feat/260-api-client into bde7b4e on master.

As before, exit status 1 means a client application error and
exit status 2 means a server-returned error.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 72.813% when pulling 0c469b8 on feat/260-api-client into bde7b4e on master.

@hsanjuan
Copy link
Collaborator Author

hsanjuan commented Dec 7, 2017

Glad that sharness helped catch a couple of issues :)

Copy link
Collaborator

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

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

LGTM

@hsanjuan hsanjuan merged commit 34c815b into master Dec 7, 2017
@ghost ghost removed the status/in-progress In progress label Dec 7, 2017
@hsanjuan hsanjuan deleted the feat/260-api-client branch December 7, 2017 16:09
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants