From 4b11f413c2185bbdf037fc381d01910c008a0b31 Mon Sep 17 00:00:00 2001 From: Nicolas Seyvet Date: Tue, 27 Feb 2018 14:42:25 +0100 Subject: [PATCH] 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 --- monasca_agent/collector/checks_d/prometheus.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monasca_agent/collector/checks_d/prometheus.py b/monasca_agent/collector/checks_d/prometheus.py index 07ee4223..53aa6d10 100644 --- a/monasca_agent/collector/checks_d/prometheus.py +++ b/monasca_agent/collector/checks_d/prometheus.py @@ -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,