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

OpenTelemetry JDBC instrumentation - fix Oracle and DB2 in native mode #28921

Merged

Conversation

michalvavrik
Copy link
Member

@michalvavrik michalvavrik commented Oct 29, 2022

fixes: #28915
fixes: #30176

Oracle driver is not registered with DriverManager in native mode. When Oracle driver is used directly, e.g. by Agroal here it's not a problem, however OpenTelemetry driver uses DriverManager and thus the Oracle driver is missing. I wonder if we should initialize it at runtime, however there is a warning in OracleMetadataOverrides that deferred me from doing it. Instead, this PR register driver when quarkus-oracle-jdbc extension is used together with OpenTelemetry extension. Way I understand java.sql.DriverManager#registerDriver(java.sql.Driver) implementation, it's simply ignored if the driver is already there, however it would be nice to find better way in the future (or now if you have one!).

DB2 driver wasn't registered for reflection when used with OT driver as then Agroal registered OT driver and not DB2 driver in native mode.

@quarkus-bot
Copy link

quarkus-bot bot commented Oct 29, 2022

/cc @brunobat, @radcortez

@michalvavrik
Copy link
Member Author

Could you have a look @Sanne, please?

@quarkus-bot

This comment has been minimized.

@michalvavrik
Copy link
Member Author

(Windows) failures are not related.

@Sanne
Copy link
Member

Sanne commented Oct 30, 2022

Interesting, unfortunately my options are limited as the Oracle driver is not open source.

