Mercurial > hgrepos > Python > libs > ConfigMix
changeset 283:503768f91a05
More granular configuration of retrieving AWS metadata: retries with backoff setting
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 07 Dec 2020 01:51:24 +0100 |
| parents | da1596034954 |
| children | 4aaf74858d07 |
| files | configmix/extras/aws.py |
| diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/extras/aws.py Mon Dec 07 01:06:33 2020 +0100 +++ b/configmix/extras/aws.py Mon Dec 07 01:51:24 2020 +0100 @@ -15,6 +15,8 @@ import requests import requests.exceptions +import requests.adapters +import urllib3 _MARKER = object() @@ -24,7 +26,9 @@ URL_META_REGION = "http://169.254.169.254/latest/meta-data/placement/region" URL_META_AVAILABILITY_ZONE = "http://169.254.169.254/latest/meta-data/availability-zone" URL_DYN_INSTANCE_IDENTITY_DOC = "http://169.254.169.254/latest/dynamic/instance-identity/document" -TIMEOUT = 10 +TIMEOUT = 2 +# See https://gist.github.com/doublenns/7e3e4b72df4aaeccbeabf87ba767f44e +RETRIES = urllib3.Retry(total=3, backoff_factor=0.3) _meta_instanceid = None _meta_region = None @@ -35,6 +39,8 @@ def _get_text_req(url): with requests.Session() as sess: try: + a = requests.adapters.HTTPAdapter(max_retries=RETRIES) + sess.mount("http://", a) resp = sess.get(url, timeout=TIMEOUT) resp.raise_for_status() return resp.text @@ -45,6 +51,8 @@ def _get_json_req(url): with requests.Session() as sess: try: + a = requests.adapters.HTTPAdapter(max_retries=RETRIES) + sess.mount("http://", a) resp = sess.get(url, timeout=TIMEOUT) resp.raise_for_status() return resp.json()
