From b838d74dbea48abaf30300582289ecd8bb6cf088 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Sat, 26 Oct 2019 01:29:11 +0200 Subject: [PATCH] Simplify regexp's This is mostly to remove redundant anchoring (as it makes people believe that Prometheus's regexp's aren't anchored by default, which will backfire badly at some point), but it also removes useless grouping (again to avoid confusion). Signed-off-by: beorn7 --- docs/clients/promtail/scraping.md | 2 +- .../helm/promtail/templates/configmap.yaml | 18 +++++++++--------- .../ksonnet/promtail/scrape_config.libsonnet | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/clients/promtail/scraping.md b/docs/clients/promtail/scraping.md index cc1d4d23d73d5..2c5432e7ef76b 100644 --- a/docs/clients/promtail/scraping.md +++ b/docs/clients/promtail/scraping.md @@ -97,7 +97,7 @@ value or transformed to a final external label, such as `__job__`. * Drop the target if a label (`__service__` in the example) is empty: ```yaml - action: drop - regex: ^$ + regex: '' source_labels: - __service__ ``` diff --git a/production/helm/promtail/templates/configmap.yaml b/production/helm/promtail/templates/configmap.yaml index debc1480e9504..211279538f61c 100644 --- a/production/helm/promtail/templates/configmap.yaml +++ b/production/helm/promtail/templates/configmap.yaml @@ -28,7 +28,7 @@ data: - __meta_kubernetes_pod_node_name target_label: __host__ - action: drop - regex: ^$ + regex: '' source_labels: - __service__ - action: labelmap @@ -75,7 +75,7 @@ data: - __meta_kubernetes_pod_node_name target_label: __host__ - action: drop - regex: ^$ + regex: '' source_labels: - __service__ - action: labelmap @@ -118,7 +118,7 @@ data: - __meta_kubernetes_pod_label_name - __meta_kubernetes_pod_label_app - action: drop - regex: ^([0-9a-z-.]+)(-[0-9a-f]{8,10})$ + regex: '[0-9a-z-.]+-[0-9a-f]{8,10}' source_labels: - __meta_kubernetes_pod_controller_name - source_labels: @@ -128,7 +128,7 @@ data: - __meta_kubernetes_pod_node_name target_label: __host__ - action: drop - regex: ^$ + regex: '' source_labels: - __service__ - action: labelmap @@ -171,11 +171,11 @@ data: - __meta_kubernetes_pod_label_name - __meta_kubernetes_pod_label_app - action: keep - regex: ^([0-9a-z-.]+)(-[0-9a-f]{8,10})$ + regex: '[0-9a-z-.]+-[0-9a-f]{8,10}' source_labels: - __meta_kubernetes_pod_controller_name - action: replace - regex: ^([0-9a-z-.]+)(-[0-9a-f]{8,10})$ + regex: '([0-9a-z-.]+)-[0-9a-f]{8,10}' source_labels: - __meta_kubernetes_pod_controller_name target_label: __service__ @@ -183,7 +183,7 @@ data: - __meta_kubernetes_pod_node_name target_label: __host__ - action: drop - regex: ^$ + regex: '' source_labels: - __service__ - action: labelmap @@ -220,7 +220,7 @@ data: - role: pod relabel_configs: - action: drop - regex: ^$ + regex: '' source_labels: - __meta_kubernetes_pod_annotation_kubernetes_io_config_mirror - action: replace @@ -231,7 +231,7 @@ data: - __meta_kubernetes_pod_node_name target_label: __host__ - action: drop - regex: ^$ + regex: '' source_labels: - __service__ - action: labelmap diff --git a/production/ksonnet/promtail/scrape_config.libsonnet b/production/ksonnet/promtail/scrape_config.libsonnet index ad590a1d7877a..ff4a1bb2d493b 100644 --- a/production/ksonnet/promtail/scrape_config.libsonnet +++ b/production/ksonnet/promtail/scrape_config.libsonnet @@ -20,7 +20,7 @@ config + { { source_labels: ['__service__'], action: 'drop', - regex: '^$', + regex: '', }, // Include all the other labels on the pod. @@ -122,7 +122,7 @@ config + { { source_labels: ['__meta_kubernetes_pod_controller_name'], action: 'drop', - regex: '^([0-9a-z-.]+)(-[0-9a-f]{8,10})$', + regex: '[0-9a-z-.]+-[0-9a-f]{8,10}', }, // Use controller name as __service__. @@ -149,15 +149,15 @@ config + { // Drop pods not from an indirect controller. eg StatefulSets, DaemonSets { source_labels: ['__meta_kubernetes_pod_controller_name'], - regex: '^([0-9a-z-.]+)(-[0-9a-f]{8,10})$', + regex: '[0-9a-z-.]+-[0-9a-f]{8,10}', action: 'keep', }, - // put the indirect controller name into a temp label. + // Put the indirect controller name into a temp label. { source_labels: ['__meta_kubernetes_pod_controller_name'], action: 'replace', - regex: '^([0-9a-z-.]+)(-[0-9a-f]{8,10})$', + regex: '([0-9a-z-.]+)-[0-9a-f]{8,10}', target_label: '__service__', }, ] @@ -171,7 +171,7 @@ config + { { action: 'drop', source_labels: ['__meta_kubernetes_pod_annotation_kubernetes_io_config_mirror'], - regex: '^$', + regex: '', }, // Static control plane pods usually have a component label that identifies them