From 3f29324e04524f70b291f9aca694dade3835e52e Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Thu, 16 Feb 2017 14:46:04 -0500 Subject: [PATCH] Fix kubernetes host:port relabel regex. This change corrects a bug introduced by PR https://github.com/prometheus/prometheus/pull/2427 The regex uses three groups: the hostname, an optional port, and the prefered port from a kubernetes annotation. Previously, the second group should have been ignored if a :port was not present in the input. However, making the port group optional with the "?" had the unintended side-effect of allowing the hostname regex "(.+)" to match greedily, which included the ":port" patterns up to the ";" separating the hostname from the kubernetes port annotation. This change updates the regex for the hostname to match any non-":" characters. This forces the regex to stop if a ":port" is present and allow the second group to match the optional port. --- documentation/examples/prometheus-kubernetes.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/examples/prometheus-kubernetes.yml b/documentation/examples/prometheus-kubernetes.yml index 893614e63..8ac7899b2 100644 --- a/documentation/examples/prometheus-kubernetes.yml +++ b/documentation/examples/prometheus-kubernetes.yml @@ -108,7 +108,7 @@ scrape_configs: - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port] action: replace target_label: __address__ - regex: (.+)(?::\d+)?;(\d+) + regex: ([^:]+)(?::\d+)?;(\d+) replacement: $1:$2 - action: labelmap regex: __meta_kubernetes_service_label_(.+) @@ -174,7 +174,7 @@ scrape_configs: regex: (.+) - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] action: replace - regex: (.+)(?::\d+)?;(\d+) + regex: ([^:]+)(?::\d+)?;(\d+) replacement: $1:$2 target_label: __address__ - action: labelmap