Fix Prometheus metrics endpoint scanning
Fix bug where it was failing to determine the right metrics endpoint. I was seeing messages like the below: Could not get metrics from http://172.17.0.5:r with error ... The problem was the += of a string to an array which caused the string to be split into characters. This fixes the issue by using append instead of += Change-Id: I3e2996077e8013819a47aa868f0e8653892aadfe
This commit is contained in:
parent
2e5c6475e7
commit
8a09ee6517
|
@ -191,19 +191,20 @@ class Prometheus(checks.AgentCheck):
|
|||
if self.detect_method == "pod" and not configured_ports:
|
||||
configured_ports = [9102]
|
||||
prometheus_endpoint = annotations.get("prometheus.io/path", "/metrics")
|
||||
prometheus_endpoint = prometheus_endpoint.lstrip('/')
|
||||
|
||||
endpoints = []
|
||||
for port in ports:
|
||||
for configured_port in configured_ports:
|
||||
if port[pod_index] == configured_port:
|
||||
# Build up list of ports and prometheus endpoints to return
|
||||
endpoints += "{}/{}".format(configured_port,
|
||||
prometheus_endpoint)
|
||||
endpoints.append("{}/{}".format(configured_port,
|
||||
prometheus_endpoint))
|
||||
|
||||
if len(ports) == 1 and not endpoints:
|
||||
self.log.info("Could not find matching port using only port "
|
||||
"configured")
|
||||
endpoints += "{}/{}".format(ports[pod_index], prometheus_endpoint)
|
||||
endpoints.append("{}/{}".format(ports[pod_index], prometheus_endpoint))
|
||||
|
||||
if not endpoints:
|
||||
self.log.error("Can not derive which port to use. Due to more "
|
||||
|
|
Loading…
Reference in New Issue