From bfc507a654f35add01cdec75391ee6efba608a46 Mon Sep 17 00:00:00 2001 From: Ryan Lanny Jenkins Date: Wed, 2 Dec 2020 15:05:44 -0600 Subject: [PATCH] Reduce default read/connect timeouts, made them configurable. --- setup.py | 2 +- src/ss_instrumentation/SSInstrumentation.py | 4 ++-- test/SSInstrumentation.py | 25 +++++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 9715549..9ee26eb 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ ) setup(name='ss_instrumentation', - version='1.2.0', + version='1.2.3', description='', url='https://github.com/styleseat/ss-instrumentation', author='Some Dude at StyleSeat', diff --git a/src/ss_instrumentation/SSInstrumentation.py b/src/ss_instrumentation/SSInstrumentation.py index 5f19337..22591c3 100644 --- a/src/ss_instrumentation/SSInstrumentation.py +++ b/src/ss_instrumentation/SSInstrumentation.py @@ -113,8 +113,8 @@ class SSInstrumentation(object): def __init__(self, config, storage=None): self.namespace = config['AWS_METRIC_NAMESPACE'] self.client = boto3.client('cloudwatch', config=Config( - connect_timeout=3, - read_timeout=3, + connect_timeout=config.get('BOTO_CONNECT_TIMEOUT', 1), + read_timeout=config.get('BOTO_READ_TIMEOUT', 1), retries={'max_attempts': 0}, region_name=config['AWS_LOGGING_REGION'] )) diff --git a/test/SSInstrumentation.py b/test/SSInstrumentation.py index d0aa12d..979f9e9 100644 --- a/test/SSInstrumentation.py +++ b/test/SSInstrumentation.py @@ -24,11 +24,12 @@ def wrapper(*args, **kwargs): @freeze_time('1984-08-06') class TestSSInstrumenation(object): - def create_instr(self): + def create_instr(self, config_override={}): config = { 'AWS_METRIC_NAMESPACE': 'FizzBuzzAsAService', 'AWS_LOGGING_REGION': 'us-west-2', } + config.update(config_override) return SSInstrumentation(config) @@ -52,13 +53,29 @@ def assert_metric_present(self, actual_metrics, expected_metric): @mock.patch('boto3.client') def test_client_config(self, mock_client_constructor): self.create_instr() - client_name, config = mock_client_constructor.call_args.args + client_name = mock_client_constructor.call_args.args[0] + config = mock_client_constructor.call_args.kwargs['config'] assert client_name == 'cloudwatch' - assert config.connect_timeout == 3 - assert config.read_timeout == 3 + assert config.connect_timeout == 1 + assert config.read_timeout == 1 assert config.retries['max_attempts'] == 0 assert config.region_name == 'us-west-2' + @mock.patch('boto3.client') + def test_custom_client_config(self, mock_client_constructor): + self.create_instr({ + 'BOTO_CONNECT_TIMEOUT': 42, + 'BOTO_READ_TIMEOUT': 7, + 'AWS_LOGGING_REGION': 'us-east-1' + }) + client_name = mock_client_constructor.call_args.args[0] + config = mock_client_constructor.call_args.kwargs['config'] + assert client_name == 'cloudwatch' + assert config.connect_timeout == 42 + assert config.read_timeout == 7 + assert config.retries['max_attempts'] == 0 + assert config.region_name == 'us-east-1' + @standard_mock def test_put_metric(self, mock_client): instr = self.create_instr()