Skip to content

Commit 0d5c211

Browse files
Merge pull request #329 from grafana/three-prom-configmaps
Split prom configmap into three
2 parents c6590ac + a400e19 commit 0d5c211

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

prometheus-ksonnet/lib/prometheus-config.libsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
},
66

77
rule_files: [
8-
'alerts.rules',
9-
'recording.rules',
8+
'alerts/alerts.rules',
9+
'recording/recording.rules',
1010
],
1111

1212
alerting: {

prometheus-ksonnet/lib/prometheus-configmap.libsonnet

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@
1111

1212
local configMap = $.core.v1.configMap,
1313

14-
prometheus_config_map:
14+
prometheus_config_maps:
1515
// Can't reference self.foo below as we're in a map context, so
1616
// need to capture reference to the configs in scope here.
1717
local prometheus_config = self.prometheus_config;
1818
local prometheusAlerts = self.prometheusAlerts;
1919
local prometheusRules = self.prometheusRules;
20+
[
21+
configMap.new('%s-config' % self.name) +
22+
configMap.withData({
23+
'prometheus.yml': $.util.manifestYaml(prometheus_config),
24+
}),
2025

21-
configMap.new('%s-config' % self.name) +
22-
configMap.withData({
23-
'prometheus.yml': $.util.manifestYaml(prometheus_config),
24-
'alerts.rules': $.util.manifestYaml(prometheusAlerts),
25-
'recording.rules': $.util.manifestYaml(prometheusRules),
26-
}),
26+
configMap.new('%s-alerts' % self.name) +
27+
configMap.withData({
28+
'alerts.rules': $.util.manifestYaml(prometheusAlerts),
29+
}),
30+
31+
configMap.new('%s-recording' % self.name) +
32+
configMap.withData({
33+
'recording.rules': $.util.manifestYaml(prometheusRules),
34+
}),
35+
],
2736
},
2837
}

prometheus-ksonnet/lib/prometheus-ha-mixin.libsonnet

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ local configMap = k.core.v1.configMap;
2929
config+:: root.prometheus_config {
3030
global+: {
3131
external_labels+: {
32-
__replica__: 'zero',
32+
__replica__: 'prometheus-0',
3333
},
3434
},
3535
},
@@ -41,32 +41,50 @@ local configMap = k.core.v1.configMap;
4141
config+:: root.prometheus_config {
4242
global+: {
4343
external_labels+: {
44-
__replica__: 'one',
44+
__replica__: 'prometheus-1',
4545
},
4646
},
4747
},
4848
alerts+:: root.prometheusAlerts,
4949
rules+:: root.prometheusRules,
5050
},
5151

52-
prometheus_config_map:: {},
53-
5452
prometheus_config_maps: [
55-
configMap.new('%s-config-0' % self.name) +
53+
configMap.new('%s-0-config' % self.name) +
5654
configMap.withData({
5755
'prometheus.yml': k.util.manifestYaml(root.prometheus_zero.config),
56+
}),
57+
configMap.new('%s-0-alerts' % self.name) +
58+
configMap.withData({
5859
'alerts.rules': k.util.manifestYaml(root.prometheus_zero.alerts),
60+
}),
61+
configMap.new('%s-0-recording' % self.name) +
62+
configMap.withData({
5963
'recording.rules': k.util.manifestYaml(root.prometheus_zero.rules),
6064
}),
61-
configMap.new('%s-config-1' % self.name) +
65+
66+
configMap.new('%s-1-config' % self.name) +
6267
configMap.withData({
6368
'prometheus.yml': k.util.manifestYaml(root.prometheus_one.config),
69+
}),
70+
configMap.new('%s-1-alerts' % self.name) +
71+
configMap.withData({
6472
'alerts.rules': k.util.manifestYaml(root.prometheus_one.alerts),
73+
}),
74+
configMap.new('%s-1-recording' % self.name) +
75+
configMap.withData({
6576
'recording.rules': k.util.manifestYaml(root.prometheus_one.rules),
6677
}),
6778
],
6879

69-
prometheus_config_mount:: {},
80+
prometheus_config_mount::
81+
k.util.configVolumeMount('%s-0-config' % self.name, '/etc/prometheus-0')
82+
+ k.util.configVolumeMount('%s-0-alerts' % self.name, '/etc/prometheus-0/alerts')
83+
+ k.util.configVolumeMount('%s-0-recording' % self.name, '/etc/prometheus-0/recording')
84+
+ k.util.configVolumeMount('%s-1-config' % self.name, '/etc/prometheus-1')
85+
+ k.util.configVolumeMount('%s-1-alerts' % self.name, '/etc/prometheus-1/alerts')
86+
+ k.util.configVolumeMount('%s-1-recording' % self.name, '/etc/prometheus-1/recording')
87+
,
7088

7189
prometheus_container+:: container.withEnv([
7290
container.envType.fromFieldPath('POD_NAME', 'metadata.name'),
@@ -82,7 +100,5 @@ local configMap = k.core.v1.configMap;
82100
]),
83101

84102
prometheus_statefulset+:
85-
k.util.configVolumeMount('%s-config-0' % self.name, '/etc/prometheus-0') +
86-
k.util.configVolumeMount('%s-config-1' % self.name, '/etc/prometheus-1') +
87103
statefulset.mixin.spec.withReplicas(2),
88104
}

prometheus-ksonnet/lib/prometheus.libsonnet

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@
7575
local volumeMount = $.core.v1.volumeMount,
7676

7777
prometheus_config_mount::
78-
$.util.configVolumeMount('%s-config' % self.name, _config.prometheus_config_dir),
78+
$.util.configVolumeMount('%s-config' % self.name, _config.prometheus_config_dir)
79+
+ $.util.configVolumeMount('%s-alerts' % self.name, _config.prometheus_config_dir + '/alerts')
80+
+ $.util.configVolumeMount('%s-recording' % self.name, _config.prometheus_config_dir + '/recording')
81+
,
7982

8083
prometheus_statefulset:
8184
statefulset.new(self.name, 1, [

0 commit comments

Comments
 (0)