mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #40478 from cpuguy83/dont-prime-the-stats
Add stats options to not prime the stats
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/api/types/versions/v1p20"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
)
|
||||
|
||||
@@ -30,6 +31,10 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
|
||||
return err
|
||||
}
|
||||
|
||||
if config.Stream && config.OneShot {
|
||||
return errdefs.InvalidParameter(errors.New("cannot have stream=true and one-shot=true"))
|
||||
}
|
||||
|
||||
// If the container is either not running or restarting and requires no stream, return an empty stats.
|
||||
if (!ctr.IsRunning() || ctr.IsRestarting()) && !config.Stream {
|
||||
return json.NewEncoder(config.OutStream).Encode(&types.StatsJSON{
|
||||
@@ -64,7 +69,7 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
|
||||
updates := daemon.subscribeToContainerStats(ctr)
|
||||
defer daemon.unsubscribeToContainerStats(ctr, updates)
|
||||
|
||||
noStreamFirstFrame := true
|
||||
noStreamFirstFrame := !config.OneShot
|
||||
for {
|
||||
select {
|
||||
case v, ok := <-updates:
|
||||
|
||||
Reference in New Issue
Block a user