From cb097946cfceb976870145da52546f93397a606a Mon Sep 17 00:00:00 2001 From: Matthew Oliver Date: Thu, 13 Aug 2020 10:41:44 +1000 Subject: [PATCH] prometheus: Properly split the port off IPv6 addresses 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 Fixes: https://tracker.ceph.com/issues/46846 (cherry picked from commit 985cce055bcee60b843806291458517c7ee890a3) --- src/pybind/mgr/prometheus/module.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 54c1c265a6f65..1200708ca7104 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -499,7 +499,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']) @@ -604,8 +604,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" -- 2.39.5