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

[Metricbeat] Introduce Logger per metricset #11106

Merged
merged 2 commits into from
Mar 6, 2019

Conversation

ruflin
Copy link
Member

@ruflin ruflin commented Mar 6, 2019

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.

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.
@ruflin ruflin added discuss Issue needs further discussion. refactoring Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Mar 6, 2019
@ruflin ruflin requested review from jsoriano and andrewkroh March 6, 2019 08:59
@ruflin ruflin requested review from a team as code owners March 6, 2019 08:59
@ruflin ruflin requested a review from sayden March 6, 2019 09:54
Copy link
Contributor

@sayden sayden left a 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!

@ruflin ruflin merged commit 30f809b into elastic:master Mar 6, 2019
@ruflin ruflin deleted the logger-per-metricset branch March 6, 2019 11:57
@@ -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
Copy link
Member

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(...)).

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Name updated here: #11126

ruflin added a commit to ruflin/beats that referenced this pull request Mar 7, 2019
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.
@ruflin ruflin self-assigned this Mar 11, 2019
ycombinator added a commit that referenced this pull request Apr 11, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Issue needs further discussion. Metricbeat Metricbeat refactoring Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants