Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow longer lines before eliding #1197

Merged
merged 3 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
Expand Down
6 changes: 4 additions & 2 deletions client/src/balrogclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
import requests
import requests.auth

MAX_LOG_LINE_LENGTH = 10000
# Refresh the tokens 5 minutes before they expire
REFRESH_THRESHOLD = 5 * 60
_token_cache = {}


def _json_log_data(data):
log = json.dumps(data)
if len(log) > 100:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess maybe this should be a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

log = log[:80] + "<...{} characters elided ...>".format(len(log) - 80)
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


Expand Down
4 changes: 2 additions & 2 deletions client/tests/test_balrog_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...>"]