]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: using ip instead of short hostname for prometheus urls 51212/head
authorRedouane Kachach <rkachach@redhat.com>
Mon, 23 Jan 2023 12:22:27 +0000 (13:22 +0100)
committerAdam King <adking@redhat.com>
Tue, 25 Apr 2023 16:45:36 +0000 (12:45 -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 8bd026abd23c234c3319f79476733e963c834492..61183e7611936f81de674f5f1a276c62bb89612b 100755 (executable)
@@ -1807,6 +1807,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
@@ -2388,6 +2397,13 @@ def get_daemon_args(ctx, fsid, daemon_type, daemon_id):
                 r += [f'--storage.tsdb.retention.time={retention_time}']
                 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)