add docker stats (new in docker1.5)#71
Conversation
|
ping @vieux @aluzzardi please take a look when you get a moment |
There was a problem hiding this comment.
You should remove these debug prints first...
There was a problem hiding this comment.
good point 👍
On Mon, Feb 2, 2015 at 17:59 Brian Bland notifications@github.com wrote:
In dockerclient.go
#71 (comment):
for {go func() {defer func() {recover() // ugly but necessary for sending on closed chan}()var containerStats stats.Statsif err := decoder.Decode(&containerStats); err != nil {internalErrorChan <- errreturn}internalStatsChan <- containerStats}()
select {case containerStats := <-internalStatsChan:fmt.Printf("first\n")You should remove these debug prints first...
—
Reply to this email directly or view it on GitHub
https://github.com/samalba/dockerclient/pull/71/files#r23977267.
388f1a6 to
af77c7c
Compare
There was a problem hiding this comment.
No way, we should never import docker packages directly.
The main purpose of starting this library was to be entirely client side (everything over HTTP, no docker internal import). This can break the library anytime.
|
Does the docker remote API have support for stats yet? If yes, then we should leverage it. If not, the library cannot support it and this PR should be rejected. |
|
@samalba I am using the docker remote API. I'm only importing docker/api/stats for the stats.Stats type, which is the type that the remote API encodes. This type should be relatively stable, considering https://github.com/docker/docker/blob/master/daemon/stats.go#L36, but I can redeclare this struct if you prefer that |
|
@donhcd Got it. So you should redeclare the types you need over there: https://github.com/samalba/dockerclient/blob/master/types.go |
|
okay, will do |
|
redeclared the types, but there's actually a race in the test right now, which I'm working on resolving |
|
fixed the race, ready for review now. I'm running the tests 1000 times just in case any other races pop up, but I haven't seen any problems yet. ping @samalba |
|
|
|
@aluzzardi updated. I'm a little confused what mockclient is used for... is it used somewhere? |
|
@donhcd It's for library clients to use in order to mock dockerclient (as in, to fake dockerclient responses in unit tests). Here's an example on how we use this on Swarm: |
|
ah, I see. thanks for the link :) |
|
ping @aluzzardi @vieux |
|
@samalba are you ok with the current format ? |
|
@vieux Looks ok to me, what do you think? |
|
same, please @crosbymichael can you take a look, you are the most familiar with the stats endpoint. |
always require sending on closeChan, even if an error was sent.
the reader only needs to close closeChan when they are done
|
ping @crosbymichael |
Conflicts: dockerclient.go dockerclient_test.go example_responses.go types.go
Conflicts: dockerclient.go dockerclient_test.go example_responses.go interface.go mockclient/mock.go types.go
8e9eccd to
04885d9
Compare
Conflicts: interface.go mockclient/mock.go
There was a problem hiding this comment.
Unfortunately stats don't get added until API 1.17, so you'll have to bump APIVersion. I don't know what the delta between 1.15 and 1.17 is though and if we'd be missing anything here.
There was a problem hiding this comment.
the general approach of this repo so far has just been to keep the API version the same despite adding API calls that rely on newer API versions (e.g. ListNetworks). Given that (1) we don't have a testing framework to actually test all of the dockerclient methods on docker engines of all versions and (2) it's not uncommon for API changes to be breaking and undocumented, switching the APIVersion has high risk and low reward :/
If we were to switch the APIVersion, it should probably be in a separate PR.
There was a problem hiding this comment.
Def. agree we should do it in a separate PR. For that change we should just tag the repo at 1.5 and move on. If someone wants the older version, they can pull the tag. How about a compromise for this PR until we get the library in better shape by just commenting it (and maybe ListNetworks too) so we don't forget.
The flip side of this is it looks really weird in the UCP (and presumably DTR) logs that says the API version is 1.15.
|
The only thing that really concerns me is we should bump the APIVersion up, but I don't know what's missing in here vs. 1.17. Otherwise, LGTM. |
|
@pdevine I just added a comment to the |
|
LGTM. |
add docker stats (new in docker1.5)
I'm very open to suggestions on a better interface for stats, or better ways to write this