Skip to content

Commit 17c3269

Browse files
committed
api/types: move ContainerStats to api/types/container
This is the response type; other types related to stats are left for now, but should be moved (as well as utilities ported from the CLI repository). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent fd1d8f3 commit 17c3269

6 files changed

Lines changed: 27 additions & 21 deletions

File tree

api/types/container/container.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package container
22

33
import (
4+
"io"
45
"os"
56
"time"
67
)
@@ -29,3 +30,10 @@ type CopyToContainerOptions struct {
2930
AllowOverwriteDirWithFile bool
3031
CopyUIDGID bool
3132
}
33+
34+
// StatsResponse contains response of Engine API:
35+
// GET "/stats"
36+
type StatsResponse struct {
37+
Body io.ReadCloser `json:"body"`
38+
OSType string `json:"ostype"`
39+
}

api/types/types.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package types // import "github.com/docker/docker/api/types"
22

33
import (
4-
"io"
54
"time"
65

76
"github.com/docker/docker/api/types/container"
@@ -161,13 +160,6 @@ type Container struct {
161160
Mounts []MountPoint
162161
}
163162

164-
// ContainerStats contains response of Engine API:
165-
// GET "/stats"
166-
type ContainerStats struct {
167-
Body io.ReadCloser `json:"body"`
168-
OSType string `json:"ostype"`
169-
}
170-
171163
// Ping contains response of Engine API:
172164
// GET "/_ping"
173165
type Ping struct {

api/types/types_deprecated.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ type ContainerPathStat = container.PathStat
9191
//
9292
// Deprecated: use [container.CopyToContainerOptions],
9393
type CopyToContainerOptions = container.CopyToContainerOptions
94+
95+
// ContainerStats contains response of Engine API:
96+
// GET "/stats"
97+
//
98+
// Deprecated: use [container.StatsResponse].
99+
type ContainerStats = container.StatsResponse

client/container_stats.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"context"
55
"net/url"
66

7-
"github.com/docker/docker/api/types"
7+
"github.com/docker/docker/api/types/container"
88
)
99

1010
// ContainerStats returns near realtime stats for a given container.
1111
// It's up to the caller to close the io.ReadCloser returned.
12-
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
12+
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponse, error) {
1313
query := url.Values{}
1414
query.Set("stream", "0")
1515
if stream {
@@ -18,28 +18,28 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea
1818

1919
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
2020
if err != nil {
21-
return types.ContainerStats{}, err
21+
return container.StatsResponse{}, err
2222
}
2323

24-
return types.ContainerStats{
24+
return container.StatsResponse{
2525
Body: resp.body,
2626
OSType: getDockerOS(resp.header.Get("Server")),
2727
}, nil
2828
}
2929

3030
// ContainerStatsOneShot gets a single stat entry from a container.
3131
// It differs from `ContainerStats` in that the API should not wait to prime the stats
32-
func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (types.ContainerStats, error) {
32+
func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (container.StatsResponse, error) {
3333
query := url.Values{}
3434
query.Set("stream", "0")
3535
query.Set("one-shot", "1")
3636

3737
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
3838
if err != nil {
39-
return types.ContainerStats{}, err
39+
return container.StatsResponse{}, err
4040
}
4141

42-
return types.ContainerStats{
42+
return container.StatsResponse{
4343
Body: resp.body,
4444
OSType: getDockerOS(resp.header.Get("Server")),
4545
}, nil

client/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ type ContainerAPIClient interface {
6767
ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error
6868
ContainerRestart(ctx context.Context, container string, options container.StopOptions) error
6969
ContainerStatPath(ctx context.Context, container, path string) (container.PathStat, error)
70-
ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
71-
ContainerStatsOneShot(ctx context.Context, container string) (types.ContainerStats, error)
70+
ContainerStats(ctx context.Context, container string, stream bool) (container.StatsResponse, error)
71+
ContainerStatsOneShot(ctx context.Context, container string) (container.StatsResponse, error)
7272
ContainerStart(ctx context.Context, container string, options container.StartOptions) error
7373
ContainerStop(ctx context.Context, container string, options container.StopOptions) error
7474
ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)

integration-cli/docker_api_containers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
151151
runSleepingContainer(c, "--name", name)
152152

153153
type b struct {
154-
stats types.ContainerStats
154+
stats container.StatsResponse
155155
err error
156156
}
157157

@@ -255,7 +255,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
255255
runSleepingContainer(c, "--name", name)
256256

257257
type b struct {
258-
stats types.ContainerStats
258+
stats container.StatsResponse
259259
err error
260260
}
261261

@@ -296,7 +296,7 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
296296
runSleepingContainer(c, "--name", name)
297297

298298
type b struct {
299-
stats types.ContainerStats
299+
stats container.StatsResponse
300300
err error
301301
}
302302

@@ -1417,7 +1417,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
14171417
cli.WaitRun(c, name)
14181418

14191419
type b struct {
1420-
stats types.ContainerStats
1420+
stats container.StatsResponse
14211421
err error
14221422
}
14231423
bc := make(chan b, 1)

0 commit comments

Comments
 (0)