In general I would suggest to not rely on the DriverManager - such static global registries are very ancient code patterns, I'm sure we can do better today. We're not relying on DriverManager in other code in Quarkus (as far as I know - clearly I didn't know about OpenTelemetry using it) and actively trying to not trigger it.

Would that be possible? It also happens to solve this issue, but I also believe it would be better overall.

@michalvavrik
Copy link
Member Author

OpenTelemetry driver is relying on DriverManager https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/OpenTelemetryDriver.java#L103 and do not offer other way to set drivers, so there are 2 ways we can work around this:

  • byte code transformation of either one of drivers (Oracle/ OT)
  • forcing runtime initialization of Oracle driver (didn't do that according to your comments)

Registering Oracle driver for now and opening issue in OT (yet to do) felt like the easiest way to work around the issue.

@geoand
Copy link
Contributor

geoand commented Oct 31, 2022

I am also -1 for this unless there is absolutely no other way to go about it.

@radcortez @brunobat can't we contribute something to OTel around this?

@Sanne
Copy link
Member

Sanne commented Oct 31, 2022

This might indeed be our only option though.

Anyone knows why it's a problem specific for Oracle and why we shuouldn't register all drivers on DriverManager if OTel requires it?

@radcortez
Copy link
Member

We can undoubtedly contribute something to OTel. We did that in the past successfully.

@michalvavrik
Copy link
Member Author

michalvavrik commented Oct 31, 2022

Anyone knows why it's a problem specific for Oracle and why we shuouldn't register all drivers on DriverManager if OTel requires it?

Adjusted reproducer for Postgresql and the issue is not there even though -H:+PrintClassInitialization shows org.postgresql.Driver, BUILD_TIME. I can't find direct call to org.postgresql.Driver#register except in static init block & PGBundleActivator (in pgjdbc project, can't see anything in quarkus/ot projects either so far). Don't have the answer, but can't see how there could be other explanation than that something calls org.postgresql.Driver#register. Update: sorry, wrong assumptions, don't know yet.

@michalvavrik michalvavrik requested a review from brunobat October 31, 2022 22:02
@michalvavrik
Copy link
Member Author

michalvavrik commented Nov 2, 2022

Hey @brunobat & @radcortez ,

I hope I didn't block solution with this PR - e.g. hope you don't wait for me. Here is my suggestion: I'll open an issue in OpenTelemetry and also provide a PR that close it. The issue should allow us to register drivers without java.sql.DriverManager#registerDriver(java.sql.Driver).

I propose it takes a while to get this fixed in OT and get it released, so it would be nice to have workaround till then. This PR does that, should you prefer different one, please, bring it on!

@brunobat
Copy link
Contributor

brunobat commented Nov 2, 2022

Hi @michalvavrik,
Thanks for the PR. I was on PTO, therefore the delay.
I agree on having this provisional solution on, with some tweaks. The PR looks good to me but later, will the final solution we should move this instrumentation wiring elsewhere and create specific test projects per DB... We should assert also do PostgreSQL and MariaDB, at least.
If you want to provide a link for the OTel side PR, I'm happy to review and help with it.

@michalvavrik
Copy link
Member Author

michalvavrik commented Nov 2, 2022

Hi @michalvavrik, Thanks for the PR. I was on PTO, therefore the delay. I agree on having this provisional solution on, with some tweaks. The PR looks good to me but later, will the final solution we should move this instrumentation wiring elsewhere and create specific test projects per DB...

Yeah, but that will mean 3 new IT modules, right? (fine with me, just checking).

We should assert also do PostgreSQL and MariaDB, at least.

I checked manually https://github.com/michalvavrik/quarkus-native-oracle-otel-reproducer and PG and MariaDB are fine, which confuses me heavily as they all (including OracleDriver) works pretty same way - register themselves in static initializer block. Not sure what's different and will try to identify exact reason, but avoiding DriverManager still seems like a good way around this (with OT PR).

If you want to provide a link for the OTel side PR, I'm happy to review and help with it.

Thank you, I opened an issue open-telemetry/opentelemetry-java-instrumentation#7028 and will draft a PR over weekend and ask you for review/kindly provide help if I go in a wrong direction etc.

@brunobat
Copy link
Contributor

brunobat commented Nov 2, 2022

Hi @michalvavrik, Thanks for the PR. I was on PTO, therefore the delay. I agree on having this provisional solution on, with some tweaks. The PR looks good to me but later, will the final solution we should move this instrumentation wiring elsewhere and create specific test projects per DB...

Yeah, but that will mean 3 new IT modules, right? (fine with me, just checking).

We should assert also do PostgreSQL and MariaDB, at least.

We can go with TestContainers and have just one JDBC Driver related project with different test classes. One different test resource for each test class: https://quarkus.io/guides/getting-started-testing#quarkus-test-resource

I checked manually https://github.com/michalvavrik/quarkus-native-oracle-otel-reproducer and PG and MariaDB are fine, which confuses me heavily as they all (including OracleDriver) works pretty same way - register themselves in static initializer block. Not sure what's different and will try to identify exact reason, but avoiding DriverManager still seems like a good way around this (with OT PR).

If you want to provide a link for the OTel side PR, I'm happy to review and help with it.

Thank you, I opened an issue open-telemetry/opentelemetry-java-instrumentation#7028 and will draft a PR over weekend and ask you for review/kindly provide help if I go in a wrong direction etc.

@michalvavrik michalvavrik force-pushed the feature/ot-jdbc-oracle-register-driver branch from 2bb9acc to 878b15c Compare November 3, 2022 14:39
@michalvavrik
Copy link
Member Author

We can go with TestContainers and have just one JDBC Driver related project with different test classes. One different test resource for each test class: https://quarkus.io/guides/getting-started-testing#quarkus-test-resource

Thanks, done.

@michalvavrik michalvavrik force-pushed the feature/ot-jdbc-oracle-register-driver branch from 878b15c to 81bd209 Compare November 3, 2022 14:42
@quarkus-bot

This comment has been minimized.

Copy link
Contributor

@brunobat brunobat left a comment

Choose a reason for hiding this comment

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

This looks really good @michalvavrik. Thanks very much.
Left a small comment.

@michalvavrik michalvavrik force-pushed the feature/ot-jdbc-oracle-register-driver branch 2 times, most recently from 6f60c12 to 94aebd0 Compare November 3, 2022 17:35
@quarkus-bot

This comment has been minimized.

@michalvavrik
Copy link
Member Author

@michalvavrik michalvavrik#48 fixes the issue for me.

Thanks, help really appreciated! I can see you added it to OT module, I'm really interested whether I could reproduce without OT, but I'm busy today. Let me have a look next week, or if you submit Quarkus PR, I will test it ex post.

@jerboaa
Copy link
Contributor

jerboaa commented Dec 23, 2022

I'll let you run with it.

@michalvavrik michalvavrik force-pushed the feature/ot-jdbc-oracle-register-driver branch 2 times, most recently from e5120d9 to 01547ca Compare December 30, 2022 14:23
@michalvavrik
Copy link
Member Author

fyi @jerboaa - the issue is not related to OT, but comes from combination of jdbc-oracle and jdbc-db2, I don't want to create addition integration test modules as this PR already adds tests that verifies fix, so I included your fix into this PR as second commit with description. And thanks.

@quarkus-bot

This comment has been minimized.

@michalvavrik
Copy link
Member Author

Quarkus QE experienced exactly same native build failures as described above, logs are here https://github.com/quarkus-qe/quarkus-test-suite/actions/runs/3814140863/jobs/6488338890; I verified it's fixed by this PR too.

I won't open an issue as there is a chance that @brunobat will review this PR and we can have it fixed in no time; in case that's a false hope, I'll open an issue later this week.

@brunobat
Copy link
Contributor

brunobat commented Jan 2, 2023

I checked out the PR and executed the db tests in my M1, in native mode and they pass...
This must be a CI issue.

@michalvavrik
Copy link
Member Author

I checked out the PR and executed the db tests in my M1, in native mode and they pass... This must be a CI issue.

I think so, thank you for checking. Please review the PR (or merge it) when times is right for you. I'm sure you've got a lot to catch up after holidays period. Thank you very much.

@geoand
Copy link
Contributor

geoand commented Jan 4, 2023

What's the status of this one?

@michalvavrik
Copy link
Member Author

What's the status of this one?

I guess we are waiting for additional reviewers.

@brunobat
Copy link
Contributor

brunobat commented Jan 4, 2023

@gsmet needs to review it

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

I added one small question for something I don't understand fully. Could you check?

@michalvavrik michalvavrik requested a review from gsmet January 11, 2023 23:15
Fixes native build when `jdbc-oracle` is combined with `jdbc-db2`. This fix was kindly provided Severin Gehwolf and is added as second commit of this PR as 1. integration tests need the fix 2. no point of creating additional integration test module that combines jdbc-oracle and jdbc-db2 as we already have them here.
@michalvavrik michalvavrik force-pushed the feature/ot-jdbc-oracle-register-driver branch from 01547ca to 24735ab Compare January 17, 2023 09:55
@michalvavrik
Copy link
Member Author

Rebased the PR to resolve merge conflicts. No changes made, still waiting for the review.

@quarkus-bot
Copy link

quarkus-bot bot commented Jan 17, 2023

Failing Jobs - Building 24735ab

Status Name Step Failures Logs Raw logs
Native Tests - Misc4 Build ⚠️ Check → Logs Raw logs

@gsmet gsmet merged commit df60a85 into quarkusio:main Jan 19, 2023
@quarkus-bot quarkus-bot bot added this to the 2.17 - main milestone Jan 19, 2023
@michalvavrik michalvavrik deleted the feature/ot-jdbc-oracle-register-driver branch January 20, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/agroal area/core area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure area/persistence OBSOLETE, DO NOT USE area/tracing kind/bugfix
Projects
Status: Done
8 participants