Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 2ca0d97

Browse files
committed
Alertmanager configuration tweaks
- Introduces the `fallback_config` option to allow an Alertmanager to have a fallback config. - Given the headless service a different name to allow seamless switching between 1 or multiple replicas. The cluster field in the service metadata is immutable which made it impossible to create the new service unless you delete the previous one.
1 parent b430982 commit 2ca0d97

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

cortex/alertmanager.libsonnet

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
local pvc = $.core.v1.persistentVolumeClaim,
33
local volumeMount = $.core.v1.volumeMount,
4+
local volume = $.core.v1.volume,
45
local container = $.core.v1.container,
56
local statefulSet = $.apps.v1.statefulSet,
67
local service = $.core.v1.service,
8+
local configMap = $.core.v1.configMap,
9+
710
local isHA = $._config.alertmanager.replicas > 1,
11+
local hasFallbackConfig = std.length($._config.alertmanager.fallback_config) > 0,
812
local peers = if isHA then
913
[
1014
'alertmanager-%d.alertmanager.%s.svc.%s.local:%s' % [i, $._config.namespace, $._config.cluster, $._config.alertmanager.gossip_port]
@@ -22,7 +26,18 @@
2226
'alertmanager.storage.path': '/data',
2327
'alertmanager.storage.gcs.bucketname': '%(cluster)s-cortex-%(namespace)s' % $._config,
2428
'alertmanager.web.external-url': '%s/alertmanager' % $._config.external_url,
25-
},
29+
} + if hasFallbackConfig then {
30+
'alertmanager.configs.fallback': '/configs/alertmanager_fallback_config.yaml',
31+
} else {},
32+
33+
alertmanager_fallback_config_map:
34+
if hasFallbackConfig then
35+
configMap.new('alertmanager-fallback-config') +
36+
configMap.withData({
37+
'alertmanager_fallback_config.yaml': $.util.manifestYaml($._config.alertmanager.fallback_config),
38+
})
39+
else {},
40+
2641

2742
alertmanager_pvc::
2843
if $._config.alertmanager_enabled then
@@ -51,7 +66,12 @@
5166
['--cluster.peer=%s' % peer for peer in peers]
5267
else [],
5368
) +
54-
container.withVolumeMountsMixin([volumeMount.new('alertmanager-data', '/data')]) +
69+
container.withVolumeMountsMixin(
70+
[volumeMount.new('alertmanager-data', '/data')] +
71+
if hasFallbackConfig then
72+
[volumeMount.new('alertmanager-fallback-config', '/configs')]
73+
else []
74+
) +
5575
$.util.resourcesRequests('100m', '1Gi') +
5676
$.util.readinessProbe +
5777
$.jaeger_mixin
@@ -67,15 +87,22 @@
6787
statefulSet.mixin.spec.selector.withMatchLabels({ name: 'alertmanager' }) +
6888
statefulSet.mixin.spec.template.spec.securityContext.withRunAsUser(0) +
6989
statefulSet.mixin.spec.updateStrategy.withType('RollingUpdate') +
70-
statefulSet.mixin.spec.template.spec.withTerminationGracePeriodSeconds(900)
90+
statefulSet.mixin.spec.template.spec.withTerminationGracePeriodSeconds(900) +
91+
statefulSet.mixin.spec.template.spec.withVolumesMixin(
92+
if hasFallbackConfig then
93+
[volume.fromConfigMap('alertmanager-fallback-config', 'alertmanager-fallback-config')]
94+
else []
95+
)
7196
else {},
7297

7398
alertmanager_service:
7499
if $._config.alertmanager_enabled then
75100
if isHA then
76101
$.util.serviceFor($.alertmanager_statefulset) +
102+
service.mixin.metadata.withName('alertmanager-headless') +
77103
service.mixin.spec.withClusterIp('None')
78104
else
79-
$.util.serviceFor($.alertmanager_statefulset)
105+
$.util.serviceFor($.alertmanager_statefulset) +
106+
service.mixin.metadata.withName('alertmanager')
80107
else {},
81108
}

cortex/config.libsonnet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
alertmanager: {
247247
replicas: 3,
248248
gossip_port: 9094,
249+
fallback_config: {},
249250
},
250251

251252
overrides: {

0 commit comments

Comments
 (0)