From 75bc89f6e3094c56119aa7a2ae7c7ecd0e594599 Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Fri, 2 Sep 2022 17:51:30 +0200 Subject: [PATCH] prometheus-adapter: add prefix option to config for container metrics (#1844) This commit adds the options `containerMetricsPrefix` to the prometheus-adapter config-map generator. By default this option is the empty string and doesn't change the current behavior. If set however to e.g. `pa_`, the prometheus-adapter configuration will add this prefix to all container_ queries in the resource rules. This enables users of kube-prometheus to define a specialised service monitor, that only expose the prometheus-adapter related container metrics with a different configuration, like `honorTimestamps: true` or a tighter scrape interval. Signed-off-by: Jan Fajerski --- .../components/prometheus-adapter.libsonnet | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet b/jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet index 41fadebffe..f83601cff9 100644 --- a/jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet +++ b/jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet @@ -31,6 +31,7 @@ local defaults = { nodeExporter: '4m', windowsExporter: '4m', }, + containerMetricsPrefix:: '', prometheusURL:: error 'must provide prometheusURL', config:: { @@ -39,10 +40,10 @@ local defaults = { containerQuery: ||| sum by (<<.GroupBy>>) ( irate ( - container_cpu_usage_seconds_total{<<.LabelMatchers>>,container!="",pod!=""}[%(kubelet)s] + %(containerMetricsPrefix)scontainer_cpu_usage_seconds_total{<<.LabelMatchers>>,container!="",pod!=""}[%(kubelet)s] ) ) - ||| % $.rangeIntervals, + ||| % { kubelet: $.rangeIntervals.kubelet, containerMetricsPrefix: $.containerMetricsPrefix }, nodeQuery: ||| sum by (<<.GroupBy>>) ( 1 - irate( @@ -57,7 +58,7 @@ local defaults = { windows_cpu_time_total{mode="idle", job="windows-exporter",<<.LabelMatchers>>}[%(windowsExporter)s] ) ) - ||| % $.rangeIntervals, + ||| % { nodeExporter: $.rangeIntervals.nodeExporter, windowsExporter: $.rangeIntervals.windowsExporter, containerMetricsPrefix: $.containerMetricsPrefix }, resources: { overrides: { node: { resource: 'node' }, @@ -70,9 +71,9 @@ local defaults = { memory: { containerQuery: ||| sum by (<<.GroupBy>>) ( - container_memory_working_set_bytes{<<.LabelMatchers>>,container!="",pod!=""} + %(containerMetricsPrefix)scontainer_memory_working_set_bytes{<<.LabelMatchers>>,container!="",pod!=""} ) - |||, + ||| % { containerMetricsPrefix: $.containerMetricsPrefix }, nodeQuery: ||| sum by (<<.GroupBy>>) ( node_memory_MemTotal_bytes{job="node-exporter",<<.LabelMatchers>>} @@ -84,7 +85,7 @@ local defaults = { - windows_memory_available_bytes{job="windows-exporter",<<.LabelMatchers>>} ) - |||, + ||| % { containerMetricsPrefix: $.containerMetricsPrefix }, resources: { overrides: { instance: { resource: 'node' },