]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: using ip instead of short hostname for prometheus urls 50905/head
authorRedouane Kachach <rkachach@redhat.com>
Mon, 23 Jan 2023 12:22:27 +0000 (13:22 +0100)
committerAdam King <adking@redhat.com>
Wed, 5 Apr 2023 19:54:18 +0000 (15:54 -0400)
Fixes: https://tracker.ceph.com/issues/58548
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
(cherry picked from commit f56b131c804327411a1ae3cb68042f182f42996e)

src/cephadm/cephadm

index dbe2e639b661455d16e4dcd0a1bb5695d64d2876..ce63bec55c4ac0319d98e7d93e0dacd2cee584d6 100755 (executable)
@@ -2004,6 +2004,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
@@ -2671,6 +2680,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)