Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions containermetrics/cached_container_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ type CachedContainerMetrics struct {
DiskQuotaBytes uint64 `json:"disk_quota_bytes"`
MemoryUsageBytes uint64 `json:"memory_usage_bytes"`
MemoryQuotaBytes uint64 `json:"memory_quota_bytes"`
RxBytes uint64 `json:"rx_bytes"`
TxBytes uint64 `json:"tx_bytes"`
RxBytes *uint64 `json:"rx_bytes,omitempty"`
TxBytes *uint64 `json:"tx_bytes,omitempty"`
}
96 changes: 50 additions & 46 deletions containermetrics/reporters_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ var _ = Describe("ReportersRunner", func() {
ginkgomon.Interrupt(process)
})

one := uint64(1)
two := uint64(2)
three := uint64(3)

sentCPUUsage := func() []cpuUsage {
usage := []cpuUsage{}

Expand Down Expand Up @@ -150,8 +154,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 1000,
AbsoluteCPUEntitlementInNanoseconds: 2000,
RxInBytes: 1,
TxInBytes: 1,
RxInBytes: &one,
TxInBytes: &one,
},
},
"container-guid-without-index": executor.Metrics{
Expand All @@ -164,8 +168,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 1001,
AbsoluteCPUEntitlementInNanoseconds: 2001,
RxInBytes: 1,
TxInBytes: 1,
RxInBytes: &one,
TxInBytes: &one,
},
},
"container-guid-with-index": executor.Metrics{
Expand All @@ -178,8 +182,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(2048),
ContainerAgeInNanoseconds: 1002,
AbsoluteCPUEntitlementInNanoseconds: 2002,
RxInBytes: 1,
TxInBytes: 1,
RxInBytes: &one,
TxInBytes: &one,
},
},
"container-guid-without-preloaded-rootfs": executor.Metrics{
Expand All @@ -192,8 +196,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(2048),
ContainerAgeInNanoseconds: 1003,
AbsoluteCPUEntitlementInNanoseconds: 2003,
RxInBytes: 1,
TxInBytes: 1,
RxInBytes: &one,
TxInBytes: &one,
},
},
"container-guid-without-age": executor.Metrics{
Expand All @@ -206,8 +210,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 0,
AbsoluteCPUEntitlementInNanoseconds: 2004,
RxInBytes: 1,
TxInBytes: 1,
RxInBytes: &one,
TxInBytes: &one,
},
},
}
Expand All @@ -223,8 +227,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 1000 + uint64(10*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2000,
RxInBytes: 2,
TxInBytes: 2,
RxInBytes: &two,
TxInBytes: &two,
},
},

Expand All @@ -238,8 +242,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 4096,
ContainerAgeInNanoseconds: 1001 + uint64(10*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2001,
RxInBytes: 2,
TxInBytes: 2,
RxInBytes: &two,
TxInBytes: &two,
},
},
"container-guid-with-index": executor.Metrics{
Expand All @@ -252,8 +256,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 512,
ContainerAgeInNanoseconds: 1002 + uint64(10*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2002,
RxInBytes: 2,
TxInBytes: 2,
RxInBytes: &two,
TxInBytes: &two,
}},
"container-guid-without-preloaded-rootfs": executor.Metrics{
MetricsConfig: executor.MetricsConfig{Tags: map[string]string{"source_id": "source-id-without-preloaded-rootfs"}},
Expand All @@ -265,8 +269,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 2048,
ContainerAgeInNanoseconds: 1003 + uint64(10*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2003,
RxInBytes: 2,
TxInBytes: 2,
RxInBytes: &two,
TxInBytes: &two,
},
},
"container-guid-without-age": executor.Metrics{
Expand All @@ -279,8 +283,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 0,
AbsoluteCPUEntitlementInNanoseconds: 2004,
RxInBytes: 2,
TxInBytes: 2,
RxInBytes: &two,
TxInBytes: &two,
},
},
"container-guid-without-metrics-at-t0": executor.Metrics{
Expand All @@ -293,8 +297,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 512,
ContainerAgeInNanoseconds: 1002 + uint64(10*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2002,
RxInBytes: 2,
TxInBytes: 2,
RxInBytes: &two,
TxInBytes: &two,
},
},
}
Expand All @@ -310,8 +314,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 1000 + uint64(20*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2000,
RxInBytes: 3,
TxInBytes: 3,
RxInBytes: &three,
TxInBytes: &three,
},
},

