From acf7986376b15729b9320e38ff0e737dcad5cb84 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Mon, 3 Jun 2019 12:33:53 +0000 Subject: [PATCH] Increase timeout, improve error logging --- CHANGES.md | 4 ++++ index.py | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9274e6b..8537500 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.1 +- improved error logging for HTTP requests +- increased timeout / retries to ~204 seconds + ## 0.9.0 - TEST mode to be enabled explictly via environment variable - optional ( enabled by default ) IAM account_id to alias lookup diff --git a/index.py b/index.py index ceeaecd..1b1a8bf 100644 --- a/index.py +++ b/index.py @@ -17,7 +17,7 @@ import boto3 __author__ = "Stefan Reimer" __author_email__ = "stefan@zero-downtime.net" -__version__ = "0.9.0" +__version__ = "0.9.1" # Global alias lookup cache account_aliases = {} @@ -34,7 +34,6 @@ def boolean(value): return False -# Decrypt encrypted URL with KMS def decrypt(encrypted): try: kms = boto3.client('kms') @@ -136,15 +135,16 @@ class Queue: while True: try: r = self.request.post(url=_url, data=msgpack.packb(self._queue), verify=self.verify_certs) - if r.status_code == 200: + if r: break + else: + logger.warning("HTTP Error: {}".format(r.status_code)) - # Log request exceptions, retry after except requests.RequestException as e: - logger.warning("Request exception: {}".format(e)) + logger.warning("RequestException: {}".format(e)) pass - if retries >= 5: + if retries >= 8: raise Exception("Error sending {} events to {}. Giving up.".format(events, _url)) retries = retries + 1 @@ -322,7 +322,7 @@ def handler(event, context): # cloudfront access logs if re.match('#Version:', first) and re.match('#Fields:', second): - logs = Queue("aws.cloudfront") + logs = Queue("aws.cloudfront_accesslog") with gzip.open(file_path, mode='rt', newline='\n') as data: next(data)