Fix error logs in prometheus w/o prometheus annotations.

when pods have no prometheus annotation, and the prometheus
plugin is activated, for each pod that is found an error log
is generated indicating that:
File "/usr/local/lib/python2.7/site-packages/monasca_agent/common/../collector/checks_d/prometheus.py", line 276, in _get_prometheus_endpoint
    endpoints.append("{}/{}".format(ports[pod_index], prometheus_endpoint))
 TypeError: list indices must be integers, not str

The problem comes from the fact that the there are no endpoints
defined in the annotations, as well as that the reference on
line 276 should use an integer.

Story: 2001609
Task: 6570
Change-Id: I4ba0d41a6ff56885750894be2dc87ac1ee9168d0
This commit is contained in:
Nicolas Seyvet 2018-02-27 14:42:25 +01:00
parent e76cb28897
commit 4b11f413c2
1 changed files with 2 additions and 1 deletions

View File

@ -273,7 +273,7 @@ class Prometheus(checks.AgentCheck):
if len(ports) == 1 and not endpoints:
self.log.info("Could not find matching port using only port "
"configured")
endpoints.append("{}/{}".format(ports[pod_index], prometheus_endpoint))
endpoints.append("{}/{}".format(ports[0][pod_index], prometheus_endpoint))
if not endpoints:
self.log.error("Can not derive which port to use. Due to either "
@ -281,6 +281,7 @@ class Prometheus(checks.AgentCheck):
"configured and none of them selected via "
"configurations. "
"{} {} skipped for scraping".format(self.detect_method, name))
self.log.debug("Found prometheus endpoints '{}'".format(endpoints))
return endpoints
def _send_metrics(self, metric_families, dimensions, endpoint_whitelist, endpoint_metric_types,