From 2b4b7c43e95acfaaa838f13a600f08adc1589958 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Tue, 10 May 2022 15:25:54 +0200 Subject: [PATCH] cephadm: prometheus: The generatorURL in alerts is only using hostname Prometheus is currently using only the hostname in the 'generatorURL' of an alert which causes issues when clicking on the URL in the Ceph Dashboard or somewhere else, because in most cases the hostname of the node that is running the Prometheus container is not resolvable. To fix that the command line argument '--web.external-url' must be appended in the systemd unit file of the Prometheus container, e.g. '--web.external-url http://foo.bar:9095' whereas a FQDN hostname is used. Fixes: https://tracker.ceph.com/issues/55595 Signed-off-by: Volker Theile (cherry picked from commit 4281dc1bbc466dd061781a984b34bb0eafaf482f) --- src/cephadm/cephadm | 4 ++++ src/cephadm/tests/test_cephadm.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 7b8ea349aa393..f7229a3cacd57 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -2544,6 +2544,10 @@ def get_daemon_args(ctx, fsid, daemon_type, daemon_id): if 'ports' in meta and meta['ports']: port = meta['ports'][0] r += [f'--web.listen-address={ip}:{port}'] + if daemon_type == 'prometheus': + scheme = 'http' + host = get_fqdn() + r += [f'--web.external-url={scheme}://{host}:{port}'] if daemon_type == 'alertmanager': config = get_parm(ctx.config_json) peers = config.get('peers', list()) # type: ignore diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 0aa99de8b33b1..bcfc0200e60bb 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1079,6 +1079,14 @@ class TestMonitoring(object): version = cd.Monitoring.get_version(ctx, 'container_id', daemon_type) assert version == '0.16.1' + def test_prometheus_external_url(self): + ctx = cd.CephadmContext() + daemon_type = 'prometheus' + daemon_id = 'home' + fsid = 'aaf5a720-13fe-4a3b-82b9-2d99b7fd9704' + args = cd.get_daemon_args(ctx, fsid, daemon_type, daemon_id) + assert any([x.startswith('--web.external-url=http://') for x in args]) + @mock.patch('cephadm.call') def test_get_version_node_exporter(self, _call): ctx = cd.CephadmContext() -- 2.39.5