Skip to content

Commit

Permalink
adding in online_cpus as of docker v17.05 stats update
Browse files Browse the repository at this point in the history
  • Loading branch information
sebito91 committed Jan 31, 2018
1 parent f21b764 commit 6e8e612
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
9 changes: 5 additions & 4 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
"time"

"github.com/docker/go-units"
units "github.com/docker/go-units"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -547,7 +547,7 @@ func (c *Client) InspectContainer(id string) (*Container, error) {
// The context object can be used to cancel the inspect request.
//
// See https://goo.gl/FaI5JT for more details.
func (c *Client) InspectContainerWithContext(id string, ctx context.Context) (*Container, error) {
func (c *Client) InspectContainerWithContext(ctx context.Context, id string) (*Container, error) {
return c.inspectContainer(id, doOptions{context: ctx})
}

Expand Down Expand Up @@ -817,7 +817,7 @@ func (c *Client) StartContainer(id string, hostConfig *HostConfig) error {
// API 1.24 or greater.
//
// See https://goo.gl/fbOSZy for more details.
func (c *Client) StartContainerWithContext(id string, hostConfig *HostConfig, ctx context.Context) error {
func (c *Client) StartContainerWithContext(ctx context.Context, id string, hostConfig *HostConfig) error {
return c.startContainer(id, hostConfig, doOptions{context: ctx})
}

Expand Down Expand Up @@ -857,7 +857,7 @@ func (c *Client) StopContainer(id string, timeout uint) error {
// container request.
//
// See https://goo.gl/R9dZcV for more details.
func (c *Client) StopContainerWithContext(id string, timeout uint, ctx context.Context) error {
func (c *Client) StopContainerWithContext(ctx context.Context, id string, timeout uint) error {
return c.stopContainer(id, timeout, doOptions{context: ctx})
}

Expand Down Expand Up @@ -1052,6 +1052,7 @@ type CPUStats struct {
UsageInKernelmode uint64 `json:"usage_in_kernelmode,omitempty" yaml:"usage_in_kernelmode,omitempty" toml:"usage_in_kernelmode,omitempty"`
} `json:"cpu_usage,omitempty" yaml:"cpu_usage,omitempty" toml:"cpu_usage,omitempty"`
SystemCPUUsage uint64 `json:"system_cpu_usage,omitempty" yaml:"system_cpu_usage,omitempty" toml:"system_cpu_usage,omitempty"`
OnlineCPUs uint64 `json:"online_cpus,omitempty" yaml:"online_cpus,omitempty" toml:"online_cpus,omitempty"`
ThrottlingData struct {
Periods uint64 `json:"periods,omitempty"`
ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`
Expand Down
22 changes: 13 additions & 9 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ func TestStartContainerWithContext(t *testing.T) {

startError := make(chan error)
go func() {
startError <- client.StartContainerWithContext(id, &HostConfig{}, ctx)
startError <- client.StartContainerWithContext(ctx, id, &HostConfig{})
}()
select {
case err := <-startError:
Expand Down Expand Up @@ -1154,7 +1154,7 @@ func TestStopContainerWithContext(t *testing.T) {

stopError := make(chan error)
go func() {
stopError <- client.StopContainerWithContext(id, 10, ctx)
stopError <- client.StopContainerWithContext(ctx, id, 10)
}()
select {
case err := <-stopError:
Expand Down Expand Up @@ -2473,7 +2473,8 @@ func TestStats(t *testing.T) {
"total_usage" : 36488948,
"usage_in_kernelmode" : 20000000
},
"system_cpu_usage" : 20091722000000000
"system_cpu_usage" : 20091722000000000,
"online_cpus": 4
},
"precpu_stats" : {
"cpu_usage" : {
Expand All @@ -2487,7 +2488,8 @@ func TestStats(t *testing.T) {
"total_usage" : 36488948,
"usage_in_kernelmode" : 20000000
},
"system_cpu_usage" : 20091722000000000
"system_cpu_usage" : 20091722000000000,
"online_cpus": 4
}
}`
// 1 second later, cache is 100
Expand Down Expand Up @@ -2591,7 +2593,8 @@ func TestStats(t *testing.T) {
"total_usage" : 36488948,
"usage_in_kernelmode" : 20000000
},
"system_cpu_usage" : 20091722000000000
"system_cpu_usage" : 20091722000000000,
"online_cpus": 4
},
"precpu_stats" : {
"cpu_usage" : {
Expand All @@ -2605,7 +2608,8 @@ func TestStats(t *testing.T) {
"total_usage" : 36488948,
"usage_in_kernelmode" : 20000000
},
"system_cpu_usage" : 20091722000000000
"system_cpu_usage" : 20091722000000000,
"online_cpus": 4
}
}`
var expected1 Stats
Expand Down Expand Up @@ -2725,7 +2729,7 @@ func TestInspectContainerWhenContextTimesOut(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
defer cancel()

_, err := client.InspectContainerWithContext("id", ctx)
_, err := client.InspectContainerWithContext(ctx, "id")
if err != context.DeadlineExceeded {
t.Errorf("Expected 'DeadlineExceededError', got: %v", err)
}
Expand All @@ -2740,7 +2744,7 @@ func TestStartContainerWhenContextTimesOut(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
defer cancel()

err := client.StartContainerWithContext("id", nil, ctx)
err := client.StartContainerWithContext(ctx, "id", nil)
if err != context.DeadlineExceeded {
t.Errorf("Expected 'DeadlineExceededError', got: %v", err)
}
Expand All @@ -2755,7 +2759,7 @@ func TestStopContainerWhenContextTimesOut(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 50*time.Millisecond)
defer cancel()

err := client.StopContainerWithContext("id", 10, ctx)
err := client.StopContainerWithContext(ctx, "id", 10)
if err != context.DeadlineExceeded {
t.Errorf("Expected 'DeadlineExceededError', got: %v", err)
}
Expand Down

0 comments on commit 6e8e612

Please sign in to comment.