Preserve empty Alertmanager cluster.listen-address flag

What does this MR do?

PrometheusHelper#kingpin_flags skipped any flag whose value was empty?. Setting an explicit empty string in gitlab.rb, for example:

alertmanager['flags'] = {
  'cluster.listen-address' => ''
}

never reached the Alertmanager runit script. Alertmanager then bound the default cluster listener on *:9094.

This MR skips only nil in #kingpin_flags, so an explicit empty string is passed through as an empty value (how Alertmanager disables clustering). Unset flags stay omitted. #flags (Prometheus, redis_exporter) is unchanged, so an empty value there is still dropped. Empty values are passed through Shellwords.shellescape; the shell turns --flag='' into --flag= before the process sees it.

#kingpin_flags is also used by node_exporter and postgres_exporter, so an explicit empty string is now rendered for those services too (it was dropped before). Boolean flags should stay true/false; an empty string is a value flag (--flag=), which those exporters may not parse. A node_exporter spec pins the empty web.listen-address case.

Thanks @mlewans for reporting this.

Closes #10213 (closed)

How to test

  1. In /etc/gitlab/gitlab.rb, enable Alertmanager and disable clustering:

    alertmanager['enable'] = true
    alertmanager['flags'] = {
      'cluster.listen-address' => ''
    }
  2. Run gitlab-ctl reconfigure.

  3. Confirm /opt/gitlab/sv/alertmanager/run contains --cluster.listen-address='' (the shell passes this as --cluster.listen-address=).

  4. Confirm ps / the process command line shows --cluster.listen-address= (empty value), and Alertmanager is not listening on *:9094.

  5. Without that flag set, the run script should not contain cluster.listen-address at all (existing default behaviour).

Locally: bundle exec rspec on spec/chef/cookbooks/monitoring/libraries/prometheus_helper_spec.rb and spec/chef/cookbooks/monitoring/recipes/alertmanager_spec.rb (and the follow-up review commit). Local syntax checks and markdownlint-cli2 on doc/settings/prometheus.md are clean; ChefSpec and RuboCop will be confirmed in CI (no local bundle).

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion.

Required

  • MR title and description are up to date, accurate, and descriptive.
  • MR targeting the appropriate branch.
  • Latest Merge Result pipeline is green.
  • When ready for review, MR is marked as ready (not a draft) and a reviewer is requested. Pick the reviewer suggested by the reviewer roulette, or one of the project maintainers.

For GitLab team members

If you don't have access to this, the reviewer should trigger these jobs for you during the review process.

  • The manual Trigger:ee-package jobs have a green pipeline running against latest commit. Not applicable for a community contribution; a reviewer can trigger these if needed.
  • If config/software or config/patches directories are changed, make sure the build-package-on-all-os job within the Trigger:ee-package downstream pipeline succeeded. N/A: those directories are unchanged.
  • If you are changing anything SSL related, then the Trigger:package:fips manual job within the Trigger:ee-package downstream pipeline must succeed. N/A: not SSL-related.
  • If CI configuration is changed, the branch must be pushed to dev.gitlab.org to confirm regular branch builds aren't broken. N/A: CI configuration is unchanged.

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes.
  • Documentation created/updated. Short cluster.listen-address example in doc/settings/prometheus.md.
  • Tests added. ChefSpec coverage for empty, nil, and unset flags, plus '' overriding a computed default.
  • Integration tests added to GitLab QA. N/A: flag rendering is covered by ChefSpec.
  • Equivalent MR/issue for the GitLab Chart opened. N/A: this is the Omnibus flag helper.
  • Validate potential values for new configuration settings. Formats such as integer 10, duration 10s, URI scheme://user:passwd@host:port may require quotation or other special handling when rendered in a template and written to a configuration file. N/A: no new setting; empty string is now preserved as --flag=.

Reviewer checklist

  • As soon as you begin reviewing, select Start a review on your first comment so the MR shows Reviewer started review.
Edited by Priyanshu Jha

Merge request reports

Loading
Loading