From 9e30f004d3613ace13586beb65cc60ac0dcb8e30 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 20 Apr 2020 16:38:05 -0400 Subject: [PATCH] let users configure the destination and max disk size of rsyslogd spool --- awx/main/conf.py | 23 +++++++++++++++++++++++ awx/main/utils/external_logging.py | 10 +++++++++- awx/settings/defaults.py | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/awx/main/conf.py b/awx/main/conf.py index ce6b33217c..b9fb5706bc 100644 --- a/awx/main/conf.py +++ b/awx/main/conf.py @@ -787,6 +787,29 @@ register( category=_('Logging'), category_slug='logging', ) +register( + 'LOG_AGGREGATOR_MAX_DISK_USAGE_GB', + field_class=fields.IntegerField, + default=1, + min_value=1, + label=_('Maximum disk persistance for external log aggregation (in GB)'), + help_text=_('Amount of data to store (in gigabytes) during an outage of ' + 'the external log aggregator (defaults to 1). ' + 'Equivalent to the rsyslogd queue.maxdiskspace setting.'), + category=_('Logging'), + category_slug='logging', +) +register( + 'LOG_AGGREGATOR_MAX_DISK_USAGE_PATH', + field_class=fields.CharField, + default='/var/lib/awx', + label=_('File system location for rsyslogd disk persistence'), + help_text=_('Location to persist logs that should be retried after an outage ' + 'of the external log aggregator (defaults to /var/lib/awx). ' + 'Equivalent to the rsyslogd queue.spoolDirectory setting.'), + category=_('Logging'), + category_slug='logging', +) register( diff --git a/awx/main/utils/external_logging.py b/awx/main/utils/external_logging.py index 32b67542a8..9b2e7f9fdf 100644 --- a/awx/main/utils/external_logging.py +++ b/awx/main/utils/external_logging.py @@ -1,3 +1,5 @@ +import os + import urllib.parse as urlparse from django.conf import settings @@ -13,12 +15,18 @@ def construct_rsyslog_conf_template(settings=settings): port = getattr(settings, 'LOG_AGGREGATOR_PORT', '') protocol = getattr(settings, 'LOG_AGGREGATOR_PROTOCOL', '') timeout = getattr(settings, 'LOG_AGGREGATOR_TCP_TIMEOUT', 5) + max_disk_space = getattr(settings, 'LOG_AGGREGATOR_MAX_DISK_USAGE_GB', 1) + spool_directory = getattr(settings, 'LOG_AGGREGATOR_MAX_DISK_USAGE_PATH', '/var/lib/awx').rstrip('/') + + if not os.access(spool_directory, os.W_OK): + spool_directory = '/var/lib/awx' + max_bytes = settings.MAX_EVENT_RES_DATA parts.extend([ '$WorkDirectory /var/lib/awx/rsyslog', f'$MaxMessageSize {max_bytes}', '$IncludeConfig /var/lib/awx/rsyslog/conf.d/*.conf', - 'main_queue(queue.spoolDirectory="/var/lib/awx" queue.maxdiskspace="1g" queue.type="Disk" queue.filename="awx-external-logger-backlog")', + f'main_queue(queue.spoolDirectory="{spool_directory}" queue.maxdiskspace="{max_disk_space}g" queue.type="Disk" queue.filename="awx-external-logger-backlog")', # noqa 'module(load="imuxsock" SysSock.Use="off")', 'input(type="imuxsock" Socket="' + settings.LOGGING['handlers']['external_logger']['address'] + '" unlink="on")', 'template(name="awx" type="string" string="%rawmsg-after-pri%")', diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 9fb1e7e6f6..7280866d6d 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -936,6 +936,8 @@ LOG_AGGREGATOR_ENABLED = False LOG_AGGREGATOR_TCP_TIMEOUT = 5 LOG_AGGREGATOR_VERIFY_CERT = True LOG_AGGREGATOR_LEVEL = 'INFO' +LOG_AGGREGATOR_MAX_DISK_USAGE_GB = 1 +LOG_AGGREGATOR_MAX_DISK_USAGE_PATH = '/var/lib/awx' # The number of retry attempts for websocket session establishment # If you're encountering issues establishing websockets in clustered Tower,