From: Sebastian Wagner Date: Mon, 18 Oct 2021 13:04:46 +0000 (+0200) Subject: mgr/cephadm: Monitoring: Grafana: Fix IPv6 X-Git-Tag: v17.1.0~605^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bb2cb3ea3a9704cf124b5342fb2a974e8618cc01;p=ceph.git mgr/cephadm: Monitoring: Grafana: Fix IPv6 Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/cephadm/services/monitoring.py b/src/pybind/mgr/cephadm/services/monitoring.py index d86c5a8803a6..46af5b4727c3 100644 --- a/src/pybind/mgr/cephadm/services/monitoring.py +++ b/src/pybind/mgr/cephadm/services/monitoring.py @@ -2,6 +2,7 @@ import errno import logging import os from typing import List, Any, Tuple, Dict, Optional, cast +from urllib.parse import urlparse from mgr_module import HandleCommandResult @@ -32,7 +33,8 @@ class GrafanaService(CephadmService): assert dd.hostname is not None addr = dd.ip if dd.ip else self._inventory_get_addr(dd.hostname) port = dd.ports[0] if dd.ports else 9095 - prom_services.append(addr + ':' + str(port)) + prom_services.append(build_url(scheme='http', host=addr, port=port)) + deps.append(dd.name()) grafana_data_sources = self.mgr.template.render( 'services/grafana/ceph-dashboard.yml.j2', {'hosts': prom_services}) diff --git a/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 b/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 index 8946cac0a098..170e6f246f6d 100644 --- a/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 +++ b/src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2 @@ -1,17 +1,17 @@ # {{ cephadm_managed }} deleteDatasources: -{% for host in hosts %} +{% for host in hosts %} - name: 'Dashboard{{ loop.index }}' orgId: 1 {% endfor %} datasources: -{% for host in hosts %} +{% for host in hosts %} - name: 'Dashboard{{ loop.index }}' type: 'prometheus' access: 'proxy' orgId: 1 - url: 'http://{{ host }}' + url: '{{ host }}' basicAuth: false isDefault: {{ 'true' if loop.first else 'false' }} editable: false diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 7fe868392b4d..8b3721e20e34 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -98,6 +98,14 @@ def with_cephadm_module(module_options=None, store=None): 'modified': datetime_to_str(datetime_now()), 'fsid': 'foobar', }) + if '_ceph_get/mgr_map' not in store: + m.mock_store_set('_ceph_get', 'mgr_map', { + 'services': { + 'dashboard': 'http://[::1]:8080', + 'prometheus': 'http://[::1]:8081' + }, + 'modules': ['dashboard', 'prometheus'], + }) for k, v in store.items(): m._ceph_set_store(k, v) @@ -116,7 +124,7 @@ def wait(m, c): @contextmanager -def with_host(m: CephadmOrchestrator, name, addr='1.2.3.4', refresh_hosts=True): +def with_host(m: CephadmOrchestrator, name, addr='1::4', refresh_hosts=True): # type: (CephadmOrchestrator, str) -> None with mock.patch("cephadm.utils.resolve_ip", return_value=addr): wait(m, m.add_host(HostSpec(hostname=name))) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index de160df2cb9c..ec4657c18726 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -85,19 +85,19 @@ class TestCephadm(object): def test_host(self, cephadm_module): assert wait(cephadm_module, cephadm_module.get_hosts()) == [] with with_host(cephadm_module, 'test'): - assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1.2.3.4')] + assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1::4')] # Be careful with backward compatibility when changing things here: assert json.loads(cephadm_module.get_store('inventory')) == \ - {"test": {"hostname": "test", "addr": "1.2.3.4", "labels": [], "status": ""}} + {"test": {"hostname": "test", "addr": "1::4", "labels": [], "status": ""}} with with_host(cephadm_module, 'second', '1.2.3.5'): assert wait(cephadm_module, cephadm_module.get_hosts()) == [ - HostSpec('test', '1.2.3.4'), + HostSpec('test', '1::4'), HostSpec('second', '1.2.3.5') ] - assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1.2.3.4')] + assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1::4')] assert wait(cephadm_module, cephadm_module.get_hosts()) == [] @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]')) @@ -420,7 +420,7 @@ spec: with mock.patch("cephadm.module.CephadmOrchestrator.mon_command") as _mon_cmd: CephadmServe(cephadm_module)._check_daemons() _mon_cmd.assert_any_call( - {'prefix': 'dashboard set-grafana-api-url', 'value': 'https://1.2.3.4:3000'}, + {'prefix': 'dashboard set-grafana-api-url', 'value': 'https://[1::4]:3000'}, None) @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]')) @@ -950,7 +950,7 @@ spec: @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}')) @mock.patch("subprocess.run", None) @mock.patch("cephadm.module.CephadmOrchestrator.rados", mock.MagicMock()) - @mock.patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '1.2.3.4') + @mock.patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '1::4') def test_iscsi(self, cephadm_module): with with_host(cephadm_module, 'test'): ps = PlacementSpec(hosts=['test'], count=1) diff --git a/src/pybind/mgr/cephadm/tests/test_ssh.py b/src/pybind/mgr/cephadm/tests/test_ssh.py index 288217b7aea8..83690b207dfd 100644 --- a/src/pybind/mgr/cephadm/tests/test_ssh.py +++ b/src/pybind/mgr/cephadm/tests/test_ssh.py @@ -40,13 +40,13 @@ class TestWithSSH: assert "Host 'test' not found" in err out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json() - assert out == HostSpec('test', '1.2.3.4', status='Offline').to_json() + assert out == HostSpec('test', '1::4', status='Offline').to_json() asyncssh_connect.return_value = mock.MagicMock() asyncssh_connect.side_effect = None assert CephadmServe(cephadm_module)._check_host('test') is None out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json() - assert out == HostSpec('test', '1.2.3.4').to_json() + assert out == HostSpec('test', '1::4').to_json() @pytest.mark.skipif(ConnectionLost is not None, reason='asyncssh')