Skip to content

[Chore] Replace global logger with local loggers in mb modules #5#44107

Merged
pierrehilbert merged 16 commits intoelastic:mainfrom
khushijain21:locallogger-5
May 8, 2025
Merged

[Chore] Replace global logger with local loggers in mb modules #5#44107
pierrehilbert merged 16 commits intoelastic:mainfrom
khushijain21:locallogger-5

Conversation

@khushijain21
Copy link
Copy Markdown
Contributor

Proposed commit message

This PR replaces global logger instances with local loggers in metricbeat modules

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Related issues

@khushijain21 khushijain21 requested review from a team as code owners April 29, 2025 06:03
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 29, 2025
@khushijain21 khushijain21 added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Apr 29, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 29, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@khushijain21 khushijain21 added Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team Team:Monitoring Stack Monitoring team labels Apr 29, 2025
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 29, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @khushijain21? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@khushijain21 khushijain21 added the Team:Integrations Label for the Integrations team label Apr 29, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/integrations (Team:Integrations)

@khushijain21
Copy link
Copy Markdown
Contributor Author

cc: @lalit-satapathy, @consulthys , @gizas

@gizas
Copy link
Copy Markdown
Contributor

gizas commented May 5, 2025

LGTM especially for k8s and docker modules

Copy link
Copy Markdown
Member

@pickypg pickypg left a comment

Choose a reason for hiding this comment

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

LGT Stack Monitoring

@pierrehilbert pierrehilbert requested a review from leehinman May 6, 2025 13:03
@khushijain21 khushijain21 requested review from a team as code owners May 6, 2025 14:00
Copy link
Copy Markdown
Contributor

@leehinman leehinman left a comment

Choose a reason for hiding this comment

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

LGTM. Thank You.

@khushijain21
Copy link
Copy Markdown
Contributor Author

/test

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented May 7, 2025

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b locallogger-5 upstream/locallogger-5
git merge upstream/main
git push upstream locallogger-5


groups := makeNameSet(test.groups...).pred()
topics := makeNameSet(test.topics...).pred()
err := fetchGroupInfo(collectEvents, test.client, groups, topics)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In some places, we have used "", selector, "test" as values in the second param of NewTestingLogger. Should we use "test" instead of "" in all *_test.go files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By default, I have used an empty selector. But if there existed a logger setup with "test" as the selector - "test" is used with NewTestingLogger as well. This is to stay consistent with the old code.

}

// lookup ips for all brokers
debugf("match by ips")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not use: m.logger.Named("kafka")

why all debugf calls are not replaces in a similar way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This specific one was a typo. Thanks for catching this.

Copy link
Copy Markdown
Contributor Author

@khushijain21 khushijain21 May 8, 2025

Choose a reason for hiding this comment

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

why all debugf calls are not replaces in a similar way?

All are replaced in a similar way. I did not find such discrepancy anywhere else, have you?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah na. Did not open the full file; I just asked if there are more or not. If there's not, LGTM.

// do not report events since this is not a leader
if res.StatusCode == http.StatusForbidden &&
retMessage == msgValueNonLeader {
if m.debugEnabled {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we sure that something like m.logger.IsDebug() or something like this is not required; it's handled already with Debugf?

Copy link
Copy Markdown
Contributor Author

@khushijain21 khushijain21 May 8, 2025

Choose a reason for hiding this comment

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

yes, so m.debugEnabled would check if the particular selector can be logged at debug level. i.e if debug level is configured

m.logger.Debugf() will only log message when debug level is configured.
It is achieving the same functionality

@khushijain21 khushijain21 requested a review from shmsr May 8, 2025 09:43
@khushijain21 khushijain21 enabled auto-merge (squash) May 8, 2025 10:16
@pierrehilbert pierrehilbert disabled auto-merge May 8, 2025 11:32
@pierrehilbert pierrehilbert merged commit 11713f0 into elastic:main May 8, 2025
197 of 200 checks passed
@khushijain21 khushijain21 added the backport-8.19 Automated backport to the 8.19 branch label Jun 12, 2025
mergify bot pushed a commit that referenced this pull request Jun 12, 2025
…4107)

* [Chore] Replace global logger with local loggers in mb modules #5

* fix tests

* make check

* make check

* fix tests

* make update

* fix redis integ test

* deploy on k8's

* add deps

* fix logger name for kafka

(cherry picked from commit 11713f0)

# Conflicts:
#	x-pack/metricbeat/module/awsfargate/task_stats/task_stats.go
khushijain21 added a commit that referenced this pull request Jun 12, 2025
…4107)

* [Chore] Replace global logger with local loggers in mb modules #5

* fix tests

* make check

* make check

* fix tests

* make update

* fix redis integ test

* deploy on k8's

* add deps

* fix logger name for kafka
khushijain21 added a commit to khushijain21/beats that referenced this pull request Jun 19, 2025
 (elastic#44107)

* [Chore] Replace global logger with local loggers in mb modules elastic#5

* fix tests

* make check

* make check

* fix tests

* make update

* fix redis integ test

* deploy on k8's

* add deps

* fix logger name for kafka
khushijain21 pushed a commit that referenced this pull request Jul 9, 2025
…ers in mb modules #5 (#44775)

* [Chore] Replace global logger with local loggers in mb modules #5 (#44107)
khushijain21 added a commit to khushijain21/beats that referenced this pull request Aug 11, 2025
 (elastic#44107)

* [Chore] Replace global logger with local loggers in mb modules elastic#5

* fix tests

* make check

* make check

* fix tests

* make update

* fix redis integ test

* deploy on k8's

* add deps

* fix logger name for kafka
cmacknz pushed a commit that referenced this pull request Aug 12, 2025
…les #5  (#45883)

* [Chore] Replace global logger with local loggers in mb modules #5 (#44107)

* [Chore] Replace global logger with local loggers in mb modules #5

* fix tests

* make check

* make check

* fix tests

* make update

* fix redis integ test

* deploy on k8's

* add deps

* fix logger name for kafka

* add config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.19 Automated backport to the 8.19 branch Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Integrations Label for the Integrations team Team:Monitoring Stack Monitoring team Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants