From 7fed7d7eb4d7766d9342821f2667d160c5f958eb Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 24 Feb 2015 10:47:47 -0800 Subject: [PATCH] Move stats api types into api/types package Move the stats structs from the api/stats package into a new package api/types that will contain all the api structs for docker's api request and responses. Signed-off-by: Michael Crosby --- api/client/commands.go | 6 ++--- api/{stats => types}/stats.go | 2 +- daemon/stats.go | 24 +++++++++---------- integration-cli/docker_api_containers_test.go | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) rename api/{stats => types}/stats.go (99%) diff --git a/api/client/commands.go b/api/client/commands.go index 9776936506..8530c02285 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -26,7 +26,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/docker/docker/api" - "github.com/docker/docker/api/stats" + "github.com/docker/docker/api/types" "github.com/docker/docker/autogen/dockerversion" "github.com/docker/docker/engine" "github.com/docker/docker/graph" @@ -2640,7 +2640,7 @@ func (s *containerStats) Collect(cli *DockerCli) { ) go func() { for { - var v *stats.Stats + var v *types.Stats if err := dec.Decode(&v); err != nil { u <- err return @@ -2757,7 +2757,7 @@ func (cli *DockerCli) CmdStats(args ...string) error { return nil } -func calculateCpuPercent(previousCpu, previousSystem uint64, v *stats.Stats) float64 { +func calculateCpuPercent(previousCpu, previousSystem uint64, v *types.Stats) float64 { var ( cpuPercent = 0.0 // calculate the change for the cpu usage of the container in between readings diff --git a/api/stats/stats.go b/api/types/stats.go similarity index 99% rename from api/stats/stats.go rename to api/types/stats.go index 8edf18fe0e..97804e95e6 100644 --- a/api/stats/stats.go +++ b/api/types/stats.go @@ -1,6 +1,6 @@ // This package is used for API stability in the types and response to the // consumers of the API stats endpoint. -package stats +package types import "time" diff --git a/daemon/stats.go b/daemon/stats.go index e047497ec6..b36b28ae72 100644 --- a/daemon/stats.go +++ b/daemon/stats.go @@ -3,7 +3,7 @@ package daemon import ( "encoding/json" - "github.com/docker/docker/api/stats" + "github.com/docker/docker/api/types" "github.com/docker/docker/daemon/execdriver" "github.com/docker/docker/engine" "github.com/docker/libcontainer" @@ -33,10 +33,10 @@ func (daemon *Daemon) ContainerStats(job *engine.Job) engine.Status { // convertToAPITypes converts the libcontainer.ContainerStats to the api specific // structs. This is done to preserve API compatibility and versioning. -func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats { - s := &stats.Stats{} +func convertToAPITypes(ls *libcontainer.ContainerStats) *types.Stats { + s := &types.Stats{} if ls.NetworkStats != nil { - s.Network = stats.Network{ + s.Network = types.Network{ RxBytes: ls.NetworkStats.RxBytes, RxPackets: ls.NetworkStats.RxPackets, RxErrors: ls.NetworkStats.RxErrors, @@ -49,7 +49,7 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats { } cs := ls.CgroupStats if cs != nil { - s.BlkioStats = stats.BlkioStats{ + s.BlkioStats = types.BlkioStats{ IoServiceBytesRecursive: copyBlkioEntry(cs.BlkioStats.IoServiceBytesRecursive), IoServicedRecursive: copyBlkioEntry(cs.BlkioStats.IoServicedRecursive), IoQueuedRecursive: copyBlkioEntry(cs.BlkioStats.IoQueuedRecursive), @@ -60,21 +60,21 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats { SectorsRecursive: copyBlkioEntry(cs.BlkioStats.SectorsRecursive), } cpu := cs.CpuStats - s.CpuStats = stats.CpuStats{ - CpuUsage: stats.CpuUsage{ + s.CpuStats = types.CpuStats{ + CpuUsage: types.CpuUsage{ TotalUsage: cpu.CpuUsage.TotalUsage, PercpuUsage: cpu.CpuUsage.PercpuUsage, UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode, UsageInUsermode: cpu.CpuUsage.UsageInUsermode, }, - ThrottlingData: stats.ThrottlingData{ + ThrottlingData: types.ThrottlingData{ Periods: cpu.ThrottlingData.Periods, ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods, ThrottledTime: cpu.ThrottlingData.ThrottledTime, }, } mem := cs.MemoryStats - s.MemoryStats = stats.MemoryStats{ + s.MemoryStats = types.MemoryStats{ Usage: mem.Usage, MaxUsage: mem.MaxUsage, Stats: mem.Stats, @@ -84,10 +84,10 @@ func convertToAPITypes(ls *libcontainer.ContainerStats) *stats.Stats { return s } -func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []stats.BlkioStatEntry { - out := make([]stats.BlkioStatEntry, len(entries)) +func copyBlkioEntry(entries []cgroups.BlkioStatEntry) []types.BlkioStatEntry { + out := make([]types.BlkioStatEntry, len(entries)) for i, re := range entries { - out[i] = stats.BlkioStatEntry{ + out[i] = types.BlkioStatEntry{ Major: re.Major, Minor: re.Minor, Op: re.Op, diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 50c92c5149..b1477212a9 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/docker/docker/api/stats" + "github.com/docker/docker/api/types" "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" ) @@ -311,7 +311,7 @@ func TestGetContainerStats(t *testing.T) { } dec := json.NewDecoder(bytes.NewBuffer(sr.body)) - var s *stats.Stats + var s *types.Stats // decode only one object from the stream if err := dec.Decode(&s); err != nil { t.Fatal(err)