From fa09ce863c3ae6b5a1e0cf9fb78d595bb5a5be41 Mon Sep 17 00:00:00 2001 From: Thiago Freitas Date: Fri, 5 Oct 2018 13:29:26 -0300 Subject: [PATCH] fix(app) add retries for request metrics api --- app.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 904783d..bb7c265 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.5) + 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