Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
fix(app) add retries for request metrics api
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc committed Oct 5, 2018
1 parent 0b27dc2 commit fa09ce8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa09ce8

Please # to comment.