diff --git a/jsonnet/kube-prometheus/components/prometheus.libsonnet b/jsonnet/kube-prometheus/components/prometheus.libsonnet index 5e1c9e33f5e0bcb0158d9b684a7a2d755ad0186d..a9d0100ae351e5ea3f060aa322726ab79ee6c72d 100644 --- a/jsonnet/kube-prometheus/components/prometheus.libsonnet +++ b/jsonnet/kube-prometheus/components/prometheus.libsonnet @@ -50,20 +50,21 @@ function(params) { assert std.isObject(p._config.resources), assert std.isObject(p._config.mixin._config), - mixin:: (import 'github.com/prometheus/prometheus/documentation/prometheus-mixin/mixin.libsonnet') + - (import 'github.com/kubernetes-monitoring/kubernetes-mixin/lib/add-runbook-links.libsonnet') + ( - if p._config.thanos != {} then - (import 'github.com/thanos-io/thanos/mixin/alerts/sidecar.libsonnet') + { - targetGroups: {}, - sidecar: { - selector: p._config.mixin._config.thanosSelector, - dimensions: std.join(', ', ['job', 'instance']), - }, - } - else {} - ) { - _config+:: p._config.mixin._config, - }, + mixin:: + (import 'github.com/prometheus/prometheus/documentation/prometheus-mixin/mixin.libsonnet') + + (import 'github.com/kubernetes-monitoring/kubernetes-mixin/lib/add-runbook-links.libsonnet') + { + _config+:: p._config.mixin._config, + }, + + mixinThanos:: + (import 'github.com/thanos-io/thanos/mixin/alerts/sidecar.libsonnet') + + (import 'github.com/kubernetes-monitoring/kubernetes-mixin/lib/add-runbook-links.libsonnet') + { + targetGroups: {}, + sidecar: { + selector: p._config.mixin._config.thanosSelector, + dimensions: std.join(', ', ['job', 'instance']), + }, + }, prometheusRule: { apiVersion: 'monitoring.coreos.com/v1', @@ -327,6 +328,22 @@ function(params) { }, }, + // Include thanos sidecar PrometheusRule only if thanos config was passed by user + [if std.objectHas(params, 'thanos') && std.length(params.thanos) > 0 then 'prometheusRuleThanosSidecar']: { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'PrometheusRule', + metadata: { + labels: p._config.commonLabels + p._config.mixin.ruleLabels, + name: 'prometheus-' + p._config.name + '-thanos-sidecar-rules', + namespace: p._config.namespace, + }, + spec: { + local r = if std.objectHasAll(p.mixinThanos, 'prometheusRules') then p.mixinThanos.prometheusRules.groups else [], + local a = if std.objectHasAll(p.mixinThanos, 'prometheusAlerts') then p.mixinThanos.prometheusAlerts.groups else [], + groups: a + r, + }, + }, + // Include thanos sidecar Service only if thanos config was passed by user [if std.objectHas(params, 'thanos') && std.length(params.thanos) > 0 then 'serviceThanosSidecar']: { apiVersion: 'v1',