]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
prometheus: Properly split the port off IPv6 addresses 36594/head
authorMatthew Oliver <moliver@suse.com>
Thu, 13 Aug 2020 00:41:44 +0000 (10:41 +1000)
committerMatthew Oliver <moliver@suse.com>
Thu, 13 Aug 2020 00:41:44 +0000 (10:41 +1000)
The Prometheus module when splitting the port nubmer for public and
client networks/ips doesn't take IPv6 addresses into account.

This patch fixes this by using `rsplit(':', 1)` rather then `split(':')`
which leads to bugs like:

  curl --silent http://localhost:9283/metrics | grep ceph_mon_metadata{
  ceph_mon_metadata{ceph_daemon="mon.mon2",hostname="mon2.example.net",public_addr="[2001",rank="0",ceph_version="ceph version 15.2.4 (7447c15c6ff58d7fce91843b705a268a1917325c) octopus (stable)"} 1.0

Note the public_addr above being split at the first ':' of an IPv6
address.

Signed-off-by: Matthew Oliver <moliver@suse.com>
Fixes: https://tracker.ceph.com/issues/46846
src/pybind/mgr/prometheus/module.py

index 83fe6c3af0ca6ac6e1ef4ae40defbaf0866e0831..e9c734b8f8a99240079532c6b1a77847a9a57520 100644 (file)
@@ -510,7 +510,7 @@ class Module(MgrModule):
             host_version = servers.get((id_, 'mon'), ('', ''))
             self.metrics['mon_metadata'].set(1, (
                 'mon.{}'.format(id_), host_version[0],
-                mon['public_addr'].split(':')[0], rank,
+                mon['public_addr'].rsplit(':', 1)[0], rank,
                 host_version[1]
             ))
             in_quorum = int(rank in mon_status['quorum'])
@@ -619,8 +619,8 @@ class Module(MgrModule):
             # id can be used to link osd metrics and metadata
             id_ = osd['osd']
             # collect osd metadata
-            p_addr = osd['public_addr'].split(':')[0]
-            c_addr = osd['cluster_addr'].split(':')[0]
+            p_addr = osd['public_addr'].rsplit(':', 1)[0]
+            c_addr = osd['cluster_addr'].rsplit(':', 1)[0]
             if p_addr == "-" or c_addr == "-":
                 self.log.info(
                     "Missing address metadata for osd {0}, skipping occupation"