From de905a5c7dd6ae21685d170cca8ecdc1a8fc75d3 Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Fri, 14 Feb 2020 10:23:13 -0500 Subject: [PATCH 1/3] Allow longer lines before eliding --- client/src/balrogclient/api.py | 4 ++-- client/tests/test_balrog_api.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/balrogclient/api.py b/client/src/balrogclient/api.py index eb48501423..0081a0e918 100644 --- a/client/src/balrogclient/api.py +++ b/client/src/balrogclient/api.py @@ -16,8 +16,8 @@ def _json_log_data(data): log = json.dumps(data) - if len(log) > 100: - log = log[:80] + "<...{} characters elided ...>".format(len(log) - 80) + if len(log) > 10000: + log = log[:9980] + "<...{} characters elided ...>".format(len(log) - 9980) return log diff --git a/client/tests/test_balrog_api.py b/client/tests/test_balrog_api.py index 63edbb8186..936dbf3f67 100644 --- a/client/tests/test_balrog_api.py +++ b/client/tests/test_balrog_api.py @@ -26,7 +26,7 @@ def test_log_lines_truncated(caplog): caplog.set_level(logging.DEBUG) api = API(AUTH0_SECRETS, session=session) - api.do_request("https://api/", {"data": "a" * 100}, "GET") + api.do_request("https://api/", {"data": "a" * 11000}, "GET") logs = [message.split(": ", 1)[1] for message in caplog.messages if message.startswith("Data sent: ")] - assert logs == ['{"data": "' + "a" * 70 + "<...32 characters elided ...>"] + assert logs == ['{"data": "' + "a" * 9970 + "<...1032 characters elided ...>"] From e9240d17c264807e5ea902d45cacd2ce548f4df8 Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Fri, 14 Feb 2020 10:31:40 -0500 Subject: [PATCH 2/3] Version bump --- client/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/setup.py b/client/setup.py index b61deab3d8..e8551ce671 100755 --- a/client/setup.py +++ b/client/setup.py @@ -5,7 +5,7 @@ setup( name="balrogclient", - version="1.1.0", + version="1.1.1", description="Balrog Admin API Client", author="Mozilla Release Engineers", author_email="release+python@mozilla.com", From 22ba1062d9ae30410ebec5cd873313749a4a77a2 Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Thu, 20 Feb 2020 15:15:00 -0500 Subject: [PATCH 3/3] Make max line length a constant --- client/src/balrogclient/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/balrogclient/api.py b/client/src/balrogclient/api.py index 0081a0e918..b10ba55157 100644 --- a/client/src/balrogclient/api.py +++ b/client/src/balrogclient/api.py @@ -9,6 +9,7 @@ import requests import requests.auth +MAX_LOG_LINE_LENGTH = 10000 # Refresh the tokens 5 minutes before they expire REFRESH_THRESHOLD = 5 * 60 _token_cache = {} @@ -16,8 +17,9 @@ def _json_log_data(data): log = json.dumps(data) - if len(log) > 10000: - log = log[:9980] + "<...{} characters elided ...>".format(len(log) - 9980) + if len(log) > MAX_LOG_LINE_LENGTH: + slice_length = MAX_LOG_LINE_LENGTH - 20 + log = log[:slice_length] + "<...{} characters elided ...>".format(len(log) - slice_length) return log