Skip to content
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

Logging sources #502

Closed
wants to merge 28 commits into from
Closed

Logging sources #502

wants to merge 28 commits into from

Conversation

spuun
Copy link
Member

@spuun spuun commented Apr 19, 2023

Refactor logging to embrace Crystal's Log pattern with sources.

Instead of adding e.g. entity name to the source it will be appended as metadata in all entries.

New configuration section log_levels:

[log_levels]
lavinmq.vhost = info
lavinmq.launcher = debug

If log_levels is used log_level in main section won't have any effect.

Sources:

  • lavinmq.amqpconnection
  • lavinmq.http
  • lavinmq.http.server
  • lavinmq.launcher
  • lavinmq.schema
  • lavinmq.schema.v4
  • lavinmq.server
  • lavinmq.vhost
  • lavinmq.vhost.client
  • lavinmq.vhost.client.channel
  • lavinmq.vhost.exchange
  • lavinmq.vhost.federation
  • lavinmq.vhost.federation.upstream
  • lavinmq.vhost.federation.upstream.exchangelink
  • lavinmq.vhost.federation.upstream.queuelink
  • lavinmq.vhost.federation.upstreamstore
  • lavinmq.vhost.shovel
  • lavinmq.vhost.shovel.amqpdestination
  • lavinmq.vhost.shovel.amqpsource
  • lavinmq.vhost.shovel.httpdestination
  • lavinmq.vhost.shovel.store
  • lavinmq.vhost.vhoststore

@github-actions
Copy link

github-actions bot commented Apr 19, 2023

Main benchmark
'Average publish rate: 402353.6 msgs/s'
'Average consume rate: 402127.6 msgs/s'

PR benchmark
'Average publish rate: 272645.7 msgs/s'
'Average consume rate: 271255.5 msgs/s'

Keep in mind, these numbers are not representative of LavinMQ's peak performance.
It is rather an indication of how the changes of this pull request affects the performance of the main branch.

@spuun spuun force-pushed the logging-sources branch 2 times, most recently from 30bd9bf to 1fdb20e Compare May 2, 2023 07:45
@spuun spuun marked this pull request as ready for review May 6, 2023 08:48
@spuun spuun force-pushed the logging-sources branch from 31b1d66 to 7382c2b Compare May 9, 2023 19:03
Copy link
Member

@viktorerlingsson viktorerlingsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@carlhoerberg
Copy link
Member

Wondering if the lavinmq. prefix is needed? this software isn't included in other applications (as for example a library would)

@carlhoerberg
Copy link
Member

What is this new EntityLog? Can't the native Log::Context be used?

@spuun
Copy link
Member Author

spuun commented May 15, 2023

What is this new EntityLog? Can't the native Log::Context be used?

Log::Context is per fiber, and it may be different fibers accessing the same object. EntityLog will use Metadata and append "context" for the current entity in each log call.

@spuun
Copy link
Member Author

spuun commented May 15, 2023

Wondering if the lavinmq. prefix is needed? this software isn't included in other applications (as for example a library would)

Maybe not, I just think it's nice to be explicit. Also, if you want debug for lavinmq code but not libraries you must specify a level for each of the libraries too.

@spuun
Copy link
Member Author

spuun commented May 24, 2023

@carlhoerberg wdyt?

@spuun spuun force-pushed the logging-sources branch from 7382c2b to 2c837d9 Compare June 26, 2023 06:02
@@ -12,10 +12,12 @@ module LavinMQ
include Stats
include SortableJSON

Log = Client::Log.for "channel"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Suggested change
Log = Client::Log.for "channel"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used by the EntityLog for Channel, and also by Consumer.

Following the docs/"pattern" for Log, declaring a Log per namespace seems to be the way to go. Sticking to always declaring Log in module/class makes it consistent on where source is set. I have no real opinion on this. Also, as I mention in the other comment, I thought it would create a new Log instance for every for call.


module LavinMQ
class Client
class Channel
class Consumer
include SortableJSON

Log = Channel::Log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this used by?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's declared here to show that Consumer has the same log source as Channel. It's then used by each Consumer's EntityLog.

@spuun spuun force-pushed the logging-sources branch from 2c837d9 to a1506a2 Compare August 9, 2023 12:42

def initialize(@vhost : VHost)
@log = Log.for "UpstreamStore[vhost=#{@vhost}]"
@log = @vhost.log.extend(Log)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not?

Suggested change
@log = @vhost.log.extend(Log)
@log = @vhost.log.extend(Federation::Log.for "upstreamstore")

Isn't there a risk that someone starts to use Log in the class otherwise? and/or that the Log = Federation::Log.for "upstreamstore" is removed because it's not used except here, but kind of implicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, absolutely.

IIRC the reason for setting Log and use that was that I assumed that Log.for would create a new Log instance for every call. Now that I've read the code and I see that it's not, this could be changed.

@spuun spuun force-pushed the logging-sources branch 3 times, most recently from e21dfdc to fe0b7ef Compare August 16, 2023 08:45
The Queue::Log instnance is wrapped and vhost name and queue name is
passed as metadata to all log entries instead of being a part of the log
source.
Make it easier to use Log constans, step by step.
@tls_context : OpenSSL::SSL::Context::Server?
@first_shutdown_attempt = true
@data_dir_lock : DataDirLock?
@log_setup = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doens't seem to be used

Suggested change
@log_setup = false

Comment on lines +11 to +13
::Log.setup_from_env(
backend: Log::IOBackend.new(
formatter: LavinMQ::Logging::StdoutLogFormat))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

means that we get logs in specs, in systemd environments etc with wrong format?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno what you mean with wrong format? It's the same formatter as will be used again when the log is configured from config.

I don't recall exactly why I added this, but it's to have a "default logger" configured before we've parse the config.

Move extend method to Log::Metadata to make it more efficient. This will
reduce the need of temporary hashes when creating the new Metadata.
@spuun
Copy link
Member Author

spuun commented Mar 6, 2024

Closing this for now. We're probably not going with it.

@spuun spuun closed this Mar 6, 2024
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.

4 participants