From d902ba335d1816c972d55ebdbb6b8d0a3b7094ef Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Tue, 31 Oct 2023 16:00:23 +0100 Subject: [PATCH] Allow setting remote write default parameters --- class/defaults.yml | 5 ++++ component/main.jsonnet | 11 ++++++-- .../ROOT/pages/references/parameters.adoc | 28 +++++++++++++++++++ .../openshift4-monitoring/10_configmap.yaml | 5 ++++ .../10_configmap_user_workload.yaml | 4 +++ tests/remote-write.yml | 12 ++++++++ 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/class/defaults.yml b/class/defaults.yml index 8ba36d3d..f9b0b4cc 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -79,6 +79,11 @@ parameters: retention: 8d volumeClaimTemplate: ${openshift4_monitoring:configs:prometheusK8s:volumeClaimTemplate} thanosRuler: {} + + remoteWriteDefaults: + cluster: {} + userWorkload: {} + alertManagerConfig: route: group_wait: 0s diff --git a/component/main.jsonnet b/component/main.jsonnet index 572bfb39..de4ee246 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -50,7 +50,7 @@ then remoteWriteConfig { } else remoteWriteConfig; -local patchRemoteWrite(promConfig) = promConfig { +local patchRemoteWrite(promConfig, defaults) = promConfig { _remoteWrite+:: {}, } + { local rwd = super._remoteWrite, @@ -59,6 +59,11 @@ local patchRemoteWrite(promConfig) = promConfig { function(name) transformRelabelConfigs(rwd[name] { name: name }), std.objectFields(rwd) ), +} + { + remoteWrite: std.map( + function(rw) defaults + com.makeMergeable(rw), + super.remoteWrite, + ), }; local customRules = @@ -80,7 +85,7 @@ local customRules = } + std.mapWithKey( function(field, value) value + params.defaultConfig, params.configs { - prometheusK8s: patchRemoteWrite(super.prometheusK8s), + prometheusK8s: patchRemoteWrite(super.prometheusK8s, params.remoteWriteDefaults.cluster), } ), ), @@ -96,7 +101,7 @@ local customRules = std.mapWithKey( function(field, value) value + params.defaultConfig, params.configsUserWorkload { - prometheus: patchRemoteWrite(super.prometheus), + prometheus: patchRemoteWrite(super.prometheus, params.remoteWriteDefaults.userWorkload), } ) ), diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index 2884d8ae..e95f362d 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -711,3 +711,31 @@ default:: `{}` A dict of secrets to create in the namespace. The key is the name of the secret, the value is the content of the secret. The value must be a dict with a key `stringData` which is a dict of key/value pairs to add to the secret. + +== `remoteWriteDefaults` + +[horizontal] +type:: dict +default:: ++ +[source,yaml] +---- +remoteWriteDefaults: + cluster: {} + userWorkload: {} +---- +example:: ++ +[source,yaml] +---- +remoteWriteDefaults: + cluster: + queueConfig: + maxShards: 80 + userWorkload: + queueConfig: + maxShards: 20 +---- + +A dict of default remote write configurations for the Prometheus component. +Those values are merged into each remote write configuration in `configs.prometheusK8s.remoteWrite` and `configsUserWorkload.prometheus.remoteWrite`. diff --git a/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap.yaml b/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap.yaml index c741762d..e064b8c7 100644 --- a/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap.yaml +++ b/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap.yaml @@ -32,6 +32,9 @@ data: "node-role.kubernetes.io/infra": "" "remoteWrite": - "name": "backwards-compatibility" + "queueConfig": + "maxShards": 80 + "minShards": 5 - "basicAuth": "password": "key": "password" @@ -42,6 +45,8 @@ data: "headers": "X-Scope-OrgID": "example" "name": "example" + "queueConfig": + "maxShards": 70 "url": "https://prometheus.example.com/api/v1/write" "writeRelabelConfigs": - "action": "keep" diff --git a/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap_user_workload.yaml b/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap_user_workload.yaml index 4beb42b1..9b1dc9cd 100644 --- a/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap_user_workload.yaml +++ b/tests/golden/remote-write/openshift4-monitoring/openshift4-monitoring/10_configmap_user_workload.yaml @@ -21,6 +21,8 @@ data: "node-role.kubernetes.io/infra": "" "remoteWrite": - "name": "backwards-compatibility-user" + "queueConfig": + "maxShards": 20 - "basicAuth": "password": "key": "password" @@ -31,6 +33,8 @@ data: "headers": "X-Scope-OrgID": "customer" "name": "example" + "queueConfig": + "maxShards": 20 "url": "https://user-prometheus.example.com/api/v1/write" "writeRelabelConfigs": - "action": "keep" diff --git a/tests/remote-write.yml b/tests/remote-write.yml index ef462296..5966a0a9 100644 --- a/tests/remote-write.yml +++ b/tests/remote-write.yml @@ -23,10 +23,20 @@ parameters: username: prometheus password: prometheus + remoteWriteDefaults: + cluster: + queueConfig: + maxShards: 80 + userWorkload: + queueConfig: + maxShards: 20 + configs: prometheusK8s: remoteWrite: - name: backwards-compatibility + queueConfig: + minShards: 5 _remoteWrite: example: url: https://prometheus.example.com/api/v1/write @@ -52,6 +62,8 @@ parameters: password: name: remote-write key: password + queueConfig: + maxShards: 70 configsUserWorkload: prometheus: