From ab2f897eded3c6fd4d15734cfe9f09daea8c1ab4 Mon Sep 17 00:00:00 2001 From: Thiago Freitas Date: Tue, 9 Oct 2018 16:46:28 -0300 Subject: [PATCH] fix(app) fix request.get problem (#11) * chore(deploy) adjust image version * fix(app) add retries for request metrics api --- app.py | 13 +++++++++++-- deploy/deployment-metrics-server-exporter.yaml | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 904783d..b36f765 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,9 @@ import time import string +from requests.adapters import HTTPAdapter +from requests.packages.urllib3.util.retry import Retry + from prometheus_client import Metric, start_http_server from prometheus_client.core import REGISTRY @@ -33,9 +36,15 @@ def set_token(self): def kube_metrics(self): headers = { "Authorization": "Bearer {}".format(self.token) } + session = requests.Session() + retry = Retry(connect=3, backoff_factor=0.1) + adapter = HTTPAdapter(max_retries=retry) + session.mount('http://', adapter) + session.mount('https://', adapter) + payload = { - 'nodes': requests.get(self.api_nodes_url, headers=headers, verify=False), - 'pods': requests.get(self.api_pods_url, headers=headers, verify=False) + 'nodes': session.get(self.api_nodes_url, headers=headers, verify=False), + 'pods': session.get(self.api_pods_url, headers=headers, verify=False) } return payload diff --git a/deploy/deployment-metrics-server-exporter.yaml b/deploy/deployment-metrics-server-exporter.yaml index 349b7a3..e7f75d6 100644 --- a/deploy/deployment-metrics-server-exporter.yaml +++ b/deploy/deployment-metrics-server-exporter.yaml @@ -24,7 +24,7 @@ spec: serviceAccountName: metrics-server-exporter containers: - name: metrics-server-exporter - image: vivareal/metrics-server-exporter:v0.0.2 + image: vivareal/metrics-server-exporter:v0.0.3 imagePullPolicy: IfNotPresent ports: - containerPort: 8000