Skip to content

Commit

Permalink
Allow setting remote write default parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Oct 31, 2023
1 parent 4ea3995 commit 0101661
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
5 changes: 5 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ parameters:
retention: 8d
volumeClaimTemplate: ${openshift4_monitoring:configs:prometheusK8s:volumeClaimTemplate}
thanosRuler: {}

remoteWriteDefaults:
cluster: {}
userWorkload: {}

alertManagerConfig:
route:
group_wait: 0s
Expand Down
11 changes: 8 additions & 3 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ then remoteWriteConfig {
}
else remoteWriteConfig;

local patchRemoteWrite(promConfig) = promConfig {
local patchRemoteWrite(promConfig, defaults) = promConfig {
_remoteWrite+:: {},
} + {
local rwd = super._remoteWrite,
Expand All @@ -59,6 +59,11 @@ local patchRemoteWrite(promConfig) = promConfig {
function(name) transformRelabelConfigs(rwd[name] { name: name }),
std.objectFields(rwd)
),
} + {
remoteWrite: std.map(
function(rw) rw + com.makeMergeable(defaults),
super.remoteWrite,
),
};

local customRules =
Expand All @@ -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),
}
),
),
Expand All @@ -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),
}
)
),
Expand Down
28 changes: 28 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ data:
"node-role.kubernetes.io/infra": ""
"remoteWrite":
- "name": "backwards-compatibility"
"queueConfig":
"maxShards": 80
- "basicAuth":
"password":
"key": "password"
Expand All @@ -42,6 +44,8 @@ data:
"headers":
"X-Scope-OrgID": "example"
"name": "example"
"queueConfig":
"maxShards": 80
"url": "https://prometheus.example.com/api/v1/write"
"writeRelabelConfigs":
- "action": "keep"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ data:
"node-role.kubernetes.io/infra": ""
"remoteWrite":
- "name": "backwards-compatibility-user"
"queueConfig":
"maxShards": 20
- "basicAuth":
"password":
"key": "password"
Expand All @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tests/remote-write.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ parameters:
username: prometheus
password: prometheus

remoteWriteDefaults:
cluster:
queueConfig:
maxShards: 80
userWorkload:
queueConfig:
maxShards: 20

configs:
prometheusK8s:
remoteWrite:
Expand Down

0 comments on commit 0101661

Please sign in to comment.