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

Match specific direct JDBC driver implementations #2247

Merged
merged 5 commits into from
Jan 19, 2021

Conversation

richardstartin
Copy link
Member

This is here for review of the lists I have made of connection and preparedstatement implementations, in case any omissions jump out.

The motivation is twofold, both because JDBC involves lots of wrapping and we only want to create a single span:

  • We currently rely on lawful unwrapping behaviour, and work around unlawful unwrapping when we discover it with various approaches, including a ClassValue<Boolean> of bad unwrapping candidates, and replacing the implementations of unwrap in some datanucleus wrappers. Targeting known non-delegating implementations makes this problem go away, so long as we can create a comprehensive enough list of implementation classes.
  • Performance - see Store dbinfo in Connection context store #2220 which improves Connection to DBInfo association, which interferes with datanucleus, but would be safe if we never matched any datanucleus classes. The much bigger gain following from this is not doing any depth tracking, unwrapping, or unwrap safety checking (see unwrap prepared statements once on preparation #2216).

The awkward odd one out from the big databases is Oracle, because of the licensing of its driver. I don't believe it is within the terms of the license to use the names of its implementation classes, so we need to check whether the classes implement the Oracle JDBC API. I haven't looked at the class names, so don't know if the prefix check is correct (this needs testing), and think it would be safer to just check if the interfaces are implemented, and perhaps add an oracle integration feature which can be disabled to speed up matching for users of other databases.

@richardstartin richardstartin requested a review from a team as a code owner January 5, 2021 11:32
@richardstartin
Copy link
Member Author

It appears that the DB2 types referred to here are interfaces so will need handling similarly to the Oracle types

@randomanderson
Copy link
Contributor

randomanderson commented Jan 5, 2021

Looked at the https://github.com/pgjdbc/pgjdbc repo. It gets tricky. They changed packages/classnames a few times and since we're doing exact name matching, we have to also match on CallableStatement which extends PreparedStatement. (I'm not actually sure if our instrumentation works with 21 year old postgres drivers, I assume it does).

Some that are missing:

6.4
postgresql.PreparedStatement
postgresql.CallableStatement
postgresql.Connection

6.5:
org.postgresql.jdbc1.CallableStatement
org.postgresql.jdbc1.PreparedStatement
org.postgresql.jdbc1.Connection
org.postgresql.jdbc2.CallableStatement
org.postgresql.jdbc2.PreparedStatement
org.postgresql.jdbc2.Connectiion

7.3
org.postgresql.jdbc1.Jdbc1CallableStatement
org.postgresql.jdbc1.Jdbc1PreparedStatement
org.postgresql.jdbc1.Jdbc1Connection
org.postgresql.jdbc2.Jdbc2CallableStatement
org.postgresql.jdbc2.Jdbc2PreparedStatement
org.postgresql.jdbc2.Jdbc2Connection
org.postgresql.jdbc3.Jdbc3CallableStatement
org.postgresql.jdbc3.Jdbc3PreparedStatement
org.postgresql.jdbc3.Jdbc3Connection

8.0
org.postgresql.jdbc3g.Jdbc3gCallableStatement
org.postgresql.jdbc3g.Jdbc3gPreparedStatement
org.postgresql.jdbc3g.Jdbc3gConnection

8.2
org.postgresql.jdbc4.Jdbc4CallableStatement
org.postgresql.jdbc4.Jdbc4PreparedStatement
org.postgresql.jdbc4.Jdbc4Connection

latest
org.postgresql.jdbc.PgCallableStatement

This list gets much shorter if we use extends instead of exact name matching.

@richardstartin richardstartin force-pushed the rgs/jdbc-opt-in branch 2 times, most recently from 5fdffc5 to fac2daa Compare January 5, 2021 19:25
@richardstartin
Copy link
Member Author

richardstartin commented Jan 5, 2021

@randomanderson thanks for digging into that, I was aware of a couple of the jdbc1/jdbc2 names but had left them out. I've added what should be complete coverage for Oracle, DB2, JT400, Postgres, and SQLite. I'll look in to the histories of the other drivers.

  • Postgres
  • JT400
  • DB2
  • Oracle
  • Mysql
  • SQL Server
  • Derby
  • H2
  • Sqlite
  • Mariadb
  • hsqldb
  • hive-jdbc
  • ?

@richardstartin
Copy link
Member Author

There's also no harm in having some redundancy in the list because it will short circuit matching, it's just important not to include any wrappers.

@richardstartin richardstartin force-pushed the rgs/jdbc-opt-in branch 5 times, most recently from 877c8fb to 4adba40 Compare January 8, 2021 11:16
@@ -41,7 +43,52 @@ public ConnectionInstrumentation() {

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return implementsInterface(named("java.sql.Connection"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider a temporary config to toggle back to the original matcher?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that's possible because the motivation for this PR is to remove checks on the critical path which make this matcher possible to use. The strategy proposed was to make a best effort attempt to find all relevant native connection/PS classes, extend the list over time, and add the flags to allow setting custom implementation classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I understand the motivation for this PR. If we postpone the follow on work for a future release, we could add the config I suggested and potentially have a safer fallback. I'm fine moving forward with your proposal though.

Copy link
Contributor

@randomanderson randomanderson left a comment

Choose a reason for hiding this comment

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

Shouldn't all of the unwrap logic in JDBCUtils be removed since we know these classes will never need unwrapping?

@richardstartin
Copy link
Member Author

@randomanderson I want to rebase #2216 on to this, and then remove the unwrapping there. WDYT?

Copy link
Contributor

@mcculls mcculls left a comment

Choose a reason for hiding this comment

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

👍

@richardstartin richardstartin merged commit c3e298c into master Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants