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 <github@gone.nl>
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package container |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "io" |
|
| 4 | 5 |
"os" |
| 5 | 6 |
"time" |
| 6 | 7 |
) |
| ... | ... |
@@ -29,3 +30,10 @@ type CopyToContainerOptions struct {
|
| 29 | 29 |
AllowOverwriteDirWithFile bool |
| 30 | 30 |
CopyUIDGID bool |
| 31 | 31 |
} |
| 32 |
+ |
|
| 33 |
+// StatsResponse contains response of Engine API: |
|
| 34 |
+// GET "/stats" |
|
| 35 |
+type StatsResponse struct {
|
|
| 36 |
+ Body io.ReadCloser `json:"body"` |
|
| 37 |
+ OSType string `json:"ostype"` |
|
| 38 |
+} |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package types // import "github.com/docker/docker/api/types" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "io" |
|
| 5 | 4 |
"time" |
| 6 | 5 |
|
| 7 | 6 |
"github.com/docker/docker/api/types/container" |
| ... | ... |
@@ -161,13 +160,6 @@ type Container struct {
|
| 161 | 161 |
Mounts []MountPoint |
| 162 | 162 |
} |
| 163 | 163 |
|
| 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 |
- |
|
| 171 | 164 |
// Ping contains response of Engine API: |
| 172 | 165 |
// GET "/_ping" |
| 173 | 166 |
type Ping struct {
|
| ... | ... |
@@ -91,3 +91,9 @@ type ContainerPathStat = container.PathStat |
| 91 | 91 |
// |
| 92 | 92 |
// Deprecated: use [container.CopyToContainerOptions], |
| 93 | 93 |
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 |
| ... | ... |
@@ -4,12 +4,12 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"net/url" |
| 6 | 6 |
|
| 7 |
- "github.com/docker/docker/api/types" |
|
| 7 |
+ "github.com/docker/docker/api/types/container" |
|
| 8 | 8 |
) |
| 9 | 9 |
|
| 10 | 10 |
// ContainerStats returns near realtime stats for a given container. |
| 11 | 11 |
// 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) {
|
|
| 13 | 13 |
query := url.Values{}
|
| 14 | 14 |
query.Set("stream", "0")
|
| 15 | 15 |
if stream {
|
| ... | ... |
@@ -18,10 +18,10 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea |
| 18 | 18 |
|
| 19 | 19 |
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) |
| 20 | 20 |
if err != nil {
|
| 21 |
- return types.ContainerStats{}, err
|
|
| 21 |
+ return container.StatsResponse{}, err
|
|
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 |
- return types.ContainerStats{
|
|
| 24 |
+ return container.StatsResponse{
|
|
| 25 | 25 |
Body: resp.body, |
| 26 | 26 |
OSType: getDockerOS(resp.header.Get("Server")),
|
| 27 | 27 |
}, nil |
| ... | ... |
@@ -29,17 +29,17 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea |
| 29 | 29 |
|
| 30 | 30 |
// ContainerStatsOneShot gets a single stat entry from a container. |
| 31 | 31 |
// 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) {
|
|
| 33 | 33 |
query := url.Values{}
|
| 34 | 34 |
query.Set("stream", "0")
|
| 35 | 35 |
query.Set("one-shot", "1")
|
| 36 | 36 |
|
| 37 | 37 |
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) |
| 38 | 38 |
if err != nil {
|
| 39 |
- return types.ContainerStats{}, err
|
|
| 39 |
+ return container.StatsResponse{}, err
|
|
| 40 | 40 |
} |
| 41 | 41 |
|
| 42 |
- return types.ContainerStats{
|
|
| 42 |
+ return container.StatsResponse{
|
|
| 43 | 43 |
Body: resp.body, |
| 44 | 44 |
OSType: getDockerOS(resp.header.Get("Server")),
|
| 45 | 45 |
}, nil |
| ... | ... |
@@ -67,8 +67,8 @@ type ContainerAPIClient interface {
|
| 67 | 67 |
ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error |
| 68 | 68 |
ContainerRestart(ctx context.Context, container string, options container.StopOptions) error |
| 69 | 69 |
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) |
|
| 72 | 72 |
ContainerStart(ctx context.Context, container string, options container.StartOptions) error |
| 73 | 73 |
ContainerStop(ctx context.Context, container string, options container.StopOptions) error |
| 74 | 74 |
ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error) |
| ... | ... |
@@ -151,7 +151,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) {
|
| 151 | 151 |
runSleepingContainer(c, "--name", name) |
| 152 | 152 |
|
| 153 | 153 |
type b struct {
|
| 154 |
- stats types.ContainerStats |
|
| 154 |
+ stats container.StatsResponse |
|
| 155 | 155 |
err error |
| 156 | 156 |
} |
| 157 | 157 |
|
| ... | ... |
@@ -255,7 +255,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) {
|
| 255 | 255 |
runSleepingContainer(c, "--name", name) |
| 256 | 256 |
|
| 257 | 257 |
type b struct {
|
| 258 |
- stats types.ContainerStats |
|
| 258 |
+ stats container.StatsResponse |
|
| 259 | 259 |
err error |
| 260 | 260 |
} |
| 261 | 261 |
|
| ... | ... |
@@ -296,7 +296,7 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) {
|
| 296 | 296 |
runSleepingContainer(c, "--name", name) |
| 297 | 297 |
|
| 298 | 298 |
type b struct {
|
| 299 |
- stats types.ContainerStats |
|
| 299 |
+ stats container.StatsResponse |
|
| 300 | 300 |
err error |
| 301 | 301 |
} |
| 302 | 302 |
|
| ... | ... |
@@ -1417,7 +1417,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) |
| 1417 | 1417 |
cli.WaitRun(c, name) |
| 1418 | 1418 |
|
| 1419 | 1419 |
type b struct {
|
| 1420 |
- stats types.ContainerStats |
|
| 1420 |
+ stats container.StatsResponse |
|
| 1421 | 1421 |
err error |
| 1422 | 1422 |
} |
| 1423 | 1423 |
bc := make(chan b, 1) |