Skip to content

Adding support for the new mongodb-driver-sync library#2241

Merged
SylvainJuge merged 29 commits intoelastic:mainfrom
juliovalcarcel:MongoClient4
Aug 1, 2022
Merged

Adding support for the new mongodb-driver-sync library#2241
SylvainJuge merged 29 commits intoelastic:mainfrom
juliovalcarcel:MongoClient4

Conversation

@juliovalcarcel
Copy link
Contributor

@juliovalcarcel juliovalcarcel commented Nov 6, 2021

This starts to address #1547 and more specifically enables the new mongodb-driver-sync to work with Spring Boot's MongoDB starter by default. I did this by following what was done for Cassandra and splitting mongoclient into a v3 and a v4 package. The v4 package is setup to start using the mongodb-driver-sync dependency and is updated to use the new classes.

I am having problems with the MongoDriverSyncInstrumentationIT and getting it to run without falling, but all unit tests passed (Just duplicated currently from v3 with minor tweaks). I could use some help from someone on what needs to be revised for the IT and then I will add additional versions to the IT.

There is definitely room for deduplication between the v3 and v4 drivers but I wanted to get a working version up and running for feedback.

Updated checklist after feedback

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.asciidoc
    • I have added tests that prove my fix is effective or that my feature works
    • Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation
  • This is a bugfix
  • This is a new plugin
    • I have updated CHANGELOG.asciidoc
    • My code follows the style guidelines of this project
    • I have made corresponding changes to the documentation
    • I have added tests that prove my fix is effective or that my feature works
    • New and existing unit tests pass locally with my changes
    • I have updated supported-technologies.asciidoc
    • Added an API method or config option? Document in which version this will be introduced
    • Added an instrumentation plugin? Describe how you made sure that old, non-supported versions are not instrumented by accident.
  • This is something else

EDT:
Closes #1547

@github-actions github-actions bot added agent-java community Issues and PRs created by the community triage labels Nov 6, 2021
@ghost
Copy link

ghost commented Nov 6, 2021

💚 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-07-31T12:39:24.164+0000

  • Duration: 51 min 11 sec

Test stats 🧪

Test Results
Failed 0
Passed 3081
Skipped 36
Total 3117

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

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

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark tests.

  • run jdk compatibility tests : Run the JDK Compatibility tests.

  • run integration tests : Run the Agent Integration tests.

  • run end-to-end tests : Run the APM-ITs.

  • run windows tests : Build & tests on windows.

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

@videnkz
Copy link
Contributor

videnkz commented Nov 11, 2021

MongoDriverSyncInstrumentationIT

Hi, @juliovalcarcel
As Felix noted in the co.elastic.apm.agent.mongoclient3.ConnectionInstrumentation comment, in version 4 everything works via 'com.mongodb.internal.connection.Connection#command'.
Therefore, in version 4, 'Connection Instrumentation' is irrelevant.
And you need instrument only with ConnectionCommandInstrumentation.
For this you need to change the 'getTypeMatcher()' in MongoDriverInstrumentation, since in version 4 Connection moved to other package com.mongodb.internal.connection.

    @Override
    public ElementMatcher<? super TypeDescription> getTypeMatcher() {
        return nameStartsWith("com.mongodb.internal")
            .and(hasSuperType(named("com.mongodb.internal.connection.Connection")));
    }

And also now command takes String as the first argument. So in ConnectionAdvice no need checking type of the 0 argument.

@botelastic
Copy link

botelastic bot commented Jan 14, 2022

Hi! We just realized that we haven't looked into this issue in a while. We're sorry! We're labeling this issue as stalled to make it hit our filters and make sure we get back to it in as soon as possible. In the meantime, it'd be extremely helpful if you could take a look at it as well and confirm its relevance. A simple comment with a nice emoji will be enough :+1. Thank you for your contribution!

@botelastic botelastic bot added the stalled label Jan 14, 2022
@SylvainJuge SylvainJuge added the new-feature New feature label Jan 25, 2022
@botelastic botelastic bot removed the stalled label Jan 25, 2022
@juliovalcarcel
Copy link
Contributor Author

@kananindzya Thank you for the feedback and sorry for the delay in response but I have rebased my branch onto main and fixed the issues you found as well as fixed both tests. Included are tests for all current minor 4.x versions. Please let me know if there are any additional fixes that you see need to be made and I will try to get to them much quicker.

@SylvainJuge SylvainJuge added the size:medium Medium (M) tasks label Jan 31, 2022
@juliovalcarcel
Copy link
Contributor Author

I wanted to check and see if there was a plan to review/merge this? Or should I wait to rebase it and fix the conficts?

@SylvainJuge
Copy link
Member

Hi @juliovalcarcel we have added this to our short-term backlog, thus we expect to be able to handle it soon (but can't guarantee any precise ETA as unexpected priorities tend to get the last word).

@juliovalcarcel
Copy link
Contributor Author

@SylvainJuge okay, I will work to rebase it and will keep an eye out for any comments to keep it moving forward. Thanks!

This splits mongoclient into a v3 and a v4 package and updates
the v4 to use the new classes. Additional work is needed to fix the
IT for v4 and to deduplicate code across v3 and v4
@juliovalcarcel
Copy link
Contributor Author

Branch has been rebased on my end. Please let me know what feedback there is and I will resolve it ASAP.

@SylvainJuge
Copy link
Member

Hi @juliovalcarcel , after trying a few different approaches for 4.x driver I think the approach used in this PR is the right one.
As a consequence I've opened a PR on your own branch to update this branch/PR : https://github.com/juliovalcarcel/apm-agent-java/pull/9/

Thus going forward we can either:

  • merge my PR on your PR (which might be quite hard to review as-is), or just blindly trust me on this one :-) <--- the easiest option.
  • close this PR and open another one from my own fork, but that would make your contributions disappear which I don't like but is the easiest on our side.
  • rebase my changes on top of your branch and push directly to it <--- a bit harder on my end.

In all cases the final result will be squashed in a single commit when merged in main.

@SylvainJuge
Copy link
Member

Quick update: I have pushed my changes to this branch so the original contributions of @juliovalcarcel are still there even if slightly altered and this PR should now be closer to be merged. My approval is only to allow running in CI for now.

Copy link
Member

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

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

Approving to allow running in CI.

@juliovalcarcel
Copy link
Contributor Author

@SylvainJuge you let me know how I should help. Sorry for the delay, I was on vacation and just got back. I am okay with all the approaches but am all good with the blind trust :)

@SylvainJuge
Copy link
Member

@juliovalcarcel I've merged the changes in this PR branch, thus I've closed the humongous "trust me I know what I do" PR.
So, code-wise there isn't much left to do, but it would be more than welcome if you could try this snapshot to make sure that it works in your setup, not being very familiar with MongoDB API there might be a few cases that aren't properly covered.

@SylvainJuge
Copy link
Member

@elasticmachine run elasticsearch-ci/docs

@SylvainJuge
Copy link
Member

@elasticmachine run elasticsearch-ci/docs

@SylvainJuge SylvainJuge enabled auto-merge (squash) July 28, 2022 15:43
@SylvainJuge
Copy link
Member

@elasticmachine run elasticsearch-ci/docs

@SylvainJuge SylvainJuge merged commit 6ee1102 into elastic:main Aug 1, 2022
@juliovalcarcel juliovalcarcel deleted the MongoClient4 branch October 6, 2022 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.4-candidate agent-java community Issues and PRs created by the community new-feature New feature size:medium Medium (M) tasks stretch

5 participants