Skip to content

Commit

Permalink
AAP-36536 Send job_lifecycle logs to external loggers (#15701)
Browse files Browse the repository at this point in the history
* Send job_lifecycle logs to external loggers

* Include structured data in message

* Attach the organization_id of the job
  • Loading branch information
AlanCoding authored Dec 16, 2024
1 parent 86d2024 commit 36c75a2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion awx/main/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
register(
'LOG_AGGREGATOR_LOGGERS',
field_class=fields.StringListField,
default=['awx', 'activity_stream', 'job_events', 'system_tracking', 'broadcast_websocket'],
default=['awx', 'activity_stream', 'job_events', 'system_tracking', 'broadcast_websocket', 'job_lifecycle'],
label=_('Loggers Sending Data to Log Aggregator Form'),
help_text=_(
'List of loggers that will send HTTP logs to the collector, these can '
Expand All @@ -602,6 +602,7 @@
'job_events - callback data from Ansible job events\n'
'system_tracking - facts gathered from scan jobs\n'
'broadcast_websocket - errors pertaining to websockets broadcast metrics\n'
'job_lifecycle - logs related to processing of a job\n'
),
category=_('Logging'),
category_slug='logging',
Expand Down
2 changes: 1 addition & 1 deletion awx/main/models/unified_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ def log_lifecycle(self, state, blocked_by=None):
elif state == "execution_node_chosen":
extra["execution_node"] = self.execution_node or "NOT_SET"

logger_job_lifecycle.info(f"{msg} {json.dumps(extra)}")
logger_job_lifecycle.info(f"{msg} {json.dumps(extra)}", extra={'lifecycle_data': extra, 'organization_id': self.organization_id})

@property
def launched_by(self):
Expand Down
5 changes: 5 additions & 0 deletions awx/main/utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def reformat_data_for_log(self, raw_data, kind=None):
data = json.loads(data)
data_for_log = {}

# For the job_lifecycle logger, copy some raw data fields directly
for key in ('lifecycle_data', 'organization_id'):
if key in raw_data:
data_for_log[key] = raw_data[key]

if kind == 'job_events' and raw_data.get('python_objects', {}).get('job_event'):
job_event = raw_data['python_objects']['job_event']
guid = job_event.event_data.pop('guid', None)
Expand Down
2 changes: 1 addition & 1 deletion awx/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@
'awx.analytics': {'handlers': ['external_logger'], 'level': 'INFO', 'propagate': False},
'awx.analytics.broadcast_websocket': {'handlers': ['console', 'file', 'wsrelay', 'external_logger'], 'level': 'INFO', 'propagate': False},
'awx.analytics.performance': {'handlers': ['console', 'file', 'tower_warnings', 'external_logger'], 'level': 'DEBUG', 'propagate': False},
'awx.analytics.job_lifecycle': {'handlers': ['console', 'job_lifecycle'], 'level': 'DEBUG', 'propagate': False},
'awx.analytics.job_lifecycle': {'handlers': ['console', 'job_lifecycle', 'external_logger'], 'level': 'DEBUG', 'propagate': False},
'social': {'handlers': ['console', 'file', 'tower_warnings'], 'level': 'DEBUG'},
'system_tracking_migrations': {'handlers': ['console', 'file', 'tower_warnings'], 'level': 'DEBUG'},
'rbac_migrations': {'handlers': ['console', 'file', 'tower_warnings'], 'level': 'DEBUG'},
Expand Down
3 changes: 2 additions & 1 deletion tools/docker-compose/docs/logstash.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ authentication set up inside of the logstash configuration file).
"awx",
"activity_stream",
"job_events",
"system_tracking"
"system_tracking",
"job_lifecycle"
],
"LOG_AGGREGATOR_INDIVIDUAL_FACTS": false,
"LOG_AGGREGATOR_TOWER_UUID": "991ac7e9-6d68-48c8-bbde-7ca1096653c6",
Expand Down

0 comments on commit 36c75a2

Please sign in to comment.