]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: using ip instead of short hostname for prometheus urls 49836/head
authorRedouane Kachach <rkachach@redhat.com>
Mon, 23 Jan 2023 12:22:27 +0000 (13:22 +0100)
committerRedouane Kachach <rkachach@redhat.com>
Wed, 25 Jan 2023 14:29:58 +0000 (15:29 +0100)
Fixes: https://tracker.ceph.com/issues/58548
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
src/cephadm/cephadm.py

index f19a7383e8b931f89eaaa71580973c01a739246c..ba34aa68fefe9fe0983a31609d8fb90c3bbf63a4 100755 (executable)
@@ -2036,6 +2036,15 @@ def get_fqdn():
     return socket.getfqdn() or socket.gethostname()
 
 
+def get_ip_addresses(hostname: str) -> Tuple[List[str], List[str]]:
+    items = socket.getaddrinfo(hostname, None,
+                               flags=socket.AI_CANONNAME,
+                               type=socket.SOCK_STREAM)
+    ipv4_addresses = [i[4][0] for i in items if i[0] == socket.AF_INET]
+    ipv6_addresses = [i[4][0] for i in items if i[0] == socket.AF_INET6]
+    return ipv4_addresses, ipv6_addresses
+
+
 def get_arch():
     # type: () -> str
     return platform.uname().machine
@@ -2705,6 +2714,13 @@ def get_daemon_args(ctx, fsid, daemon_type, daemon_id):
                 r += [f'--storage.tsdb.retention.size={retention_size}']
                 scheme = 'http'
                 host = get_fqdn()
+                # in case host is not an fqdn then we use the IP to
+                # avoid producing a broken web.external-url link
+                if '.' not in host:
+                    ipv4_addrs, ipv6_addrs = get_ip_addresses(get_hostname())
+                    # use the first ipv4 (if any) otherwise use the first ipv6
+                    addr = next(iter(ipv4_addrs or ipv6_addrs), None)
+                    host = wrap_ipv6(addr) if addr else host
                 r += [f'--web.external-url={scheme}://{host}:{port}']
         if daemon_type == 'alertmanager':
             config = get_parm(ctx.config_json)