]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: Monitoring: Grafana: Fix IPv6
authorSebastian Wagner <sewagner@redhat.com>
Mon, 18 Oct 2021 13:04:46 +0000 (15:04 +0200)
committerSebastian Wagner <sewagner@redhat.com>
Mon, 18 Oct 2021 13:04:46 +0000 (15:04 +0200)
Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
src/pybind/mgr/cephadm/services/monitoring.py
src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2
src/pybind/mgr/cephadm/tests/fixtures.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/cephadm/tests/test_ssh.py

index d86c5a8803a6dd33553bdea3d79663aa23776f35..46af5b4727c34da6092d65499a1835eea58d5899 100644 (file)
@@ -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})
index 8946cac0a09895c919636bd57179d0644c55cbca..170e6f246f6df6f40b37c705c2c1541913b5ef11 100644 (file)
@@ -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
index 7fe868392b4dedea12ab3b9f5023ae232353da28..8b3721e20e342d47c01d7b23eb7007d27af52730 100644 (file)
@@ -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)))
index de160df2cb9ca54c74ce8cc264a4a6f925a4ae0b..ec4657c1872628935d4d9b7fab618dcdcb7aaea9 100644 (file)
@@ -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)
index 288217b7aea84c9cfd7e07d78b7855f0b1ad8cd4..83690b207dfdd39c20d019b6a203171b2db821a0 100644 (file)
@@ -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')