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

Commit d6741b3

Browse files
authored
Merge pull request #1656 from loburm/fix-1639
Fix renaming of "runtime" container to "docker-daemon"
2 parents 5f9bf94 + ddecaae commit d6741b3

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
}
@@ -194,11 +194,11 @@ func (this *summaryMetricsSource) decodePodStats(metrics map[string]*MetricSet,
194194

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

201-
func (this *summaryMetricsSource) decodeContainerStats(podLabels map[string]string, container *stats.ContainerStats) *MetricSet {
201+
func (this *summaryMetricsSource) decodeContainerStats(podLabels map[string]string, container *stats.ContainerStats, isSystemContainer bool) *MetricSet {
202202
glog.V(9).Infof("Decoding container stats stats for container %s...", container.Name)
203203
containerMetrics := &MetricSet{
204204
Labels: this.cloneLabels(podLabels),
@@ -208,7 +208,11 @@ func (this *summaryMetricsSource) decodeContainerStats(podLabels map[string]stri
208208
ScrapeTime: this.getScrapeTime(container.CPU, container.Memory, nil),
209209
}
210210
containerMetrics.Labels[LabelMetricSetType.Key] = MetricSetTypePodContainer
211-
containerMetrics.Labels[LabelContainerName.Key] = this.getContainerName(container)
211+
if isSystemContainer {
212+
containerMetrics.Labels[LabelContainerName.Key] = this.getSystemContainerName(container)
213+
} else {
214+
containerMetrics.Labels[LabelContainerName.Key] = container.Name
215+
}
212216

213217
this.decodeUptime(containerMetrics, container.StartTime.Time)
214218
this.decodeCPUStats(containerMetrics, container.CPU)
@@ -346,7 +350,7 @@ func (this *summaryMetricsSource) addLabeledIntMetric(metrics *MetricSet, metric
346350
}
347351

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

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)