From e0e62d2ea336b8d91778af53b96ab3ff15358637 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Fri, 17 Jun 2022 13:11:22 +0200 Subject: [PATCH 1/2] Logging: reduce log verbosity Reduce logging level on some logs that are not that relevant anymore. --- readthedocs/builds/tasks.py | 19 +++++++++++++------ readthedocs/proxito/middleware.py | 2 +- readthedocs/proxito/views/utils.py | 6 +++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/readthedocs/builds/tasks.py b/readthedocs/builds/tasks.py index 41b31d02aac..185dc70231e 100644 --- a/readthedocs/builds/tasks.py +++ b/readthedocs/builds/tasks.py @@ -210,12 +210,19 @@ def archive_builds_task(self, days=14, limit=200, delete=False): commands = BuildCommandSerializer(build.commands, many=True).data if commands: for cmd in commands: - if len(cmd['output']) > MAX_BUILD_COMMAND_SIZE: - cmd['output'] = cmd['output'][-MAX_BUILD_COMMAND_SIZE:] - cmd['output'] = "... (truncated) ...\n\nCommand output too long. Truncated to last 1MB.\n\n" + cmd['output'] # noqa - log.warning('Truncating build command for build.', build_id=build.id) - output = BytesIO(json.dumps(commands).encode('utf8')) - filename = '{date}/{id}.json'.format(date=str(build.date.date()), id=build.id) + if len(cmd["output"]) > MAX_BUILD_COMMAND_SIZE: + cmd["output"] = cmd["output"][-MAX_BUILD_COMMAND_SIZE:] + cmd["output"] = ( + "... (truncated) ...\n\nCommand output too long. Truncated to last 1MB.\n\n" + + cmd["output"] + ) # noqa + log.debug( + "Truncating build command for build.", build_id=build.id + ) + output = BytesIO(json.dumps(commands).encode("utf8")) + filename = "{date}/{id}.json".format( + date=str(build.date.date()), id=build.id + ) try: build_commands_storage.save(name=filename, content=output) if delete: diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py index 92785ed2b9b..2e7954fbf93 100644 --- a/readthedocs/proxito/middleware.py +++ b/readthedocs/proxito/middleware.py @@ -313,7 +313,7 @@ def process_request(self, request): # noqa try: project = Project.objects.get(slug=request.host_project_slug) except Project.DoesNotExist: - log.warning('No host_project_slug set on project') + log.debug("No host_project_slug set on project") return None # This is hacky because Django wants a module for the URLConf, diff --git a/readthedocs/proxito/views/utils.py b/readthedocs/proxito/views/utils.py index 5d6a8fbcf24..81c20632f04 100644 --- a/readthedocs/proxito/views/utils.py +++ b/readthedocs/proxito/views/utils.py @@ -1,6 +1,6 @@ import os -import structlog +import structlog from django.http import HttpResponse from django.shortcuts import get_object_or_404, render @@ -60,8 +60,8 @@ def _get_project_data_from_request( if lang_slug and version_slug: filename = os.path.join(lang_slug, version_slug, filename) log.warning( - 'URL looks like versioned on a single version project.' - 'Changing filename to match.', + "URL looks like versioned on a single version project. " + "Changing filename to match.", filename=filename, ) lang_slug = version_slug = None From f7bfbd639ad4cb119c4a9d007a50f7e1f60ee068 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 20 Jun 2022 20:15:40 +0200 Subject: [PATCH 2/2] Lint --- readthedocs/builds/tasks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/readthedocs/builds/tasks.py b/readthedocs/builds/tasks.py index 185dc70231e..2317dd3a06e 100644 --- a/readthedocs/builds/tasks.py +++ b/readthedocs/builds/tasks.py @@ -213,8 +213,11 @@ def archive_builds_task(self, days=14, limit=200, delete=False): if len(cmd["output"]) > MAX_BUILD_COMMAND_SIZE: cmd["output"] = cmd["output"][-MAX_BUILD_COMMAND_SIZE:] cmd["output"] = ( - "... (truncated) ...\n\nCommand output too long. Truncated to last 1MB.\n\n" - + cmd["output"] + "\n\n" + "... (truncated) ..." + "\n\n" + "Command output too long. Truncated to last 1MB." + "\n\n" + cmd["output"] ) # noqa log.debug( "Truncating build command for build.", build_id=build.id