Skip to content

Commit 6e8e612

Browse files
committed
adding in online_cpus as of docker v17.05 stats update
1 parent f21b764 commit 6e8e612

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

container.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"strings"
1616
"time"
1717

18-
"github.com/docker/go-units"
18+
units "github.com/docker/go-units"
1919
"golang.org/x/net/context"
2020
)
2121

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

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

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

@@ -1052,6 +1052,7 @@ type CPUStats struct {
10521052
UsageInKernelmode uint64 `json:"usage_in_kernelmode,omitempty" yaml:"usage_in_kernelmode,omitempty" toml:"usage_in_kernelmode,omitempty"`
10531053
} `json:"cpu_usage,omitempty" yaml:"cpu_usage,omitempty" toml:"cpu_usage,omitempty"`
10541054
SystemCPUUsage uint64 `json:"system_cpu_usage,omitempty" yaml:"system_cpu_usage,omitempty" toml:"system_cpu_usage,omitempty"`
1055+
OnlineCPUs uint64 `json:"online_cpus,omitempty" yaml:"online_cpus,omitempty" toml:"online_cpus,omitempty"`
10551056
ThrottlingData struct {
10561057
Periods uint64 `json:"periods,omitempty"`
10571058
ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`

container_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ func TestStartContainerWithContext(t *testing.T) {
10791079

10801080
startError := make(chan error)
10811081
go func() {
1082-
startError <- client.StartContainerWithContext(id, &HostConfig{}, ctx)
1082+
startError <- client.StartContainerWithContext(ctx, id, &HostConfig{})
10831083
}()
10841084
select {
10851085
case err := <-startError:
@@ -1154,7 +1154,7 @@ func TestStopContainerWithContext(t *testing.T) {
11541154

11551155
stopError := make(chan error)
11561156
go func() {
1157-
stopError <- client.StopContainerWithContext(id, 10, ctx)
1157+
stopError <- client.StopContainerWithContext(ctx, id, 10)
11581158
}()
11591159
select {
11601160
case err := <-stopError:
@@ -2473,7 +2473,8 @@ func TestStats(t *testing.T) {
24732473
"total_usage" : 36488948,
24742474
"usage_in_kernelmode" : 20000000
24752475
},
2476-
"system_cpu_usage" : 20091722000000000
2476+
"system_cpu_usage" : 20091722000000000,
2477+
"online_cpus": 4
24772478
},
24782479
"precpu_stats" : {
24792480
"cpu_usage" : {
@@ -2487,7 +2488,8 @@ func TestStats(t *testing.T) {
24872488
"total_usage" : 36488948,
24882489
"usage_in_kernelmode" : 20000000
24892490
},
2490-
"system_cpu_usage" : 20091722000000000
2491+
"system_cpu_usage" : 20091722000000000,
2492+
"online_cpus": 4
24912493
}
24922494
}`
24932495
// 1 second later, cache is 100
@@ -2591,7 +2593,8 @@ func TestStats(t *testing.T) {
25912593
"total_usage" : 36488948,
25922594
"usage_in_kernelmode" : 20000000
25932595
},
2594-
"system_cpu_usage" : 20091722000000000
2596+
"system_cpu_usage" : 20091722000000000,
2597+
"online_cpus": 4
25952598
},
25962599
"precpu_stats" : {
25972600
"cpu_usage" : {
@@ -2605,7 +2608,8 @@ func TestStats(t *testing.T) {
26052608
"total_usage" : 36488948,
26062609
"usage_in_kernelmode" : 20000000
26072610
},
2608-
"system_cpu_usage" : 20091722000000000
2611+
"system_cpu_usage" : 20091722000000000,
2612+
"online_cpus": 4
26092613
}
26102614
}`
26112615
var expected1 Stats
@@ -2725,7 +2729,7 @@ func TestInspectContainerWhenContextTimesOut(t *testing.T) {
27252729
ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
27262730
defer cancel()
27272731

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

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

2758-
err := client.StopContainerWithContext("id", 10, ctx)
2762+
err := client.StopContainerWithContext(ctx, "id", 10)
27592763
if err != context.DeadlineExceeded {
27602764
t.Errorf("Expected 'DeadlineExceededError', got: %v", err)
27612765
}

0 commit comments

Comments
 (0)