Reduce client & cluster logs upon requests

Change-Id: I333769380edb41e283c13e1ca78f3a5f956e610e
This commit is contained in:
asarfaty 2020-08-06 10:11:17 +02:00 committed by Adit Sarfaty
parent fbdeaecb53
commit 0b52a1b74e
2 changed files with 22 additions and 14 deletions

View File

@ -251,25 +251,24 @@ class RESTClient(object):
request_headers.update(inject_headers)
request_url = self._build_url(url)
do_request = getattr(self._conn, method.lower())
if not silent:
LOG.debug("REST call: %s %s. Headers: %s. Body: %s",
method, request_url,
utils.censor_headers(request_headers),
self._mask_password(body))
if silent:
self._conn.set_silent(True)
ts = time.time()
result = do_request(
request_url,
data=body,
headers=request_headers)
te = time.time()
if silent:
self._conn.set_silent(False)
if not silent:
LOG.debug("REST call: %s %s. Response: %s. Took %2.4f",
LOG.debug("REST call: %s %s. Headers: %s. Body: %s. Response: %s. "
"Took %2.4f",
method, request_url,
utils.censor_headers(request_headers),
self._mask_password(body),
result.json() if result.content else '',
te - ts)

View File

@ -85,6 +85,7 @@ class TimeoutSession(requests.Session):
self.timeout = timeout
self.read_timeout = read_timeout
self.cert_provider = None
self._silent = False
super(TimeoutSession, self).__init__()
@property
@ -95,6 +96,9 @@ class TimeoutSession(requests.Session):
def cert_provider(self, value):
self._cert_provider = value
def set_silent(self, silent_mode):
self._silent = silent_mode
# wrapper timeouts at the session level
# see: https://goo.gl/xNk7aM
def request(self, *args, **kwargs):
@ -441,6 +445,7 @@ class ClusteredAPI(object):
self._http_provider = http_provider
self._keepalive_interval = keepalive_interval
self._print_keepalive = 0
self._silent = False
def _init_cluster(*args, **kwargs):
self._init_endpoints(providers, min_conns_per_pool,
@ -454,6 +459,9 @@ class ClusteredAPI(object):
# loops + state
self._reinit_cluster = _init_cluster
def set_silent(self, silent_mode):
self._silent = silent_mode
def _init_endpoints(self, providers, min_conns_per_pool,
max_conns_per_pool, api_rate_limit, api_rate_mode):
LOG.debug("Initializing API endpoints")
@ -722,10 +730,11 @@ class ClusteredAPI(object):
if conn.default_headers:
kwargs['headers'] = kwargs.get('headers', {})
kwargs['headers'].update(conn.default_headers)
LOG.debug("API cluster proxy %s %s to %s with %s. "
"Waited conn: %2.4f, rate: %2.4f",
proxy_for.upper(), uri, url, kwargs,
conn_data.conn_wait, conn_data.rate_wait)
if not self._silent:
LOG.debug("API cluster proxy %s %s to %s with %s. "
"Waited conn: %2.4f, rate: %2.4f",
proxy_for.upper(), uri, url, kwargs,
conn_data.conn_wait, conn_data.rate_wait)
# call the actual connection method to do the
# http request/response over the wire
@ -756,7 +765,7 @@ class ClusteredAPI(object):
raise e
# Returning the exception instead of raising it will cause
# decarator to retry. If retry attempts is exceeded, this
# decorator to retry. If retry attempts is exceeded, this
# same exception will be raised due to overriden reraise
# method of RetryAttemptsExceeded
return e