From d06ce8f9119267862fcca00fc85af3a9f323d61c Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Mon, 25 Mar 2024 16:01:53 -0400 Subject: [PATCH] Remove json formatter for job lifecycle * We didn't really make use of json formatting across the app. Remove the special case json formatter. Instead, output all of the meta-data associated with a job lifecycle event every time. Before, we tried to only output this extra meta data when in DEBUG mode. It turns out this information is smaller than we thought and more useful than we thought so always output it. --- awx/main/models/unified_jobs.py | 3 ++- awx/main/utils/formatters.py | 10 ---------- awx/settings/defaults.py | 3 +-- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index a169feec25..0f70dc50fb 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -1599,7 +1599,8 @@ class UnifiedJob( extra["controller_node"] = self.controller_node or "NOT_SET" elif state == "execution_node_chosen": extra["execution_node"] = self.execution_node or "NOT_SET" - logger_job_lifecycle.info(msg, extra=extra) + + logger_job_lifecycle.info(f"{msg} {json.dumps(extra)}") @property def launched_by(self): diff --git a/awx/main/utils/formatters.py b/awx/main/utils/formatters.py index 48edd56f65..5b6b5d785d 100644 --- a/awx/main/utils/formatters.py +++ b/awx/main/utils/formatters.py @@ -3,7 +3,6 @@ from copy import copy import json -import json_log_formatter import logging import traceback import socket @@ -15,15 +14,6 @@ from django.core.serializers.json import DjangoJSONEncoder from django.conf import settings -class JobLifeCycleFormatter(json_log_formatter.JSONFormatter): - def json_record(self, message: str, extra: dict, record: logging.LogRecord): - if 'time' not in extra: - extra['time'] = now() - if record.exc_info: - extra['exc_info'] = self.formatException(record.exc_info) - return extra - - class TimeFormatter(logging.Formatter): """ Custom log formatter used for inventory imports diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 3ad62ca8b2..2ff82d7fc5 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -849,7 +849,6 @@ LOGGING = { 'json': {'()': 'awx.main.utils.formatters.LogstashFormatter'}, 'timed_import': {'()': 'awx.main.utils.formatters.TimeFormatter', 'format': '%(relativeSeconds)9.3f %(levelname)-8s %(message)s'}, 'dispatcher': {'format': '%(asctime)s %(levelname)-8s [%(guid)s] %(name)s PID:%(process)d %(message)s'}, - 'job_lifecycle': {'()': 'awx.main.utils.formatters.JobLifeCycleFormatter'}, }, # Extended below based on install scenario. You probably don't want to add something directly here. # See 'handler_config' below. @@ -917,7 +916,7 @@ handler_config = { 'wsrelay': {'filename': 'wsrelay.log'}, 'task_system': {'filename': 'task_system.log'}, 'rbac_migrations': {'filename': 'tower_rbac_migrations.log'}, - 'job_lifecycle': {'filename': 'job_lifecycle.log', 'formatter': 'job_lifecycle'}, + 'job_lifecycle': {'filename': 'job_lifecycle.log'}, 'rsyslog_configurer': {'filename': 'rsyslog_configurer.log'}, 'cache_clear': {'filename': 'cache_clear.log'}, 'ws_heartbeat': {'filename': 'ws_heartbeat.log'},