Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit ddecaae

Browse files
committed
Fix renaming of "runtime" container to "docker-daemon".
1 parent 2ca8178 commit ddecaae

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

metrics/sources/summary/summary.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ func (this *summaryMetricsSource) decodeNodeStats(metrics map[string]*MetricSet,
163163
metrics[NodeKey(node.NodeName)] = nodeMetrics
164164

165165
for _, container := range node.SystemContainers {
166-
key := NodeContainerKey(node.NodeName, this.getContainerName(&container))
167-
containerMetrics := this.decodeContainerStats(labels, &container)
166+
key := NodeContainerKey(node.NodeName, this.getSystemContainerName(&container))
167+
containerMetrics := this.decodeContainerStats(labels, &container, true)
168168
containerMetrics.Labels[LabelMetricSetType.Key] = MetricSetTypeSystemContainer
169169
metrics[key] = containerMetrics
170170
}
@@ -196,11 +196,11 @@ func (this *summaryMetricsSource) decodePodStats(metrics map[string]*MetricSet,
196196

197197
for _, container := range pod.Containers {
198198
key := PodContainerKey(ref.Namespace, ref.Name, container.Name)
199-
metrics[key] = this.decodeContainerStats(podMetrics.Labels, &container)
199+
metrics[key] = this.decodeContainerStats(podMetrics.Labels, &container, false)
200200
}
201201
}
202202

203-
func (this *summaryMetricsSource) decodeContainerStats(podLabels map[string]string, container *stats.ContainerStats) *MetricSet {
203+
func (this *summaryMetricsSource) decodeContainerStats(podLabels map[string]string, container *stats.ContainerStats, isSystemContainer bool) *MetricSet {
204204
glog.V(9).Infof("Decoding container stats stats for container %s...", container.Name)
205205
containerMetrics := &MetricSet{
206206
Labels: this.cloneLabels(podLabels),
@@ -210,7 +210,11 @@ func (this *summaryMetricsSource) decodeContainerStats(podLabels map[string]stri
210210
ScrapeTime: this.getScrapeTime(container.CPU, container.Memory, nil),
211211
}
212212
containerMetrics.Labels[LabelMetricSetType.Key] = MetricSetTypePodContainer
213-
containerMetrics.Labels[LabelContainerName.Key] = this.getContainerName(container)
213+
if isSystemContainer {
214+
containerMetrics.Labels[LabelContainerName.Key] = this.getSystemContainerName(container)
215+
} else {
216+
containerMetrics.Labels[LabelContainerName.Key] = container.Name
217+
}
214218

215219
this.decodeUptime(containerMetrics, container.StartTime.Time)
216220
this.decodeCPUStats(containerMetrics, container.CPU)
@@ -348,7 +352,7 @@ func (this *summaryMetricsSource) addLabeledIntMetric(metrics *MetricSet, metric
348352
}
349353

350354
// Translate system container names to the legacy names for backwards compatibility.
351-
func (this *summaryMetricsSource) getContainerName(c *stats.ContainerStats) string {
355+
func (this *summaryMetricsSource) getSystemContainerName(c *stats.ContainerStats) string {
352356
if legacyName, ok := systemNameMap[c.Name]; ok {
353357
return legacyName
354358
}

metrics/sources/summary/summary_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ const (
5959
seedPod1 = 3000
6060
seedPod1Container = 4000
6161
seedPod2 = 5000
62-
seedPod2Container = 6000
62+
seedPod2Container0 = 6000
63+
seedPod2Container1 = 7000
6364
)
6465

6566
const (
@@ -72,8 +73,9 @@ const (
7273

7374
cName00 = "c0"
7475
cName01 = "c1"
75-
cName10 = "c0" // ensure cName10 conflicts with cName02, but is in a different pod
76-
cName20 = "c1" // ensure cName20 conflicts with cName01, but is in a different pod + namespace
76+
cName10 = "c0" // ensure cName10 conflicts with cName02, but is in a different pod
77+
cName20 = "c1" // ensure cName20 conflicts with cName01, but is in a different pod + namespace
78+
cName21 = "runtime" // ensure that runtime containers are not renamed
7779
)
7880

7981
var (
@@ -157,7 +159,8 @@ func TestDecodeSummaryMetrics(t *testing.T) {
157159
StartTime: metav1.NewTime(startTime),
158160
Network: genTestSummaryNetwork(seedPod2),
159161
Containers: []stats.ContainerStats{
160-
genTestSummaryContainer(cName20, seedPod2Container),
162+
genTestSummaryContainer(cName20, seedPod2Container0),
163+
genTestSummaryContainer(cName21, seedPod2Container1),
161164
},
162165
}},
163166
}
@@ -237,7 +240,14 @@ func TestDecodeSummaryMetrics(t *testing.T) {
237240
}, {
238241
key: core.PodContainerKey(namespace1, pName2, cName20),
239242
setType: core.MetricSetTypePodContainer,
240-
seed: seedPod2Container,
243+
seed: seedPod2Container0,
244+
cpu: true,
245+
memory: true,
246+
fs: containerFs,
247+
}, {
248+
key: core.PodContainerKey(namespace1, pName2, cName21),
249+
setType: core.MetricSetTypePodContainer,
250+
seed: seedPod2Container1,
241251
cpu: true,
242252
memory: true,
243253
fs: containerFs,

0 commit comments

Comments
 (0)