Updating dependency github.com/google/cadvisor to version 6a8d614

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas
2020-05-14 17:29:52 -04:00
parent 449810c785
commit 082578c22f
109 changed files with 3417 additions and 1312 deletions

View File

@@ -99,9 +99,9 @@ type ContainerReference struct {
// Sorts by container name.
type ContainerReferenceSlice []ContainerReference
func (self ContainerReferenceSlice) Len() int { return len(self) }
func (self ContainerReferenceSlice) Swap(i, j int) { self[i], self[j] = self[j], self[i] }
func (self ContainerReferenceSlice) Less(i, j int) bool { return self[i].Name < self[j].Name }
func (s ContainerReferenceSlice) Len() int { return len(s) }
func (s ContainerReferenceSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ContainerReferenceSlice) Less(i, j int) bool { return s[i].Name < s[j].Name }
// ContainerInfoRequest is used when users check a container info from the REST API.
// It specifies how much data users want to get about a container
@@ -126,10 +126,10 @@ func DefaultContainerInfoRequest() ContainerInfoRequest {
}
}
func (self *ContainerInfoRequest) Equals(other ContainerInfoRequest) bool {
return self.NumStats == other.NumStats &&
self.Start.Equal(other.Start) &&
self.End.Equal(other.End)
func (r *ContainerInfoRequest) Equals(other ContainerInfoRequest) bool {
return r.NumStats == other.NumStats &&
r.Start.Equal(other.Start) &&
r.End.Equal(other.End)
}
type ContainerInfo struct {
@@ -151,30 +151,30 @@ type ContainerInfo struct {
// 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 {
func (ci *ContainerInfo) Eq(b *ContainerInfo) bool {
// If both self and b are nil, then Eq() returns true
if self == nil {
// If both ci and b are nil, then Eq() returns true
if ci == nil {
return b == nil
}
if b == nil {
return self == nil
return ci == 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) {
if !reflect.DeepEqual(ci.ContainerReference, b.ContainerReference) {
return false
}
if !reflect.DeepEqual(self.Subcontainers, b.Subcontainers) {
if !reflect.DeepEqual(ci.Subcontainers, b.Subcontainers) {
return false
}
if !self.Spec.Eq(&b.Spec) {
if !ci.Spec.Eq(&b.Spec) {
return false
}
for i, expectedStats := range b.Stats {
selfStats := self.Stats[i]
selfStats := ci.Stats[i]
if !expectedStats.Eq(selfStats) {
return false
}
@@ -183,57 +183,66 @@ func (self *ContainerInfo) Eq(b *ContainerInfo) bool {
return true
}
func (self *ContainerSpec) Eq(b *ContainerSpec) bool {
func (s *ContainerSpec) Eq(b *ContainerSpec) bool {
// Creation within 1s of each other.
diff := self.CreationTime.Sub(b.CreationTime)
diff := s.CreationTime.Sub(b.CreationTime)
if (diff > time.Second) || (diff < -time.Second) {
return false
}
if self.HasCpu != b.HasCpu {
if s.HasCpu != b.HasCpu {
return false
}
if !reflect.DeepEqual(self.Cpu, b.Cpu) {
if !reflect.DeepEqual(s.Cpu, b.Cpu) {
return false
}
if self.HasMemory != b.HasMemory {
if s.HasMemory != b.HasMemory {
return false
}
if !reflect.DeepEqual(self.Memory, b.Memory) {
if !reflect.DeepEqual(s.Memory, b.Memory) {
return false
}
if self.HasNetwork != b.HasNetwork {
if s.HasHugetlb != b.HasHugetlb {
return false
}
if self.HasFilesystem != b.HasFilesystem {
if s.HasNetwork != b.HasNetwork {
return false
}
if self.HasDiskIo != b.HasDiskIo {
if s.HasProcesses != b.HasProcesses {
return false
}
if self.HasCustomMetrics != b.HasCustomMetrics {
if s.HasFilesystem != b.HasFilesystem {
return false
}
if s.HasDiskIo != b.HasDiskIo {
return false
}
if s.HasCustomMetrics != b.HasCustomMetrics {
return false
}
if s.Image != b.Image {
return false
}
return true
}
func (self *ContainerInfo) StatsAfter(ref time.Time) []*ContainerStats {
n := len(self.Stats) + 1
for i, s := range self.Stats {
func (ci *ContainerInfo) StatsAfter(ref time.Time) []*ContainerStats {
n := len(ci.Stats) + 1
for i, s := range ci.Stats {
if s.Timestamp.After(ref) {
n = i
break
}
}
if n > len(self.Stats) {
if n > len(ci.Stats) {
return nil
}
return self.Stats[n:]
return ci.Stats[n:]
}
func (self *ContainerInfo) StatsStartTime() time.Time {
func (ci *ContainerInfo) StatsStartTime() time.Time {
var ret time.Time
for _, s := range self.Stats {
for _, s := range ci.Stats {
if s.Timestamp.Before(ret) || ret.IsZero() {
ret = s.Timestamp
}
@@ -241,10 +250,10 @@ func (self *ContainerInfo) StatsStartTime() time.Time {
return ret
}
func (self *ContainerInfo) StatsEndTime() time.Time {
func (ci *ContainerInfo) StatsEndTime() time.Time {
var ret time.Time
for i := len(self.Stats) - 1; i >= 0; i-- {
s := self.Stats[i]
for i := len(ci.Stats) - 1; i >= 0; i-- {
s := ci.Stats[i]
if s.Timestamp.After(ret) {
ret = s.Timestamp
}
@@ -816,6 +825,29 @@ type AcceleratorStats struct {
DutyCycle uint64 `json:"duty_cycle"`
}
// PerfStat represents value of a single monitored perf event.
type PerfStat struct {
// Indicates scaling ratio for an event: time_running/time_enabled
// (amount of time that event was being measured divided by
// amount of time that event was enabled for).
// value 1.0 indicates that no multiplexing occurred. Value close
// to 0 indicates that event was measured for short time and event's
// value might be inaccurate.
// See: https://lwn.net/Articles/324756/
ScalingRatio float64 `json:"scaling_ratio"`
// Value represents value of perf event retrieved from OS. It is
// normalized against ScalingRatio and takes multiplexing into
// consideration.
Value uint64 `json:"value"`
// Name is human readable name of an event.
Name string `json:"name"`
// CPU that perf event was measured on.
Cpu int `json:"cpu"`
}
type UlimitSpec struct {
Name string `json:"name"`
SoftLimit int64 `json:"soft_limit"`
@@ -864,6 +896,12 @@ type ContainerStats struct {
// Custom metrics from all collectors
CustomMetrics map[string][]MetricVal `json:"custom_metrics,omitempty"`
// Statistics originating from perf events
PerfStats []PerfStat `json:"perf_stats,omitempty"`
// Referenced memory
ReferencedMemory uint64 `json:"referenced_memory,omitempty"`
}
func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {
@@ -872,10 +910,7 @@ func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {
t1, t2 = t2, t1
}
diff := t2.Sub(t1)
if diff <= tolerance {
return true
}
return false
return diff <= tolerance
}
const (
@@ -916,6 +951,15 @@ func (a *ContainerStats) StatsEq(b *ContainerStats) bool {
if !reflect.DeepEqual(a.Filesystem, b.Filesystem) {
return false
}
if !reflect.DeepEqual(a.TaskStats, b.TaskStats) {
return false
}
if !reflect.DeepEqual(a.Accelerators, b.Accelerators) {
return false
}
if !reflect.DeepEqual(a.CustomMetrics, b.CustomMetrics) {
return false
}
return true
}
@@ -943,9 +987,9 @@ type EventType string
const (
EventOom EventType = "oom"
EventOomKill = "oomKill"
EventContainerCreation = "containerCreation"
EventContainerDeletion = "containerDeletion"
EventOomKill EventType = "oomKill"
EventContainerCreation EventType = "containerCreation"
EventContainerDeletion EventType = "containerDeletion"
)
// Extra information about an event. Only one type will be set.

View File

@@ -14,6 +14,8 @@
package v1
import "time"
type FsInfo struct {
// Block device associated with the filesystem.
Device string `json:"device"`
@@ -59,8 +61,8 @@ type Cache struct {
Level int `json:"level"`
}
func (self *Node) FindCore(id int) (bool, int) {
for i, n := range self.Cores {
func (n *Node) FindCore(id int) (bool, int) {
for i, n := range n.Cores {
if n.Id == id {
return true, i
}
@@ -68,30 +70,30 @@ func (self *Node) FindCore(id int) (bool, int) {
return false, -1
}
func (self *Node) AddThread(thread int, core int) {
func (n *Node) AddThread(thread int, core int) {
var coreIdx int
if core == -1 {
// Assume one hyperthread per core when topology data is missing.
core = thread
}
ok, coreIdx := self.FindCore(core)
ok, coreIdx := n.FindCore(core)
if !ok {
// New core
core := Core{Id: core}
self.Cores = append(self.Cores, core)
coreIdx = len(self.Cores) - 1
n.Cores = append(n.Cores, core)
coreIdx = len(n.Cores) - 1
}
self.Cores[coreIdx].Threads = append(self.Cores[coreIdx].Threads, thread)
n.Cores[coreIdx].Threads = append(n.Cores[coreIdx].Threads, thread)
}
func (self *Node) AddNodeCache(c Cache) {
self.Caches = append(self.Caches, c)
func (n *Node) AddNodeCache(c Cache) {
n.Caches = append(n.Caches, c)
}
func (self *Node) AddPerCoreCache(c Cache) {
for idx := range self.Cores {
self.Cores[idx].Caches = append(self.Cores[idx].Caches, c)
func (n *Node) AddPerCoreCache(c Cache) {
for idx := range n.Cores {
n.Cores[idx].Caches = append(n.Cores[idx].Caches, c)
}
}
@@ -138,17 +140,15 @@ type CloudProvider string
const (
GCE CloudProvider = "GCE"
AWS = "AWS"
Azure = "Azure"
Baremetal = "Baremetal"
UnknownProvider = "Unknown"
AWS CloudProvider = "AWS"
Azure CloudProvider = "Azure"
UnknownProvider CloudProvider = "Unknown"
)
type InstanceType string
const (
NoInstance InstanceType = "None"
UnknownInstance = "Unknown"
UnknownInstance = "Unknown"
)
type InstanceID string
@@ -158,6 +158,9 @@ const (
)
type MachineInfo struct {
// The time of this information point.
Timestamp time.Time `json:"timestamp"`
// The number of cores in this machine.
NumCores int `json:"num_cores"`
@@ -213,6 +216,45 @@ type MachineInfo struct {
InstanceID InstanceID `json:"instance_id"`
}
func (m *MachineInfo) Clone() *MachineInfo {
memoryByType := m.MemoryByType
if len(m.MemoryByType) > 0 {
memoryByType = make(map[string]*MemoryInfo)
for memoryType, memoryInfo := range m.MemoryByType {
memoryByType[memoryType] = memoryInfo
}
}
diskMap := m.DiskMap
if len(m.DiskMap) > 0 {
diskMap = make(map[string]DiskInfo)
for k, info := range m.DiskMap {
diskMap[k] = info
}
}
copy := MachineInfo{
Timestamp: m.Timestamp,
NumCores: m.NumCores,
NumPhysicalCores: m.NumPhysicalCores,
NumSockets: m.NumSockets,
CpuFrequency: m.CpuFrequency,
MemoryCapacity: m.MemoryCapacity,
MemoryByType: memoryByType,
NVMInfo: m.NVMInfo,
HugePages: m.HugePages,
MachineID: m.MachineID,
SystemUUID: m.SystemUUID,
BootID: m.BootID,
Filesystems: m.Filesystems,
DiskMap: diskMap,
NetworkDevices: m.NetworkDevices,
Topology: m.Topology,
CloudProvider: m.CloudProvider,
InstanceType: m.InstanceType,
InstanceID: m.InstanceID,
}
return &copy
}
type MemoryInfo struct {
// The amount of memory (in bytes).
Capacity uint64 `json:"capacity"`

View File

@@ -27,9 +27,6 @@ const (
// A counter-like value that is only expected to increase.
MetricCumulative MetricType = "cumulative"
// Rate over a time period.
MetricDelta MetricType = "delta"
)
// DataType for metric being exported.

View File

@@ -12,7 +12,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/klog/v2:go_default_library",
],
)

View File

@@ -136,6 +136,8 @@ type DeprecatedContainerStats struct {
// Custom Metrics
HasCustomMetrics bool `json:"has_custom_metrics"`
CustomMetrics map[string][]v1.MetricVal `json:"custom_metrics,omitempty"`
// Referenced memory
ReferencedMemory uint64 `json:"referenced_memory,omitempty"`
}
type ContainerStats struct {
@@ -164,6 +166,10 @@ type ContainerStats struct {
Accelerators []v1.AcceleratorStats `json:"accelerators,omitempty"`
// Custom Metrics
CustomMetrics map[string][]v1.MetricVal `json:"custom_metrics,omitempty"`
// Perf events counters
PerfStats []v1.PerfStat `json:"perf_stats,omitempty"`
// Referenced memory
ReferencedMemory uint64 `json:"referenced_memory,omitempty"`
}
type Percentiles struct {

View File

@@ -19,7 +19,7 @@ import (
"time"
"github.com/google/cadvisor/info/v1"
"k8s.io/klog"
"k8s.io/klog/v2"
)
func machineFsStatsFromV1(fsStats []v1.FsStats) []MachineFsStats {
@@ -101,7 +101,8 @@ func ContainerStatsFromV1(containerName string, spec *v1.ContainerSpec, stats []
var last *v1.ContainerStats
for _, val := range stats {
stat := &ContainerStats{
Timestamp: val.Timestamp,
Timestamp: val.Timestamp,
ReferencedMemory: val.ReferencedMemory,
}
if spec.HasCpu {
stat.Cpu = &val.Cpu
@@ -151,6 +152,9 @@ func ContainerStatsFromV1(containerName string, spec *v1.ContainerSpec, stats []
if len(val.Accelerators) > 0 {
stat.Accelerators = val.Accelerators
}
if len(val.PerfStats) > 0 {
stat.PerfStats = val.PerfStats
}
// TODO(rjnagal): Handle load stats.
newStats = append(newStats, stat)
}
@@ -169,6 +173,7 @@ func DeprecatedStatsFromV1(cont *v1.ContainerInfo) []DeprecatedContainerStats {
HasFilesystem: cont.Spec.HasFilesystem,
HasDiskIo: cont.Spec.HasDiskIo,
HasCustomMetrics: cont.Spec.HasCustomMetrics,
ReferencedMemory: val.ReferencedMemory,
}
if stat.HasCpu {
stat.Cpu = val.Cpu