From acf91f945acf7d345fbfb690b17b1b5e5b23d4e1 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. --- 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 101bf00..080d1c0 100755 --- a/src/charm.py +++ b/src/charm.py @@ -239,6 +239,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", @@ -246,7 +250,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, @@ -744,6 +748,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 19b94f7..755ba6c 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -76,7 +76,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",