To turn off Alertmanager clustering in the Linux package, you set cluster.listen-address to an empty string. The empty string never reached the process. Alertmanager bound *:9094 anyway.
This is the story of omnibus-gitlab!10089. I'll cover why empty? was the wrong check, the first version that also changed Prometheus and redis_exporter, and the review comments that narrowed the fix and tightened the specs.
The issue: a flag that vanished on reconfigure
The issue was omnibus-gitlab#10213, opened by Mikael. The documented way to disable HA clustering is an explicit empty value in /etc/gitlab/gitlab.rb:
alertmanager['flags'] = {
'cluster.listen-address' => ''
}
After gitlab-ctl reconfigure, that value was not in the generated run script. Alertmanager then used its default cluster listener on *:9094.
The drop happened in PrometheusHelper#kingpin_flags:
next if flag_value.empty?
config << "--#{flag_key}=#{Shellwords.shellescape(flag_value)}"
"" is empty?. The helper treated "please pass an empty value" as "please omit the flag." For Alertmanager, those are opposite instructions. Omitting the flag means the default listen address. Passing --cluster.listen-address= is how you disable clustering.
Unset flags should still be omitted. The distinction is nil versus "".
Version 1: keep the empty string, in two helpers
The first commit (e2baa1a21d) skipped only nil, and it did that in both #kingpin_flags and #flags. It also special-cased the empty string so it would not go through Shellwords.shellescape, on the idea that an escaped empty value would be rendered as --flag='' instead of --flag=:
next if flag_value.nil?
value = flag_value.empty? ? '' : Shellwords.shellescape(flag_value)
config << "--#{flag_key}=#{value}"
That fixed Alertmanager. It also changed what '' meant for everything else #flags and #kingpin_flags touch.
The review: do not change Prometheus and redis_exporter
Lucas Li approved the Alertmanager change and then drew a line around the rest of it:
The
#flagshunk also changes what''means for Prometheus and redis_exporter. It used to drop the flag, including computed defaults likestorage.tsdb.path, and now renders--flag=. redis_exporter uses Go'sflagpackage, where an empty value for a bool flag fails to parse, so the exporter would exit and restart in a loop. Since the issue only covers Alertmanager, could you drop the#flagshunk, or call out the new meaning of''in the description and changelog entry?
That is a strong reason to drop a hunk. A crash-loop in redis_exporter is not a side effect you take on to fix Alertmanager. The second commit (e5080ec290) left #flags alone. An empty value there is still dropped, the way it was before.
Lucas also pointed out that you can always shellescape the empty string. The run script contains --cluster.listen-address='', and the shell turns that into --flag= before the process sees it. The "do not escape ''" branch was unnecessary, and it made the empty path different from every other value. The final helper is:
# Keep explicit empty strings (Alertmanager uses
# --cluster.listen-address= to disable clustering). Skip only nil
# so unset flags stay omitted. Always shellescape; the shell still
# passes --flag='' through as an empty value.
next if flag_value.nil?
config << "--#{flag_key}=#{Shellwords.shellescape(flag_value)}"
Hossein Pursultani then widened the picture in a useful way. #kingpin_flags is also used by node_exporter and postgres_exporter. An explicit empty string is now rendered for those services too; it used to be dropped. That is worth saying in the description, and it is worth a spec so the new behaviour is pinned down. A boolean flag set to '' would probably fail to parse, so the description now says boolean flags should stay true/false.
He also caught a spec that could not fail:
In
alertmanager_spec.rb,not_to match(%r{--cluster\.listen-address=/})can never fail. Something likenot_to match(/--cluster\.listen-address=[^'\s]/)would actually test it.
The first regexp is looking for --cluster.listen-address=/. An empty flag does not look like that, and neither does a default address such as *:9094. The second regexp fails if the flag has a non-empty value. That is the case the file needs to reject.
The docs now show the gitlab.rb snippet, and they describe what actually lands in the run script: --cluster.listen-address='', which the shell turns into an empty argument.
The specs that settled the meaning of empty
The helper specs now pin four cases I care about:
- When the flag is unset,
cluster.listen-addressis omitted entirely. Alertmanager should still get its default. - When it is
'', the run flags include--cluster.listen-address=''. - When it is
nilin the flags hash, it is omitted, same as unset. - An empty
storage.pathoverrides the computed default path, instead of falling through to/var/opt/gitlab/alertmanager/data.
And, after Hossein's comment, an explicit empty web.listen-address on node_exporter is preserved too.
The recipe spec checks the generated /opt/gitlab/sv/alertmanager/run file with the regex that can actually fail:
it 'renders an empty cluster.listen-address so Alertmanager disables clustering' do
expect(chef_run).to render_file('/opt/gitlab/sv/alertmanager/run')
.with_content { |content|
# Shellwords renders --flag='', which the shell passes as --flag=.
expect(content).to include("--cluster.listen-address=''")
expect(content).not_to match(/--cluster\.listen-address=[^'\s]/)
}
end
The MR merged on 26 November 2026.
What I took away
1. empty? cannot tell "unset" from "set to empty." For a helper that builds CLI flags, those have to be different paths. Skip nil. Pass "" through.
2. The same helper is rarely used by only the service in the issue. #kingpin_flags also builds flags for node_exporter and postgres_exporter. A change that is right for Alertmanager still needs a sentence, and a spec, for the other callers.
3. Do not widen a fix into a helper you do not need. Changing #flags would have given Prometheus and redis_exporter a new meaning of '', including a possible crash-loop. The issue was Alertmanager. Leaving #flags alone kept the blast radius at the issue.
4. Let the shell do what the shell does. --flag='' in a run script is not a bug. It is how you write an empty value safely. Special-casing shellescape for "" added a second rendering path for no benefit.
5. A negative regexp has to describe the failure you care about. listen-address=/ was never going to appear, so the example could not catch a regression that put a real address back on the flag.
Links
- Issue: omnibus-gitlab#10213
- Merge request: omnibus-gitlab!10089
Thanks to Mikael for reporting the issue, to Lucas Li for catching the redis_exporter risk and the unnecessary shellescape special case, and to Hossein Pursultani for the other callers of #kingpin_flags and the regexp that can fail.
If you've been thinking about contributing to GitLab, the community issues are a great place to start: contributors.gitlab.com.
Top comments (0)