Expand All @@ -325,8 +329,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 234,
ContainerAgeInNanoseconds: 1001 + uint64(20*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2001,
RxInBytes: 3,
TxInBytes: 3,
RxInBytes: &three,
TxInBytes: &three,
},
},
"container-guid-with-index": executor.Metrics{
Expand All @@ -339,8 +343,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 43200,
ContainerAgeInNanoseconds: 1002 + uint64(20*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2002,
RxInBytes: 3,
TxInBytes: 3,
RxInBytes: &three,
TxInBytes: &three,
},
},
"container-guid-without-preloaded-rootfs": executor.Metrics{
Expand All @@ -353,8 +357,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 2048,
ContainerAgeInNanoseconds: 1003 + uint64(20*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2003,
RxInBytes: 3,
TxInBytes: 3,
RxInBytes: &three,
TxInBytes: &three,
},
},
"container-guid-without-age": executor.Metrics{
Expand All @@ -367,8 +371,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: megsToBytes(1024),
ContainerAgeInNanoseconds: 0,
AbsoluteCPUEntitlementInNanoseconds: 2004,
RxInBytes: 3,
TxInBytes: 3,
RxInBytes: &three,
TxInBytes: &three,
},
},
"container-guid-without-metrics-at-t0": executor.Metrics{
Expand All @@ -381,8 +385,8 @@ var _ = Describe("ReportersRunner", func() {
DiskLimitInBytes: 512,
ContainerAgeInNanoseconds: 1002 + uint64(20*time.Second),
AbsoluteCPUEntitlementInNanoseconds: 2002,
RxInBytes: 3,
TxInBytes: 3,
RxInBytes: &three,
TxInBytes: &three,
},
},
}
Expand Down Expand Up @@ -676,8 +680,8 @@ var _ = Describe("ReportersRunner", func() {
DiskUsageBytes: 4560,
MemoryQuotaBytes: megsToBytes(7890),
DiskQuotaBytes: 4096,
RxBytes: 2,
TxBytes: 2,
RxBytes: &two,
TxBytes: &two,
}))
Expect(containerMetrics).To(HaveKeyWithValue("container-guid-with-index", &containermetrics.CachedContainerMetrics{
MetricGUID: "source-id-with-index",
Expand All @@ -686,8 +690,8 @@ var _ = Describe("ReportersRunner", func() {
DiskUsageBytes: 6540,
MemoryQuotaBytes: megsToBytes(9870),
DiskQuotaBytes: 512,
RxBytes: 2,
TxBytes: 2,
RxBytes: &two,
TxBytes: &two,
}))
Expect(containerMetrics).To(HaveKeyWithValue("container-guid-without-source-id", &containermetrics.CachedContainerMetrics{
MetricGUID: "",
Expand All @@ -696,8 +700,8 @@ var _ = Describe("ReportersRunner", func() {
DiskUsageBytes: megsToBytes(456),
MemoryQuotaBytes: megsToBytes(789),
DiskQuotaBytes: megsToBytes(1024),
RxBytes: 2,
TxBytes: 2,
RxBytes: &two,
TxBytes: &two,
}))
Expect(containerMetrics).To(HaveKeyWithValue("container-guid-without-preloaded-rootfs", &containermetrics.CachedContainerMetrics{
MetricGUID: "source-id-without-preloaded-rootfs",
Expand All @@ -706,8 +710,8 @@ var _ = Describe("ReportersRunner", func() {
DiskUsageBytes: 4560,
MemoryQuotaBytes: megsToBytes(6780),
DiskQuotaBytes: 2048,
RxBytes: 2,
TxBytes: 2,
RxBytes: &two,
TxBytes: &two,
}))
Expect(containerMetrics).To(HaveKeyWithValue("container-guid-without-age", &containermetrics.CachedContainerMetrics{
MetricGUID: "source-id-without-age",
Expand All @@ -716,8 +720,8 @@ var _ = Describe("ReportersRunner", func() {
DiskUsageBytes: megsToBytes(456),
MemoryQuotaBytes: megsToBytes(789),
DiskQuotaBytes: megsToBytes(1024),
RxBytes: 2,
TxBytes: 2,
RxBytes: &two,
TxBytes: &two,
}))
Expect(containerMetrics).To(HaveKeyWithValue("container-guid-without-metrics-at-t0", &containermetrics.CachedContainerMetrics{
MetricGUID: "source-id-without-metrics-at-t0",
Expand All @@ -726,8 +730,8 @@ var _ = Describe("ReportersRunner", func() {
DiskUsageBytes: 6540,
MemoryQuotaBytes: megsToBytes(9870),
DiskQuotaBytes: 512,
RxBytes: 2,
TxBytes: 2,
RxBytes: &two,
TxBytes: &two,
}))
})
})
Expand Down
11 changes: 9 additions & 2 deletions depot/containerstore/containerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ func (cs *containerStore) Metrics(logger lager.Logger) (map[string]executor.Cont

rootFSSize := cs.rootFSSizer.RootFSSizeFromPath(nodeInfo.RootFSPath)
diskUsage := gardenMetric.DiskStat.TotalBytesUsed - rootFSSize

var rxInBytes, txInBytes *uint64
if gardenMetric.NetworkStat != nil {
rxInBytes = &gardenMetric.NetworkStat.RxBytes
txInBytes = &gardenMetric.NetworkStat.TxBytes
}

containerMetrics[guid] = executor.ContainerMetrics{
MemoryUsageInBytes: gardenMetric.MemoryStat.TotalUsageTowardLimit,
DiskUsageInBytes: diskUsage,
Expand All @@ -367,8 +374,8 @@ func (cs *containerStore) Metrics(logger lager.Logger) (map[string]executor.Cont
TimeSpentInCPU: time.Duration(gardenMetric.CPUStat.Usage),
ContainerAgeInNanoseconds: uint64(gardenMetric.Age),
AbsoluteCPUEntitlementInNanoseconds: gardenMetric.CPUEntitlement,
RxInBytes: gardenMetric.NetworkStat.RxBytes,
TxInBytes: gardenMetric.NetworkStat.TxBytes,
RxInBytes: rxInBytes,
TxInBytes: txInBytes,
}
}

Expand Down
22 changes: 10 additions & 12 deletions depot/containerstore/containerstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,10 @@ var _ = Describe("Container Store", func() {
_, err = containerStore.Create(logger, "some-trace-id", containerGuid4)
Expect(err).ToNot(HaveOccurred())

networkStat1 := garden.ContainerNetworkStat{
RxBytes: uint64(42),
TxBytes: uint64(43),
}
bulkMetrics := map[string]garden.ContainerMetricsEntry{
containerGuid1: garden.ContainerMetricsEntry{
Metrics: garden.Metrics{
Expand All @@ -3050,10 +3054,7 @@ var _ = Describe("Container Store", func() {
},
Age: 1000000000,
CPUEntitlement: 100,
NetworkStat: garden.ContainerNetworkStat{
RxBytes: 42,
TxBytes: 43,
},
NetworkStat: &networkStat1,
},
},
containerGuid2: garden.ContainerMetricsEntry{
Expand All @@ -3069,10 +3070,7 @@ var _ = Describe("Container Store", func() {
},
Age: 2000000000,
CPUEntitlement: 200,
NetworkStat: garden.ContainerNetworkStat{
RxBytes: 44,
TxBytes: 45,
},
NetworkStat: nil,
},
},
containerGuid4: garden.ContainerMetricsEntry{
Expand Down Expand Up @@ -3118,8 +3116,8 @@ var _ = Describe("Container Store", func() {
Expect(container1Metrics.TimeSpentInCPU).To(Equal(5 * time.Second))
Expect(container1Metrics.ContainerAgeInNanoseconds).To(Equal(uint64(1000000000)))
Expect(container1Metrics.AbsoluteCPUEntitlementInNanoseconds).To(Equal(uint64(100)))
Expect(container1Metrics.RxInBytes).To(Equal(uint64(42)))
Expect(container1Metrics.TxInBytes).To(Equal(uint64(43)))
Expect(*container1Metrics.RxInBytes).To(Equal(uint64(42)))
Expect(*container1Metrics.TxInBytes).To(Equal(uint64(43)))

container2Metrics, ok := metrics[containerGuid2]
Expect(ok).To(BeTrue())
Expand All @@ -3130,8 +3128,8 @@ var _ = Describe("Container Store", func() {
Expect(container2Metrics.TimeSpentInCPU).To(Equal(1 * time.Millisecond))
Expect(container2Metrics.ContainerAgeInNanoseconds).To(Equal(uint64(2000000000)))
Expect(container2Metrics.AbsoluteCPUEntitlementInNanoseconds).To(Equal(uint64(200)))
Expect(container2Metrics.RxInBytes).To(Equal(uint64(44)))
Expect(container2Metrics.TxInBytes).To(Equal(uint64(45)))
Expect(container2Metrics.RxInBytes).To(BeNil())
Expect(container2Metrics.TxInBytes).To(BeNil())
})

Context("when fetching bulk metrics fails", func() {
Expand Down
4 changes: 2 additions & 2 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ type ContainerMetrics struct {
TimeSpentInCPU time.Duration `json:"time_spent_in_cpu"`
AbsoluteCPUEntitlementInNanoseconds uint64 `json:"absolute_cpu_entitlement_in_ns"`
ContainerAgeInNanoseconds uint64 `json:"container_age_in_ns"`
RxInBytes uint64 `json:"rx_in_bytes"`
TxInBytes uint64 `json:"tx_in_bytes"`
RxInBytes *uint64 `json:"rx_in_bytes"`
TxInBytes *uint64 `json:"tx_in_bytes"`
}

type MetricsConfig struct {
Expand Down