Skip to content

Commit 0ccca40

Browse files
committed
Add a container and pod target label
This allows joining with cAdvisor metrics.
1 parent 26402f2 commit 0ccca40

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

prometheus-ksonnet/lib/prometheus-config.libsonnet

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,23 @@
134134
replacement: '$1',
135135
},
136136

137-
// But also include the namespace as a separate label, for routing alerts
137+
// But also include the namespace, container, pod as separate labels,
138+
// for routing alerts and joining with cAdvisor metrics.
138139
{
139140
source_labels: ['__meta_kubernetes_namespace'],
140141
action: 'replace',
141142
target_label: 'namespace',
142143
},
144+
{
145+
source_labels: ['__meta_kubernetes_pod_name'],
146+
action: 'replace',
147+
target_label: 'pod', // Not 'pod_name', which disappeared in K8s 1.16.
148+
},
149+
{
150+
source_labels: ['__meta_kubernetes_container_name'],
151+
action: 'replace',
152+
target_label: 'container', // Not 'container_name', which disappeared in K8s 1.16.
153+
},
143154

144155
// Rename instances to the concatenation of pod:container:port.
145156
// All three components are needed to guarantee a unique instance label.
@@ -169,10 +180,12 @@
169180
],
170181
},
171182

172-
// A separate scrape config for kube-state-metrics which doesn't add a namespace
173-
// label, instead taking the namespace label from the exported timeseries. This
174-
// prevents the exported namespace label being renamed to exported_namespace, and
175-
// allows us to route alerts based on namespace.
183+
// A separate scrape config for kube-state-metrics which doesn't
184+
// add namespace, container, and pod labels, instead taking
185+
// those labels from the exported timeseries. This prevents them
186+
// being renamed to exported_namespace etc. and allows us to
187+
// route alerts based on namespace and join KSM metrics with
188+
// cAdvisor metrics.
176189
{
177190
job_name: '%s/kube-state-metrics' % $._config.namespace,
178191
kubernetes_sd_configs: [{

0 commit comments

Comments
 (0)