From 93d286ceea21aa27cfe2071418d236741cbccf7c Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 5 Sep 2023 10:09:29 +0100 Subject: [PATCH] logging: log to console As RabbitMQ is running under Pebble inside of a container, make sure all log output goes to the console so it can easily be accessed and collecting into observability solutions. This requires that we bypass the helper wrapper script which will always redirect STDOUT and STDERR to a log file. (cherry picked from commit acf91f945acf7d345fbfb690b17b1b5e5b23d4e1) --- src/charm.py | 10 +++++++++- tests/unit/test_charm.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/charm.py b/src/charm.py index bebf9e2..60ccddf 100755 --- a/src/charm.py +++ b/src/charm.py @@ -218,6 +218,10 @@ def _check_rmq_running(): def _rabbitmq_layer(self) -> dict: """Pebble layer definition for RabbitMQ.""" + # NOTE(jamespage) + # Use the full path to the rabbitmq-server binary + # rather than the helper wrapper script to avoid + # redirection of console output to a log file. return { "summary": "RabbitMQ layer", "description": "pebble config layer for RabbitMQ", @@ -225,7 +229,7 @@ def _rabbitmq_layer(self) -> dict: RABBITMQ_SERVICE: { "override": "replace", "summary": "RabbitMQ Server", - "command": "rabbitmq-server", + "command": "/usr/lib/rabbitmq/bin/rabbitmq-server", "startup": "enabled", "user": RABBITMQ_USER, "group": RABBITMQ_GROUP, @@ -588,6 +592,10 @@ def _render_and_push_rabbitmq_conf(self) -> None: cluster_partition_handling = autoheal queue_master_locator = min-masters + +# Log to console for pod logging +log.console = true +log.file = false """ logger.info("Pushing new rabbitmq.conf") container.push( diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 64ef556..5a4b91b 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -73,7 +73,7 @@ def test_rabbitmq_pebble_ready(self): "rabbitmq": { "override": "replace", "summary": "RabbitMQ Server", - "command": "rabbitmq-server", + "command": "/usr/lib/rabbitmq/bin/rabbitmq-server", "startup": "enabled", "user": "rabbitmq", "group": "rabbitmq",