Skip to content

Commit

Permalink
Merge pull request #305 from rollbar/request-pool-size
Browse files Browse the repository at this point in the history
Allow the request pool to be configured
  • Loading branch information
waltjones authored Apr 3, 2020
2 parents 75a5be6 + 38d668c commit 346a00d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions rollbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def _get_pylons_request():
'http_proxy_user': None,
'http_proxy_password': None,
'include_request_body': False,
'request_pool_connections': None,
'request_pool_maxsize': None,
'request_max_retries': None,
}

_CURRENT_LAMBDA_CONTEXT = None
Expand Down Expand Up @@ -319,6 +322,7 @@ def init(access_token, environment='production', scrub_fields=None, url_fields=N

SETTINGS['access_token'] = access_token
SETTINGS['environment'] = environment
_configure_transport(**SETTINGS)

if SETTINGS.get('allow_logging_basic_config'):
logging.basicConfig()
Expand Down Expand Up @@ -370,6 +374,20 @@ def init(access_token, environment='production', scrub_fields=None, url_fields=N
_initialized = True


def _configure_transport(**kw):
configuration = _requests_configuration(**kw)
transport.configure_pool(**configuration)


def _requests_configuration(**kw):
keys = {
'request_pool_connections': 'pool_connections',
'request_pool_maxsize': 'pool_maxsize',
'request_max_retries': 'max_retries',
}
return {keys[k]: kw.get(k, None) for k in keys}


def lambda_function(f):
"""
Decorator for making error handling on AWS Lambda easier
Expand Down
13 changes: 12 additions & 1 deletion rollbar/lib/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def _get_proxy_cfg(kw):
}


def configure_pool(**kw):
keys = ['pool_connections', 'pool_maxsize', 'max_retries']
args = {k: kw[k] for k in keys if kw.get(k, None) is not None}
if len(args) == 0:
return
https_adapter = requests.adapters.HTTPAdapter(**args)
http_adapter = requests.adapters.HTTPAdapter(**args)
_session().mount('https://', https_adapter)
_session().mount('http://', http_adapter)


def post(*args, **kw):
proxies = _get_proxy_cfg(kw)
return _session().post(*args, proxies=proxies, **kw)
Expand All @@ -38,4 +49,4 @@ def get(*args, **kw):
return _session().get(*args, proxies=proxies, **kw)


__all__ = ['post', 'get']
__all__ = ['post', 'get', 'configure_pool']

0 comments on commit 346a00d

Please sign in to comment.