From f67e6555bfe7e42090cd3cf6cc32a2bed2c2d050 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Jul 2025 11:11:11 +0200 Subject: [PATCH] api/types/container.StatsResponseReader: move to client This type was only used in the client, and needs a rewrite; let's move it to the client first. Signed-off-by: Sebastiaan van Stijn --- api/types/container/container.go | 13 -------- client/client_interfaces.go | 4 +-- client/container_stats.go | 31 +++++++++++++------ integration-cli/docker_api_containers_test.go | 8 ++--- .../moby/api/types/container/container.go | 13 -------- .../moby/moby/client/client_interfaces.go | 4 +-- .../moby/moby/client/container_stats.go | 31 +++++++++++++------ 7 files changed, 50 insertions(+), 54 deletions(-) diff --git a/api/types/container/container.go b/api/types/container/container.go index ba735a9f1f..56e5ac4736 100644 --- a/api/types/container/container.go +++ b/api/types/container/container.go @@ -1,7 +1,6 @@ package container import ( - "io" "os" "time" @@ -35,18 +34,6 @@ type CopyToContainerOptions struct { CopyUIDGID bool } -// StatsResponseReader wraps an io.ReadCloser to read (a stream of) stats -// for a container, as produced by the GET "/stats" endpoint. -// -// The OSType field is set to the server's platform to allow -// platform-specific handling of the response. -// -// TODO(thaJeztah): remove this wrapper, and make OSType part of [StatsResponse]. -type StatsResponseReader struct { - Body io.ReadCloser `json:"body"` - OSType string `json:"ostype"` -} - // MountPoint represents a mount point configuration inside the container. // This is used for reporting the mountpoints in use by a container. type MountPoint struct { diff --git a/client/client_interfaces.go b/client/client_interfaces.go index fc93690813..cd0e983c5d 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -85,8 +85,8 @@ type ContainerAPIClient interface { ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error ContainerRestart(ctx context.Context, container string, options container.StopOptions) error ContainerStatPath(ctx context.Context, container, path string) (container.PathStat, error) - ContainerStats(ctx context.Context, container string, stream bool) (container.StatsResponseReader, error) - ContainerStatsOneShot(ctx context.Context, container string) (container.StatsResponseReader, error) + ContainerStats(ctx context.Context, container string, stream bool) (StatsResponseReader, error) + ContainerStatsOneShot(ctx context.Context, container string) (StatsResponseReader, error) ContainerStart(ctx context.Context, container string, options container.StartOptions) error ContainerStop(ctx context.Context, container string, options container.StopOptions) error ContainerTop(ctx context.Context, container string, arguments []string) (container.TopResponse, error) diff --git a/client/container_stats.go b/client/container_stats.go index f701a693c6..e3cca04c89 100644 --- a/client/container_stats.go +++ b/client/container_stats.go @@ -2,17 +2,28 @@ package client import ( "context" + "io" "net/url" - - "github.com/moby/moby/api/types/container" ) +// StatsResponseReader wraps an io.ReadCloser to read (a stream of) stats +// for a container, as produced by the GET "/stats" endpoint. +// +// The OSType field is set to the server's platform to allow +// platform-specific handling of the response. +// +// TODO(thaJeztah): remove this wrapper, and make OSType part of [github.com/moby/moby/api/types/container.StatsResponse]. +type StatsResponseReader struct { + Body io.ReadCloser `json:"body"` + OSType string `json:"ostype"` +} + // ContainerStats returns near realtime stats for a given container. // It's up to the caller to close the io.ReadCloser returned. -func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error) { +func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (StatsResponseReader, error) { containerID, err := trimID("container", containerID) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } query := url.Values{} @@ -23,10 +34,10 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } - return container.StatsResponseReader{ + return StatsResponseReader{ Body: resp.Body, OSType: resp.Header.Get("Ostype"), }, nil @@ -34,10 +45,10 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea // ContainerStatsOneShot gets a single stat entry from a container. // It differs from `ContainerStats` in that the API should not wait to prime the stats -func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (container.StatsResponseReader, error) { +func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (StatsResponseReader, error) { containerID, err := trimID("container", containerID) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } query := url.Values{} @@ -46,10 +57,10 @@ func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } - return container.StatsResponseReader{ + return StatsResponseReader{ Body: resp.Body, OSType: resp.Header.Get("Ostype"), }, nil diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index effa807206..95b48ff681 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -151,7 +151,7 @@ func (s *DockerAPISuite) TestGetContainerStats(c *testing.T) { runSleepingContainer(c, "--name", name) type b struct { - stats container.StatsResponseReader + stats client.StatsResponseReader err error } @@ -255,7 +255,7 @@ func (s *DockerAPISuite) TestGetContainerStatsStream(c *testing.T) { runSleepingContainer(c, "--name", name) type b struct { - stats container.StatsResponseReader + stats client.StatsResponseReader err error } @@ -296,7 +296,7 @@ func (s *DockerAPISuite) TestGetContainerStatsNoStream(c *testing.T) { runSleepingContainer(c, "--name", name) type b struct { - stats container.StatsResponseReader + stats client.StatsResponseReader err error } @@ -1332,7 +1332,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) cli.WaitRun(c, name) type b struct { - stats container.StatsResponseReader + stats client.StatsResponseReader err error } bc := make(chan b, 1) diff --git a/vendor/github.com/moby/moby/api/types/container/container.go b/vendor/github.com/moby/moby/api/types/container/container.go index ba735a9f1f..56e5ac4736 100644 --- a/vendor/github.com/moby/moby/api/types/container/container.go +++ b/vendor/github.com/moby/moby/api/types/container/container.go @@ -1,7 +1,6 @@ package container import ( - "io" "os" "time" @@ -35,18 +34,6 @@ type CopyToContainerOptions struct { CopyUIDGID bool } -// StatsResponseReader wraps an io.ReadCloser to read (a stream of) stats -// for a container, as produced by the GET "/stats" endpoint. -// -// The OSType field is set to the server's platform to allow -// platform-specific handling of the response. -// -// TODO(thaJeztah): remove this wrapper, and make OSType part of [StatsResponse]. -type StatsResponseReader struct { - Body io.ReadCloser `json:"body"` - OSType string `json:"ostype"` -} - // MountPoint represents a mount point configuration inside the container. // This is used for reporting the mountpoints in use by a container. type MountPoint struct { diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index fc93690813..cd0e983c5d 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -85,8 +85,8 @@ type ContainerAPIClient interface { ContainerResize(ctx context.Context, container string, options container.ResizeOptions) error ContainerRestart(ctx context.Context, container string, options container.StopOptions) error ContainerStatPath(ctx context.Context, container, path string) (container.PathStat, error) - ContainerStats(ctx context.Context, container string, stream bool) (container.StatsResponseReader, error) - ContainerStatsOneShot(ctx context.Context, container string) (container.StatsResponseReader, error) + ContainerStats(ctx context.Context, container string, stream bool) (StatsResponseReader, error) + ContainerStatsOneShot(ctx context.Context, container string) (StatsResponseReader, error) ContainerStart(ctx context.Context, container string, options container.StartOptions) error ContainerStop(ctx context.Context, container string, options container.StopOptions) error ContainerTop(ctx context.Context, container string, arguments []string) (container.TopResponse, error) diff --git a/vendor/github.com/moby/moby/client/container_stats.go b/vendor/github.com/moby/moby/client/container_stats.go index f701a693c6..e3cca04c89 100644 --- a/vendor/github.com/moby/moby/client/container_stats.go +++ b/vendor/github.com/moby/moby/client/container_stats.go @@ -2,17 +2,28 @@ package client import ( "context" + "io" "net/url" - - "github.com/moby/moby/api/types/container" ) +// StatsResponseReader wraps an io.ReadCloser to read (a stream of) stats +// for a container, as produced by the GET "/stats" endpoint. +// +// The OSType field is set to the server's platform to allow +// platform-specific handling of the response. +// +// TODO(thaJeztah): remove this wrapper, and make OSType part of [github.com/moby/moby/api/types/container.StatsResponse]. +type StatsResponseReader struct { + Body io.ReadCloser `json:"body"` + OSType string `json:"ostype"` +} + // ContainerStats returns near realtime stats for a given container. // It's up to the caller to close the io.ReadCloser returned. -func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error) { +func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (StatsResponseReader, error) { containerID, err := trimID("container", containerID) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } query := url.Values{} @@ -23,10 +34,10 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } - return container.StatsResponseReader{ + return StatsResponseReader{ Body: resp.Body, OSType: resp.Header.Get("Ostype"), }, nil @@ -34,10 +45,10 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea // ContainerStatsOneShot gets a single stat entry from a container. // It differs from `ContainerStats` in that the API should not wait to prime the stats -func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (container.StatsResponseReader, error) { +func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (StatsResponseReader, error) { containerID, err := trimID("container", containerID) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } query := url.Values{} @@ -46,10 +57,10 @@ func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) if err != nil { - return container.StatsResponseReader{}, err + return StatsResponseReader{}, err } - return container.StatsResponseReader{ + return StatsResponseReader{ Body: resp.Body, OSType: resp.Header.Get("Ostype"), }, nil