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

Upgrade Mongodb library in Beats to v5 #31185

Merged
merged 24 commits into from
May 17, 2022

Conversation

sayden
Copy link
Contributor

@sayden sayden commented Apr 6, 2022

What does this PR do?

Replaces Mongodb library that Beats was using for the updated (and maintained) official version.

Why is it important?

Current version library was unmaintained and Beats could only support up to v3.2. This change adds support for V4 and V5 too.

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.

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 6, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Apr 6, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-17T14:05:02.391+0000

  • Duration: 177 min 58 sec

Test stats 🧪

Test Results
Failed 0
Passed 21737
Skipped 1802
Total 23539

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@sayden sayden added the Team:Service-Integrations Label for the Service Integrations team label Apr 13, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 13, 2022
@mergify
Copy link
Contributor

mergify bot commented Apr 28, 2022

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 feature/mb/upgrade-mongodb-library upstream/feature/mb/upgrade-mongodb-library
git merge upstream/main
git push upstream feature/mb/upgrade-mongodb-library

sayden added 15 commits May 7, 2022 14:55
…mb/upgrade-mongodb-library

# Conflicts:
#	go.mod
#	go.sum
#	metricbeat/module/mongodb/collstats/collstats.go
#	metricbeat/module/mongodb/dbstats/dbstats.go
#	metricbeat/module/mongodb/replstatus/data.go
#	metricbeat/module/mongodb/replstatus/replstatus_integration_test.go
#	metricbeat/module/mongodb/status/status.go
@sayden
Copy link
Contributor Author

sayden commented May 8, 2022

/test

@sayden sayden marked this pull request as ready for review May 8, 2022 17:06
@sayden sayden requested review from a team as code owners May 8, 2022 17:06
@sayden sayden requested a review from a team as a code owner May 8, 2022 17:06
@sayden sayden requested review from cmacknz and leehinman and removed request for a team May 8, 2022 17:06
// As a minimum it must inherit the mb.BaseMetricSet fields, but can be extended with
// additional entries. These variables can be used to persist data or configuration between
// multiple fetch calls.
type MetricSet struct {
*mongodb.MetricSet
type Metricset struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this name change? There appears to be disagreement in the code base about how this should be spelled; the docs spell it as a single word, but the mb package spells it as a camel-cased pair.

Copy link
Contributor Author

@sayden sayden May 9, 2022

Choose a reason for hiding this comment

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

Well, I'm afraid that it's out of the scope of the PR to reach a consensus 🙂 Personally I don't like the camelCased version and I think statistically you'll see it more often without camelCase like in the docs of most of the metricsets of most of the modules. https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-metricset-mongodb-collstats.html

Comment on lines 67 to 69
defer func() {
_ = client.Disconnect(context.Background())
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be an unpopular opinion, but I think assigning to the blank identifier to satisfy the linter is an antipattern; it does not handle the error but also evades the rationale behind enforcing require-explanation: true and makes it harder in the future to clean up linter supression because it is harder to find and reason about.

Copy link
Member

Choose a reason for hiding this comment

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

+1, I'd rather see an explanation of why errors can be ignored where possible using the //nolint:errcheck $reason comment instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On top of my head, most of Close and Disconnect operations across metricbeat modules ignores the error. As the person who has tried to maintain this module on the last years, I just wanted to do the dirty work of upgrading the library and leave improvements to the @elastic/obs-service-integrations team now

Keep in mind that it takes me more time to write this message on GH than to write a line that logs the error.

@sayden
Copy link
Contributor Author

sayden commented May 9, 2022

Thanks for the messages, it will be nice if @efd6 can take a quick look at the Packetbeat file that was modified in this PR, that's why security was pinged.

Thanks!

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

Packetbeat changes are fine.

@mergify
Copy link
Contributor

mergify bot commented May 10, 2022

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 feature/mb/upgrade-mongodb-library upstream/feature/mb/upgrade-mongodb-library
git merge upstream/main
git push upstream feature/mb/upgrade-mongodb-library

sayden added 4 commits May 11, 2022 17:08
…mb/upgrade-mongodb-library

# Conflicts:
#	metricbeat/module/mongodb/dbstats/dbstats.go
#	metricbeat/module/mongodb/metricset.go
#	metricbeat/module/mongodb/mongodb.go
#	packetbeat/protos/mongodb/mongodb_parser.go
Copy link
Contributor

@ManojS-shetty ManojS-shetty left a comment

Choose a reason for hiding this comment

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

Tested for the compatibility for MongoDB version 5.0 and >5.0 and beat managed establish the connection and pull the metrics.

As discussed please close the related issue for mongo DB. Rest LGTM.

@@ -24,40 +24,40 @@ import (

var schema = s.Schema{
"db": c.Str("db"),
"collections": c.Int("collections"),
"objects": c.Int("objects"),
"collections": c.Ifc("collections"),
Copy link
Contributor

Choose a reason for hiding this comment

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

@sayden Is this also part of this driver update change? Can you please let us know in brief for the change from Int to Ifc() .

@mergify
Copy link
Contributor

mergify bot commented May 12, 2022

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 feature/mb/upgrade-mongodb-library upstream/feature/mb/upgrade-mongodb-library
git merge upstream/main
git push upstream feature/mb/upgrade-mongodb-library

@mergify
Copy link
Contributor

mergify bot commented May 16, 2022

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 feature/mb/upgrade-mongodb-library upstream/feature/mb/upgrade-mongodb-library
git merge upstream/main
git push upstream feature/mb/upgrade-mongodb-library

sayden added 3 commits May 17, 2022 11:18
…mb/upgrade-mongodb-library

# Conflicts:
#	go.sum
#	metricbeat/module/mongodb/metricset.go
"github.com/elastic/elastic-agent-libs/mapstr"
)

func TestFetch(t *testing.T) {
t.Skip("Flaky test: https://github.com/elastic/beats/issues/29208")
Copy link
Member

Choose a reason for hiding this comment

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

This test is flaky again: #31768

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug enhancement Team:Service-Integrations Label for the Service Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants