Skip to content

Logging: Add journald support #2940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2021
Merged

Conversation

dumbbell
Copy link
Collaborator

@dumbbell dumbbell commented Mar 29, 2021

The implementation depends on erlang-systemd which uses Unix socket support introduced in Erlang 19. Therefore it doesn't rely on a native library. We also don't need special handling if the host doesn't use journald.

To enable the journald handler, add the following configuration variable:

log.journald = true

The log level can also be set the same way it is with other handlers:

log.journald.level = debug

The log messages are communicated to journald using structured data. It is possible to configure which fields are transmitted and how they are named:

log.journald.fields = SYSLOG_IDENTIFIER="rabbitmq-server" syslog_timestamp syslog_pid priority ERL_PID=pid

In this example:

  • the SYSLOG_IDENTIFIER is set to a string literal
  • syslog_timestamp and syslog_pid` are aliases for SYSLOG_TIMESTAMP=time and SYSLOG_PID=os_pid
  • priority is a special field computed from the log level
  • ERL_PID=pid indicates pid should be sent as the ERL_PID field.

The message itself is implicit and always sent. Otherwise, the list of fields must be exhaustive: fields which are unset in a particular log event meta are sent as an empty string and non-mentionned fields are not sent. The order is not important.

Here are some messages printed by journalctl -f during RabbitMQ startup:

Mar 26 11:58:31 ip-172-31-43-179 rabbitmq-server[19286]: Ready to start client connection listeners
Mar 26 11:58:31 ip-172-31-43-179 rabbitmq-server[19286]: started TCP listener on [::]:5672
Mar 26 11:58:31 ip-172-31-43-179 rabbitmq-server[19286]: Server startup complete; 0 plugins started.

@dumbbell
Copy link
Collaborator Author

Note that erlang-systemd is only used for its journald support in this pull request. I plan to change how we tell systemd RabbitMQ is ready to use this new dependency as well. This will allow us to get rid of the previous methods (socat and sd_notify). This will come in a separate patch.

@dumbbell dumbbell force-pushed the support-journald-logging branch from 0a4dee3 to c4f3693 Compare March 29, 2021 16:23
The implementation depends on erlang-systemd [1] which uses Unix socket
support introduced in Erlang 19. Therefore it doesn't rely on a native
library. We also don't need special handling if the host doesn't use
journald.

To enable the journald handler, add the following configuration
variable:

    log.journald = true

The log level can also be set the same way it is with other handlers:

    log.journald.level = debug

The log messages are communicated to journald using structured data. It
is possible to configure which fields are transmitted and how they are
named:

    log.journald.fields = SYSLOG_IDENTIFIER="rabbitmq-server" syslog_timestamp syslog_pid priority ERL_PID=pid

In this example:
  * the `SYSLOG_IDENTIFIER` is set to a string literal
  * `syslog_timestamp and `syslog_pid` are aliases for
    SYSLOG_TIMESTAMP=time and SYSLOG_PID=os_pid
  * `priority` is a special field computed from the log level
  * `ERL_PID=pid` indicates `pid` should be sent as the `ERL_PID`
    field.

The message itself is implicit and always sent. Otherwise, the list of
fields must be exhaustive: fields which are unset in a particular log
event meta are sent as an empty string and non-mentionned fields are not
sent. The order is not important.

Here are some messages printed by `journalctl -f` during RabbitMQ
startup:

    Mar 26 11:58:31 ip-172-31-43-179 rabbitmq-server[19286]: Ready to start client connection listeners
    Mar 26 11:58:31 ip-172-31-43-179 rabbitmq-server[19286]: started TCP listener on [::]:5672
    Mar 26 11:58:31 ip-172-31-43-179 rabbitmq-server[19286]: Server startup complete; 0 plugins started.

[1] https://github.com/rabbitmq/erlang-systemd
@dumbbell dumbbell force-pushed the support-journald-logging branch from c4f3693 to 91583a0 Compare March 31, 2021 12:15
@dumbbell dumbbell marked this pull request as ready for review March 31, 2021 12:16
@dumbbell
Copy link
Collaborator Author

Here is how I tested the patch:

  1. I used a Debian Buster VM because journald requires systemd as far as I know.

  2. To view the logs, I just used the "tail -f" journald equivalent:

    journalctl -f
    
  3. I configured RabbitMQ to use both journald and stdout:

    cat >/tmp/rabbitmq.conf <<EOF
    log.console = true
    log.journald = true
    EOF
    
  4. I started RabbitMQ with that configuration file:

    gmake run-broker RABBITMQ_CONFIG_FILES=/tmp/rabbitmq.conf
    

@michaelklishin michaelklishin merged commit 34b03d6 into master Apr 1, 2021
@michaelklishin michaelklishin deleted the support-journald-logging branch April 1, 2021 03:58
@michaelklishin michaelklishin added this to the 3.9.0 milestone Apr 1, 2021
dumbbell added a commit that referenced this pull request Apr 9, 2021
Until now, we were using socat(1). It was added as a dependency to our
Debian and RPM packages. Unfortunately, the availability of this package
has not always been good. We also supported erlang-sd_notify which
relied on a UDP socket. None of them had journald support.

Now, thanks to erlang-systemd, we can use the Unix socket and provide
more fine-grained status updates if we want.

Journald support is also provided by erlang-systemd. It was added to
RabbitMQ in commit 91583a0 (#2940).
dumbbell added a commit that referenced this pull request Apr 9, 2021
Until now, we were using socat(1). It was added as a dependency to our
Debian and RPM packages. Unfortunately, the availability of this package
has not always been good. We also supported erlang-sd_notify which
relied on a UDP socket. None of them had journald support.

Now, thanks to erlang-systemd, we can use the Unix socket and provide
more fine-grained status updates if we want.

Journald support is also provided by erlang-systemd. It was added to
RabbitMQ in commit 91583a0 (#2940).
openstack-mirroring pushed a commit to openstack/openstack-ansible-rabbitmq_server that referenced this pull request Feb 12, 2022
Since RabbitMQ 3.9 [1] journald logging support has been implemented

As we use journald logging for most of the services and aim to make it
a standard, switching rabbitmq to journald follows this goal and
deployment unification

[1] rabbitmq/rabbitmq-server#2940

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-rabbitmq_server/+/826446/
Change-Id: I86462f8279ebb5dc28e92fc8440cc0ab26f0759d
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Feb 12, 2022
* Update openstack-ansible-rabbitmq_server from branch 'master'
  to 9790981aa60fbdc0aba6fc41c71feb65d57aa063
  - Merge "Use journald logging for RabbitMQ"
  - Use journald logging for RabbitMQ
    
    Since RabbitMQ 3.9 [1] journald logging support has been implemented
    
    As we use journald logging for most of the services and aim to make it
    a standard, switching rabbitmq to journald follows this goal and
    deployment unification
    
    [1] rabbitmq/rabbitmq-server#2940
    
    Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-rabbitmq_server/+/826446/
    Change-Id: I86462f8279ebb5dc28e92fc8440cc0ab26f0759d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants