Increase timeout, improve error logging

This commit is contained in:
Stefan Reimer 2019-06-03 12:33:53 +00:00
parent dd1c72b2d5
commit acf7986376
2 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## 0.9.1
- improved error logging for HTTP requests
- increased timeout / retries to ~204 seconds
## 0.9.0 ## 0.9.0
- TEST mode to be enabled explictly via environment variable - TEST mode to be enabled explictly via environment variable
- optional ( enabled by default ) IAM account_id to alias lookup - optional ( enabled by default ) IAM account_id to alias lookup

View File

@ -17,7 +17,7 @@ import boto3
__author__ = "Stefan Reimer" __author__ = "Stefan Reimer"
__author_email__ = "stefan@zero-downtime.net" __author_email__ = "stefan@zero-downtime.net"
__version__ = "0.9.0" __version__ = "0.9.1"
# Global alias lookup cache # Global alias lookup cache
account_aliases = {} account_aliases = {}
@ -34,7 +34,6 @@ def boolean(value):
return False return False
# Decrypt encrypted URL with KMS
def decrypt(encrypted): def decrypt(encrypted):
try: try:
kms = boto3.client('kms') kms = boto3.client('kms')
@ -136,15 +135,16 @@ class Queue:
while True: while True:
try: try:
r = self.request.post(url=_url, data=msgpack.packb(self._queue), verify=self.verify_certs) r = self.request.post(url=_url, data=msgpack.packb(self._queue), verify=self.verify_certs)
if r.status_code == 200: if r:
break break
else:
logger.warning("HTTP Error: {}".format(r.status_code))
# Log request exceptions, retry after
except requests.RequestException as e: except requests.RequestException as e:
logger.warning("Request exception: {}".format(e)) logger.warning("RequestException: {}".format(e))
pass pass
if retries >= 5: if retries >= 8:
raise Exception("Error sending {} events to {}. Giving up.".format(events, _url)) raise Exception("Error sending {} events to {}. Giving up.".format(events, _url))
retries = retries + 1 retries = retries + 1
@ -322,7 +322,7 @@ def handler(event, context):
# cloudfront access logs # cloudfront access logs
if re.match('#Version:', first) and re.match('#Fields:', second): 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: with gzip.open(file_path, mode='rt', newline='\n') as data:
next(data) next(data)