Skip to content

Commit 123e6f5

Browse files
committed
Keep scrape config in line with the new Prometheus scrape config
This is triggered by grafana/jsonnet-libs#261 . The above PR removes the `instance` label. As it has turned out (see PR linked above), a sane `instance` label in Prometheus has to be unique, and that includes the case where a single container exposes metrics on two different endpoints. However, that scenario would still only result in one log stream for Loki to scrape. Therefore, Loki and Prometheus need to sync via target labels uniquely identifying a container (rather than a metrics endpoint). Those labels are namespace, pod, container, also added here. This commit removes the `container_name` label. It is the same as the `container` label and was already added to Loki previously. However, the `container_name` label is deprecated and has disappeared in K8s 1.16, so that it will soon become useless for direct joining.
1 parent 89d80a6 commit 123e6f5

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

production/helm/promtail/templates/configmap.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ data:
4747
- action: replace
4848
source_labels:
4949
- __meta_kubernetes_pod_name
50-
target_label: instance
50+
target_label: pod
5151
- action: replace
5252
source_labels:
5353
- __meta_kubernetes_pod_container_name
54-
target_label: container_name
54+
target_label: container
5555
- replacement: /var/log/pods/*$1/*.log
5656
separator: /
5757
source_labels:
@@ -94,11 +94,11 @@ data:
9494
- action: replace
9595
source_labels:
9696
- __meta_kubernetes_pod_name
97-
target_label: instance
97+
target_label: pod
9898
- action: replace
9999
source_labels:
100100
- __meta_kubernetes_pod_container_name
101-
target_label: container_name
101+
target_label: container
102102
- replacement: /var/log/pods/*$1/*.log
103103
separator: /
104104
source_labels:
@@ -147,11 +147,11 @@ data:
147147
- action: replace
148148
source_labels:
149149
- __meta_kubernetes_pod_name
150-
target_label: instance
150+
target_label: pod
151151
- action: replace
152152
source_labels:
153153
- __meta_kubernetes_pod_container_name
154-
target_label: container_name
154+
target_label: container
155155
- replacement: /var/log/pods/*$1/*.log
156156
separator: /
157157
source_labels:
@@ -202,11 +202,11 @@ data:
202202
- action: replace
203203
source_labels:
204204
- __meta_kubernetes_pod_name
205-
target_label: instance
205+
target_label: pod
206206
- action: replace
207207
source_labels:
208208
- __meta_kubernetes_pod_container_name
209-
target_label: container_name
209+
target_label: container
210210
- replacement: /var/log/pods/*$1/*.log
211211
separator: /
212212
source_labels:
@@ -250,11 +250,11 @@ data:
250250
- action: replace
251251
source_labels:
252252
- __meta_kubernetes_pod_name
253-
target_label: instance
253+
target_label: pod
254254
- action: replace
255255
source_labels:
256256
- __meta_kubernetes_pod_container_name
257-
target_label: container_name
257+
target_label: container
258258
- replacement: /var/log/pods/*$1/*.log
259259
separator: /
260260
source_labels:

production/ksonnet/promtail/scrape_config.libsonnet

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ config {
3131
regex: '__meta_kubernetes_pod_label_(.+)',
3232
},
3333

34-
// Rename jobs to be <namespace>/<name, from pod name label>
34+
// Rename jobs to be <namespace>/<service>.
3535
{
3636
source_labels: ['__meta_kubernetes_namespace', '__service__'],
3737
action: 'replace',
@@ -40,25 +40,24 @@ config {
4040
replacement: '$1',
4141
},
4242

43-
// But also include the namespace as a separate label, for routing alerts
43+
// But also include the namespace, pod, container as separate
44+
// labels. They uniquely identify a container. They are also
45+
// identical to the target labels configured in Prometheus
46+
// (but note that Loki does not use an instance label).
4447
{
4548
source_labels: ['__meta_kubernetes_namespace'],
4649
action: 'replace',
4750
target_label: 'namespace',
4851
},
49-
50-
// Rename instances to be the pod name
5152
{
5253
source_labels: ['__meta_kubernetes_pod_name'],
5354
action: 'replace',
54-
target_label: 'instance',
55+
target_label: 'pod', // Not 'pod_name', which disappeared in K8s 1.16.
5556
},
56-
57-
// Include container_name label
5857
{
5958
source_labels: ['__meta_kubernetes_pod_container_name'],
6059
action: 'replace',
61-
target_label: 'container_name',
60+
target_label: 'container', // Not 'container_name', which disappeared in K8s 1.16.
6261
},
6362

6463
// Kubernetes puts logs under subdirectories keyed pod UID and container_name.
@@ -76,7 +75,6 @@ config {
7675
// Scrape config to scrape any pods with a 'name' label.
7776
gen_scrape_config('kubernetes-pods-name', '__meta_kubernetes_pod_uid') {
7877
prelabel_config:: [
79-
8078
// Use name label as __service__.
8179
{
8280
source_labels: ['__meta_kubernetes_pod_label_name'],
@@ -85,7 +83,7 @@ config {
8583
],
8684
},
8785

88-
// Scrape config to scrape any pods with a 'app' label.
86+
// Scrape config to scrape any pods with an 'app' label.
8987
gen_scrape_config('kubernetes-pods-app', '__meta_kubernetes_pod_uid') {
9088
prelabel_config:: [
9189
// Drop pods with a 'name' label. They will have already been added by

0 commit comments

Comments
 (0)