From a9f9c59b9132ea8487f239b0a498c7bacec33f5c Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Wed, 29 Dec 2021 11:42:46 -0800 Subject: [PATCH] Configure Prometheus to allow a custom scrape query param * Set `prometheus.io/param` on a Kubernetes Service to scrape the service endpoints and pass a custom query parameter * For example, scrape Consul with `?format=prometheus` ```yaml kind: Service metadata: annotations: prometheus.io/scrape: 'true' prometheus.io/port: '8500' prometheus.io/path: /v1/agent/metrics prometheus.io/param: format=prometheus ``` --- CHANGES.md | 4 ++++ addons/prometheus/config.yaml | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c3ea6c19..2354fb65 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,10 @@ Notable changes between versions. * Switch Kubernetes Container Runtime from `docker` to `containerd` ([#1087](https://github.com/poseidon/typhoon/pull/1087)) +### Addons + +* Configure Prometheus to allow a custom scrape query parameter ([#1095](https://github.com/poseidon/typhoon/pull/1095)) + ## v1.23.0 * Kubernetes [v1.23.0](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.23.md#v1230) diff --git a/addons/prometheus/config.yaml b/addons/prometheus/config.yaml index 8d693ad5..4d98a359 100644 --- a/addons/prometheus/config.yaml +++ b/addons/prometheus/config.yaml @@ -175,6 +175,7 @@ data: # * `prometheus.io/path`: If the metrics path is not `/metrics` override this. # * `prometheus.io/port`: If the metrics are exposed on a different port to the # service then set this appropriately. + # * `prometheus.io/param`: Custom metrics query parameter, like "format=prometheus". - job_name: 'kubernetes-service-endpoints' kubernetes_sd_configs: - role: endpoints @@ -197,6 +198,11 @@ data: target_label: __address__ regex: ([^:]+)(?::\d+)?;(\d+) replacement: $1:$2 + - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_param] + action: replace + target_label: __param_$1 + regex: ([^=]+)=(.*) + replacement: $2 - action: labelmap regex: __meta_kubernetes_service_label_(.+) - source_labels: [__meta_kubernetes_namespace]