-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
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>
3ad0cbd
to
e0e3202
Compare
Had to fix some golints from locker PR in order for tests to pass and ended up un-exporting the Locker thing. |
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.
A few minor questions, but mostly looks good.
} | ||
urlPrefix += host | ||
|
||
if lvl := cfg.LogLevel; lvl != "" { |
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.
Should we have a default level in the case lvl == ""
?
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.
yeah, addressed.
api/rest/client/client_test.go
Outdated
t.Fatal("should be able to create a new Api: ", err) | ||
} | ||
|
||
// No keep alive! Otherwise tests hang with |
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.
Is this comment still valid? If not maybe we can remove it. If so, shouldn't we still disable keepalives?
api/rest/client/client_test.go
Outdated
defer api.Shutdown() | ||
c, _ = NewClient(&Config{}) | ||
ids, err := c.Peers() | ||
if err == nil { |
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.
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>
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, 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>
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>
Glad that sharness helped catch a couple of issues :) |
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
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