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/module/mongodb: Refactor mongodb module #35502

Open
shmsr opened this issue May 17, 2023 · 1 comment
Open

metricbeat/module/mongodb: Refactor mongodb module #35502

shmsr opened this issue May 17, 2023 · 1 comment
Assignees
Labels
Team:Service-Integrations Label for the Service Integrations team

Comments

@shmsr
Copy link
Member

shmsr commented May 17, 2023

Describe the enhancement:

When reviewing #34624 I came across a bug which was essentially due to improper propagation of configuration i.e., clientOptions wasn't retaining the hosts. This clientOptions is used by mongo client to establish the connection and get the desired metrics.

Upon debugging the same with @ritalwar we found out the commit (49ae09a) that involved some major refactoring which led to the same. On further digging, I found that it is not aligned with other modules in beats repository (e.g., aerospike, redis, etc.). Before that commit it was fine and even along the same lines as other modules. The immediate parent of that commit reveals that the structure was more or less fine before that. Here's a PR made long back that introduced a common builder pattern: #7401 and it was really a good approach. The configuration passing was proper i.e., there is a field DialInfo in the struct named MetricSet which is holding the config state properly and passing it properly. The proposed solution for #35502 is similar.

Changes done in 49ae09a made the module metric fetching unnecessarily expensive. Previously one-time operations were done in NewMetricSet and not again and again in the NewClient method (Fetch calls NewClient).

In order to bring back proper propagation of clientOptions, it is important to do some refactoring. With the suggested refactoring, we would the following improvements:

  • Follows the same design pattern as any other standard module in beats.
  • Comparatively less expensive operations i.e., every Fetch call now uses the same configuration initialized once before and it is not done repeatedly for every Fetch. So, there would be lesser resource consumption.
  • Some naming fixes.
  • Lesser code and easier maintainability, etc.

Here's a prototype of the suggested solution: ritalwar#1

The suggested solution was made for #34624 but we later decided that it should go in a separate pull request. After #34624 is merged, I'll create a new PR with changes similar to the proposed solution.

cc: @ritalwar @lalit-satapathy

@shmsr shmsr self-assigned this May 17, 2023
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 17, 2023
@ritalwar ritalwar added the Team:Integrations Label for the Integrations team label May 18, 2023
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 18, 2023
@ritalwar ritalwar added Team:Service-Integrations Label for the Service Integrations team and removed Team:Integrations Label for the Integrations team labels May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Service-Integrations Label for the Service Integrations team
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants