|
134 | 134 | replacement: '$1',
|
135 | 135 | },
|
136 | 136 |
|
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. |
138 | 139 | {
|
139 | 140 | source_labels: ['__meta_kubernetes_namespace'],
|
140 | 141 | action: 'replace',
|
141 | 142 | target_label: 'namespace',
|
142 | 143 | },
|
143 |
| - |
144 |
| - // Rename instances to be the pod name |
145 | 144 | {
|
146 | 145 | source_labels: ['__meta_kubernetes_pod_name'],
|
147 | 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 | + }, |
| 154 | + |
| 155 | + // Rename instances to the concatenation of pod:container:port. |
| 156 | + // All three components are needed to guarantee a unique instance label. |
| 157 | + { |
| 158 | + source_labels: [ |
| 159 | + '__meta_kubernetes_pod_name', |
| 160 | + '__meta_kubernetes_pod_container_name', |
| 161 | + '__meta_kubernetes_pod_container_port_name', |
| 162 | + ], |
| 163 | + action: 'replace', |
| 164 | + separator: ':', |
148 | 165 | target_label: 'instance',
|
149 | 166 | },
|
150 | 167 |
|
|
163 | 180 | ],
|
164 | 181 | },
|
165 | 182 |
|
166 |
| - // A separate scrape config for kube-state-metrics which doesn't add a namespace |
167 |
| - // label, instead taking the namespace label from the exported timeseries. This |
168 |
| - // prevents the exported namespace label being renamed to exported_namespace, and |
169 |
| - // 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. |
170 | 189 | {
|
171 | 190 | job_name: '%s/kube-state-metrics' % $._config.namespace,
|
172 | 191 | kubernetes_sd_configs: [{
|
|
192 | 211 | action: 'keep',
|
193 | 212 | },
|
194 | 213 |
|
195 |
| - // Rename instances to be the pod name. |
196 |
| - // As the scrape two ports of KSM, include the port name in the instance |
197 |
| - // name. Otherwise alerts about scrape failures and timeouts won't work. |
| 214 | + // Rename instances to the concatenation of pod:container:port. |
| 215 | + // In the specific case of KSM, we could leave out the container |
| 216 | + // name and still have a unique instance label, but we leave it |
| 217 | + // in here for consistency with the normal pod scraping. |
198 | 218 | {
|
199 |
| - source_labels: ['__meta_kubernetes_pod_name', '__meta_kubernetes_pod_container_port_name'], |
| 219 | + source_labels: [ |
| 220 | + '__meta_kubernetes_pod_name', |
| 221 | + '__meta_kubernetes_pod_container_name', |
| 222 | + '__meta_kubernetes_pod_container_port_name', |
| 223 | + ], |
200 | 224 | action: 'replace',
|
201 | 225 | separator: ':',
|
202 | 226 | target_label: 'instance',
|
|
0 commit comments