Handle IPv6 address for prometheus_listen_addresses
In case prometheus uses IPv6 address, the option may contain multiple ':' (eg. [::1]:9101 ). Change-Id: Ie2129b2d079c430f81cf557a301666f3a658f57a
This commit is contained in:
parent
b9c987ee75
commit
88b5c87a30
@ -32,6 +32,7 @@ from keystoneauth1 import exceptions as ka_exceptions
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import timeutils
|
||||
from stevedore import extension
|
||||
from tooz import coordination
|
||||
@ -466,9 +467,10 @@ class AgentManager(cotyledon.Service):
|
||||
|
||||
if self.conf.polling.enable_prometheus_exporter:
|
||||
for addr in self.conf.polling.prometheus_listen_addresses:
|
||||
address = addr.split(":")
|
||||
if len(address) == 2:
|
||||
prom_exporter.export(address[0], address[1])
|
||||
address = netutils.parse_host_port(addr)
|
||||
if address[0] is None or address[1] is None:
|
||||
LOG.warning('Ignoring invalid address: %s', addr)
|
||||
prom_exporter.export(address[0], address[1])
|
||||
|
||||
self._keystone = None
|
||||
self._keystone_last_exception = None
|
||||
|
@ -20,7 +20,7 @@ CEILOMETER_REGISTRY = prom.CollectorRegistry()
|
||||
|
||||
|
||||
def export(prometheus_iface, prometheus_port):
|
||||
prom.start_http_server(port=int(prometheus_port),
|
||||
prom.start_http_server(port=prometheus_port,
|
||||
addr=prometheus_iface,
|
||||
registry=CEILOMETER_REGISTRY)
|
||||
|
||||
|
@ -170,13 +170,19 @@ class TestPromExporter(base.BaseTestCase):
|
||||
def test_export_called(self, export):
|
||||
CONF = service.prepare_service([], [])
|
||||
CONF.polling.enable_prometheus_exporter = True
|
||||
CONF.polling.prometheus_listen_addresses = ['127.0.0.1:9101',
|
||||
'127.0.0.1:9102']
|
||||
CONF.polling.prometheus_listen_addresses = [
|
||||
'127.0.0.1:9101',
|
||||
'127.0.0.1:9102',
|
||||
'[::1]:9103',
|
||||
'localhost:9104',
|
||||
]
|
||||
manager.AgentManager(0, CONF)
|
||||
|
||||
export.assert_has_calls([
|
||||
call('127.0.0.1', '9101'),
|
||||
call('127.0.0.1', '9102')
|
||||
call('127.0.0.1', 9101),
|
||||
call('127.0.0.1', 9102),
|
||||
call('::1', 9103),
|
||||
call('localhost', 9104),
|
||||
])
|
||||
|
||||
def test_collect_metrics(self):
|
||||
|
Loading…
Reference in New Issue
Block a user