Skip to content

Commit

Permalink
Keep scrape config in line with the new Prometheus scrape config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
beorn7 committed May 27, 2020
1 parent 89d80a6 commit 123e6f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
20 changes: 10 additions & 10 deletions production/helm/promtail/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ data:
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: instance
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container_name
target_label: container
- replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
Expand Down Expand Up @@ -94,11 +94,11 @@ data:
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: instance
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container_name
target_label: container
- replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
Expand Down Expand Up @@ -147,11 +147,11 @@ data:
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: instance
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container_name
target_label: container
- replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
Expand Down Expand Up @@ -202,11 +202,11 @@ data:
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: instance
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container_name
target_label: container
- replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
Expand Down Expand Up @@ -250,11 +250,11 @@ data:
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: instance
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_container_name
target_label: container_name
target_label: container
- replacement: /var/log/pods/*$1/*.log
separator: /
source_labels:
Expand Down
18 changes: 8 additions & 10 deletions production/ksonnet/promtail/scrape_config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ config {
regex: '__meta_kubernetes_pod_label_(.+)',
},

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

// But also include the namespace as a separate label, for routing alerts
// But also include the namespace, pod, container as separate
// labels. They uniquely identify a container. They are also
// identical to the target labels configured in Prometheus
// (but note that Loki does not use an instance label).
{
source_labels: ['__meta_kubernetes_namespace'],
action: 'replace',
target_label: 'namespace',
},

// Rename instances to be the pod name
{
source_labels: ['__meta_kubernetes_pod_name'],
action: 'replace',
target_label: 'instance',
target_label: 'pod', // Not 'pod_name', which disappeared in K8s 1.16.
},

// Include container_name label
{
source_labels: ['__meta_kubernetes_pod_container_name'],
action: 'replace',
target_label: 'container_name',
target_label: 'container', // Not 'container_name', which disappeared in K8s 1.16.
},

// Kubernetes puts logs under subdirectories keyed pod UID and container_name.
Expand All @@ -76,7 +75,6 @@ config {
// Scrape config to scrape any pods with a 'name' label.
gen_scrape_config('kubernetes-pods-name', '__meta_kubernetes_pod_uid') {
prelabel_config:: [

// Use name label as __service__.
{
source_labels: ['__meta_kubernetes_pod_label_name'],
Expand All @@ -85,7 +83,7 @@ config {
],
},

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

0 comments on commit 123e6f5

Please sign in to comment.