From 72d126c8427c422f6aec88568b5835b910d8b555 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Thu, 26 Mar 2015 13:04:05 -0700 Subject: [PATCH] Remove files that no longer exist in cAdvisor dep. --- .../google/cadvisor/info/container.go | 379 ------------------ .../google/cadvisor/info/container_test.go | 79 ---- .../google/cadvisor/info/machine.go | 53 --- .../google/cadvisor/info/test/datagen.go | 76 ---- .../google/cadvisor/info/version.go | 18 - 5 files changed, 605 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/google/cadvisor/info/container.go delete mode 100644 Godeps/_workspace/src/github.com/google/cadvisor/info/container_test.go delete mode 100644 Godeps/_workspace/src/github.com/google/cadvisor/info/machine.go delete mode 100644 Godeps/_workspace/src/github.com/google/cadvisor/info/test/datagen.go delete mode 100644 Godeps/_workspace/src/github.com/google/cadvisor/info/version.go diff --git a/Godeps/_workspace/src/github.com/google/cadvisor/info/container.go b/Godeps/_workspace/src/github.com/google/cadvisor/info/container.go deleted file mode 100644 index 5a4fbbd9b5b..00000000000 --- a/Godeps/_workspace/src/github.com/google/cadvisor/info/container.go +++ /dev/null @@ -1,379 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package info - -import ( - "reflect" - "time" -) - -type CpuSpec struct { - Limit uint64 `json:"limit"` - MaxLimit uint64 `json:"max_limit"` - Mask string `json:"mask,omitempty"` -} - -type MemorySpec struct { - // The amount of memory requested. Default is unlimited (-1). - // Units: bytes. - Limit uint64 `json:"limit,omitempty"` - - // The amount of guaranteed memory. Default is 0. - // Units: bytes. - Reservation uint64 `json:"reservation,omitempty"` - - // The amount of swap space requested. Default is unlimited (-1). - // Units: bytes. - SwapLimit uint64 `json:"swap_limit,omitempty"` -} - -type ContainerSpec struct { - HasCpu bool `json:"has_cpu"` - Cpu CpuSpec `json:"cpu,omitempty"` - - HasMemory bool `json:"has_memory"` - Memory MemorySpec `json:"memory,omitempty"` - - HasNetwork bool `json:"has_network"` - - HasFilesystem bool `json:"has_filesystem"` -} - -// Container reference contains enough information to uniquely identify a container -type ContainerReference struct { - // The absolute name of the container. This is unique on the machine. - Name string `json:"name"` - - // Other names by which the container is known within a certain namespace. - // This is unique within that namespace. - Aliases []string `json:"aliases,omitempty"` - - // Namespace under which the aliases of a container are unique. - // An example of a namespace is "docker" for Docker containers. - Namespace string `json:"namespace,omitempty"` -} - -// ContainerInfoQuery is used when users check a container info from the REST api. -// It specifies how much data users want to get about a container -type ContainerInfoRequest struct { - // Max number of stats to return. - NumStats int `json:"num_stats,omitempty"` -} - -type ContainerInfo struct { - ContainerReference - - // The direct subcontainers of the current container. - Subcontainers []ContainerReference `json:"subcontainers,omitempty"` - - // The isolation used in the container. - Spec ContainerSpec `json:"spec,omitempty"` - - // Historical statistics gathered from the container. - Stats []*ContainerStats `json:"stats,omitempty"` -} - -// ContainerInfo may be (un)marshaled by json or other en/decoder. In that -// case, the Timestamp field in each stats/sample may not be precisely -// en/decoded. This will lead to small but acceptable differences between a -// ContainerInfo and its encode-then-decode version. Eq() is used to compare -// two ContainerInfo accepting small difference (<10ms) of Time fields. -func (self *ContainerInfo) Eq(b *ContainerInfo) bool { - - // If both self and b are nil, then Eq() returns true - if self == nil { - return b == nil - } - if b == nil { - return self == nil - } - - // For fields other than time.Time, we will compare them precisely. - // This would require that any slice should have same order. - if !reflect.DeepEqual(self.ContainerReference, b.ContainerReference) { - return false - } - if !reflect.DeepEqual(self.Subcontainers, b.Subcontainers) { - return false - } - if !reflect.DeepEqual(self.Spec, b.Spec) { - return false - } - - for i, expectedStats := range b.Stats { - selfStats := self.Stats[i] - if !expectedStats.Eq(selfStats) { - return false - } - } - - return true -} - -func (self *ContainerInfo) StatsAfter(ref time.Time) []*ContainerStats { - n := len(self.Stats) + 1 - for i, s := range self.Stats { - if s.Timestamp.After(ref) { - n = i - break - } - } - if n > len(self.Stats) { - return nil - } - return self.Stats[n:] -} - -func (self *ContainerInfo) StatsStartTime() time.Time { - var ret time.Time - for _, s := range self.Stats { - if s.Timestamp.Before(ret) || ret.IsZero() { - ret = s.Timestamp - } - } - return ret -} - -func (self *ContainerInfo) StatsEndTime() time.Time { - var ret time.Time - for i := len(self.Stats) - 1; i >= 0; i-- { - s := self.Stats[i] - if s.Timestamp.After(ret) { - ret = s.Timestamp - } - } - return ret -} - -// All CPU usage metrics are cumulative from the creation of the container -type CpuStats struct { - Usage struct { - // Total CPU usage. - // Units: nanoseconds - Total uint64 `json:"total"` - - // Per CPU/core usage of the container. - // Unit: nanoseconds. - PerCpu []uint64 `json:"per_cpu_usage,omitempty"` - - // Time spent in user space. - // Unit: nanoseconds - User uint64 `json:"user"` - - // Time spent in kernel space. - // Unit: nanoseconds - System uint64 `json:"system"` - } `json:"usage"` - Load int32 `json:"load"` -} - -type PerDiskStats struct { - Major uint64 `json:"major"` - Minor uint64 `json:"minor"` - Stats map[string]uint64 `json:"stats"` -} - -type DiskIoStats struct { - IoServiceBytes []PerDiskStats `json:"io_service_bytes,omitempty"` - IoServiced []PerDiskStats `json:"io_serviced,omitempty"` - IoQueued []PerDiskStats `json:"io_queued,omitempty"` - Sectors []PerDiskStats `json:"sectors,omitempty"` - IoServiceTime []PerDiskStats `json:"io_service_time,omitempty"` - IoWaitTime []PerDiskStats `json:"io_wait_time,omitempty"` - IoMerged []PerDiskStats `json:"io_merged,omitempty"` - IoTime []PerDiskStats `json:"io_time,omitempty"` -} - -type MemoryStats struct { - // Current memory usage, this includes all memory regardless of when it was - // accessed. - // Units: Bytes. - Usage uint64 `json:"usage"` - - // The amount of working set memory, this includes recently accessed memory, - // dirty memory, and kernel memory. Working set is <= "usage". - // Units: Bytes. - WorkingSet uint64 `json:"working_set"` - - ContainerData MemoryStatsMemoryData `json:"container_data,omitempty"` - HierarchicalData MemoryStatsMemoryData `json:"hierarchical_data,omitempty"` -} - -type MemoryStatsMemoryData struct { - Pgfault uint64 `json:"pgfault"` - Pgmajfault uint64 `json:"pgmajfault"` -} - -type NetworkStats struct { - // Cumulative count of bytes received. - RxBytes uint64 `json:"rx_bytes"` - // Cumulative count of packets received. - RxPackets uint64 `json:"rx_packets"` - // Cumulative count of receive errors encountered. - RxErrors uint64 `json:"rx_errors"` - // Cumulative count of packets dropped while receiving. - RxDropped uint64 `json:"rx_dropped"` - // Cumulative count of bytes transmitted. - TxBytes uint64 `json:"tx_bytes"` - // Cumulative count of packets transmitted. - TxPackets uint64 `json:"tx_packets"` - // Cumulative count of transmit errors encountered. - TxErrors uint64 `json:"tx_errors"` - // Cumulative count of packets dropped while transmitting. - TxDropped uint64 `json:"tx_dropped"` -} - -type FsStats struct { - // The block device name associated with the filesystem. - Device string `json:"device,omitempty"` - - // Number of bytes that can be consumed by the container on this filesystem. - Limit uint64 `json:"capacity"` - - // Number of bytes that is consumed by the container on this filesystem. - Usage uint64 `json:"usage"` - - // Number of reads completed - // This is the total number of reads completed successfully. - ReadsCompleted uint64 `json:"reads_completed"` - - // Number of reads merged - // Reads and writes which are adjacent to each other may be merged for - // efficiency. Thus two 4K reads may become one 8K read before it is - // ultimately handed to the disk, and so it will be counted (and queued) - // as only one I/O. This field lets you know how often this was done. - ReadsMerged uint64 `json:"reads_merged"` - - // Number of sectors read - // This is the total number of sectors read successfully. - SectorsRead uint64 `json:"sectors_read"` - - // Number of milliseconds spent reading - // This is the total number of milliseconds spent by all reads (as - // measured from __make_request() to end_that_request_last()). - ReadTime uint64 `json:"read_time"` - - // Number of writes completed - // This is the total number of writes completed successfully. - WritesCompleted uint64 `json:"writes_completed"` - - // Number of writes merged - // See the description of reads merged. - WritesMerged uint64 `json:"writes_merged"` - - // Number of sectors written - // This is the total number of sectors written successfully. - SectorsWritten uint64 `json:"sectors_written"` - - // Number of milliseconds spent writing - // This is the total number of milliseconds spent by all writes (as - // measured from __make_request() to end_that_request_last()). - WriteTime uint64 `json:"write_time"` - - // Number of I/Os currently in progress - // The only field that should go to zero. Incremented as requests are - // given to appropriate struct request_queue and decremented as they finish. - IoInProgress uint64 `json:"io_in_progress"` - - // Number of milliseconds spent doing I/Os - // This field increases so long as field 9 is nonzero. - IoTime uint64 `json:"io_time"` - - // weighted number of milliseconds spent doing I/Os - // This field is incremented at each I/O start, I/O completion, I/O - // merge, or read of these stats by the number of I/Os in progress - // (field 9) times the number of milliseconds spent doing I/O since the - // last update of this field. This can provide an easy measure of both - // I/O completion time and the backlog that may be accumulating. - WeightedIoTime uint64 `json:"weighted_io_time"` -} - -type ContainerStats struct { - // The time of this stat point. - Timestamp time.Time `json:"timestamp"` - Cpu CpuStats `json:"cpu,omitempty"` - DiskIo DiskIoStats `json:"diskio,omitempty"` - Memory MemoryStats `json:"memory,omitempty"` - Network NetworkStats `json:"network,omitempty"` - - // Filesystem statistics - Filesystem []FsStats `json:"filesystem,omitempty"` -} - -func timeEq(t1, t2 time.Time, tolerance time.Duration) bool { - // t1 should not be later than t2 - if t1.After(t2) { - t1, t2 = t2, t1 - } - diff := t2.Sub(t1) - if diff <= tolerance { - return true - } - return false -} - -func durationEq(a, b time.Duration, tolerance time.Duration) bool { - if a > b { - a, b = b, a - } - diff := a - b - if diff <= tolerance { - return true - } - return false -} - -const ( - // 10ms, i.e. 0.01s - timePrecision time.Duration = 10 * time.Millisecond -) - -// This function is useful because we do not require precise time -// representation. -func (a *ContainerStats) Eq(b *ContainerStats) bool { - if !timeEq(a.Timestamp, b.Timestamp, timePrecision) { - return false - } - return a.StatsEq(b) -} - -// Checks equality of the stats values. -func (a *ContainerStats) StatsEq(b *ContainerStats) bool { - // TODO(vmarmol): Consider using this through reflection. - if !reflect.DeepEqual(a.Cpu, b.Cpu) { - return false - } - if !reflect.DeepEqual(a.Memory, b.Memory) { - return false - } - if !reflect.DeepEqual(a.DiskIo, b.DiskIo) { - return false - } - if !reflect.DeepEqual(a.Network, b.Network) { - return false - } - if !reflect.DeepEqual(a.Filesystem, b.Filesystem) { - return false - } - return true -} - -// Saturate CPU usage to 0. -func calculateCpuUsage(prev, cur uint64) uint64 { - if prev > cur { - return 0 - } - return cur - prev -} diff --git a/Godeps/_workspace/src/github.com/google/cadvisor/info/container_test.go b/Godeps/_workspace/src/github.com/google/cadvisor/info/container_test.go deleted file mode 100644 index 2ff38e699b3..00000000000 --- a/Godeps/_workspace/src/github.com/google/cadvisor/info/container_test.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package info - -import ( - "testing" - "time" -) - -func TestStatsStartTime(t *testing.T) { - N := 10 - stats := make([]*ContainerStats, 0, N) - ct := time.Now() - for i := 0; i < N; i++ { - s := &ContainerStats{ - Timestamp: ct.Add(time.Duration(i) * time.Second), - } - stats = append(stats, s) - } - cinfo := &ContainerInfo{ - ContainerReference: ContainerReference{ - Name: "/some/container", - }, - Stats: stats, - } - ref := ct.Add(time.Duration(N-1) * time.Second) - end := cinfo.StatsEndTime() - - if !ref.Equal(end) { - t.Errorf("end time is %v; should be %v", end, ref) - } -} - -func TestStatsEndTime(t *testing.T) { - N := 10 - stats := make([]*ContainerStats, 0, N) - ct := time.Now() - for i := 0; i < N; i++ { - s := &ContainerStats{ - Timestamp: ct.Add(time.Duration(i) * time.Second), - } - stats = append(stats, s) - } - cinfo := &ContainerInfo{ - ContainerReference: ContainerReference{ - Name: "/some/container", - }, - Stats: stats, - } - ref := ct - start := cinfo.StatsStartTime() - - if !ref.Equal(start) { - t.Errorf("start time is %v; should be %v", start, ref) - } -} - -func createStats(cpuUsage, memUsage uint64, timestamp time.Time) *ContainerStats { - stats := &ContainerStats{} - stats.Cpu.Usage.PerCpu = []uint64{cpuUsage} - stats.Cpu.Usage.Total = cpuUsage - stats.Cpu.Usage.System = 0 - stats.Cpu.Usage.User = cpuUsage - stats.Memory.Usage = memUsage - stats.Timestamp = timestamp - return stats -} diff --git a/Godeps/_workspace/src/github.com/google/cadvisor/info/machine.go b/Godeps/_workspace/src/github.com/google/cadvisor/info/machine.go deleted file mode 100644 index 0e73a8e0522..00000000000 --- a/Godeps/_workspace/src/github.com/google/cadvisor/info/machine.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package info - -type FsInfo struct { - // Block device associated with the filesystem. - Device string `json:"device"` - - // Total number of bytes available on the filesystem. - Capacity uint64 `json:"capacity"` -} - -type MachineInfo struct { - // The number of cores in this machine. - NumCores int `json:"num_cores"` - - // The amount of memory (in bytes) in this machine - MemoryCapacity int64 `json:"memory_capacity"` - - // Filesystems on this machine. - Filesystems []FsInfo `json:"filesystems"` -} - -type VersionInfo struct { - // Kernel version. - KernelVersion string `json:"kernel_version"` - - // OS image being used for cadvisor container, or host image if running on host directly. - ContainerOsVersion string `json:"container_os_version"` - - // Docker version. - DockerVersion string `json:"docker_version"` - - // cAdvisor version. - CadvisorVersion string `json:"cadvisor_version"` -} - -type MachineInfoFactory interface { - GetMachineInfo() (*MachineInfo, error) - GetVersionInfo() (*VersionInfo, error) -} diff --git a/Godeps/_workspace/src/github.com/google/cadvisor/info/test/datagen.go b/Godeps/_workspace/src/github.com/google/cadvisor/info/test/datagen.go deleted file mode 100644 index 519e28c1a3d..00000000000 --- a/Godeps/_workspace/src/github.com/google/cadvisor/info/test/datagen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package test - -import ( - "fmt" - "math/rand" - "time" - - "github.com/google/cadvisor/info" -) - -func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info.ContainerStats { - ret := make([]*info.ContainerStats, numStats) - perCoreUsages := make([]uint64, numCores) - currentTime := time.Now() - for i := range perCoreUsages { - perCoreUsages[i] = uint64(rand.Int63n(1000)) - } - for i := 0; i < numStats; i++ { - stats := new(info.ContainerStats) - stats.Timestamp = currentTime - currentTime = currentTime.Add(duration) - - percore := make([]uint64, numCores) - for i := range perCoreUsages { - perCoreUsages[i] += uint64(rand.Int63n(1000)) - percore[i] = perCoreUsages[i] - stats.Cpu.Usage.Total += percore[i] - } - stats.Cpu.Usage.PerCpu = percore - stats.Cpu.Usage.User = stats.Cpu.Usage.Total - stats.Cpu.Usage.System = 0 - stats.Memory.Usage = uint64(rand.Int63n(4096)) - ret[i] = stats - } - return ret -} - -func GenerateRandomContainerSpec(numCores int) info.ContainerSpec { - ret := info.ContainerSpec{ - Cpu: info.CpuSpec{}, - Memory: info.MemorySpec{}, - } - ret.Cpu.Limit = uint64(1000 + rand.Int63n(2000)) - ret.Cpu.MaxLimit = uint64(1000 + rand.Int63n(2000)) - ret.Cpu.Mask = fmt.Sprintf("0-%d", numCores-1) - ret.Memory.Limit = uint64(4096 + rand.Int63n(4096)) - return ret -} - -func GenerateRandomContainerInfo(containerName string, numCores int, query *info.ContainerInfoRequest, duration time.Duration) *info.ContainerInfo { - stats := GenerateRandomStats(query.NumStats, numCores, duration) - spec := GenerateRandomContainerSpec(numCores) - - ret := &info.ContainerInfo{ - ContainerReference: info.ContainerReference{ - Name: containerName, - }, - Spec: spec, - Stats: stats, - } - return ret -} diff --git a/Godeps/_workspace/src/github.com/google/cadvisor/info/version.go b/Godeps/_workspace/src/github.com/google/cadvisor/info/version.go deleted file mode 100644 index 771382ad3b6..00000000000 --- a/Godeps/_workspace/src/github.com/google/cadvisor/info/version.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package info - -// Version of cAdvisor. -const VERSION = "0.6.2"