-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Metricbeat] Introduce Logger per metricset #11106
Conversation
Currently each Metricset initialises its own logger. The selector has to be set manually. This PR moves this code to the initialisation of the Metricset, meaning each metricset has its own logger. This should reduce the code needed in each Metricset and removes errors like putting a wrong or inconsistent selectors. It's different from before where there was a global logger for all instances of the same metricset and now each metricset instance has it's own logger. This should not make a difference. As an example implementation the `system.fsstat` metricset was adjusted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great addition, @ruflin! Tested locally, everything ok!
@@ -106,6 +107,7 @@ type MetricSet interface { | |||
HostData() HostData // HostData returns the parsed host data. | |||
Registration() MetricSetRegistration // Params used in registration. | |||
Metrics() *monitoring.Registry // MetricSet specific metrics | |||
Logger() *logp.Logger // MetricSet specific logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, though I would have went with a shorter Log()
name in effort to keep the code lines shorter like (ms.Log().Info(...)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewkroh I like that, will open a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name updated here: #11126
Based on the comment elastic#11106 (comment) the Logger method is renamed to Log. It turned out this was already almost a convention which we used across the metricsets. This meant the Log variable and Log() method conflicted and required an update in the metricsets that had a Log variable. No functionality was changed in this PR.
With #11106, the base `Metricset` struct started defining a `Logger()` method which returned a `*logp.Logger` for metricsets to use. With this change, each metricset no longer needs to define its own logger. This PR updates Elastic Stack metricsets to use the base `Metricset`'s `Logger()` instead of defining their own.
Currently each Metricset initialises its own logger. The selector has to be set manually. This PR moves this code to the initialisation of the Metricset, meaning each metricset has its own logger. This should reduce the code needed in each Metricset and removes errors like putting a wrong or inconsistent selectors.
It's different from before where there was a global logger for all instances of the same metricset and now each metricset instance has it's own logger. This should not make a difference.
As an example implementation the
system.fsstat
metricset was adjusted.