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

adding support for null path in generic_url_like #7043

Closed
wants to merge 3 commits into from

Conversation

cmunger
Copy link

@cmunger cmunger commented Nov 4, 2022

Some unsupported jdbc driver using JdbcConnectionUrlParser.GENERIC_URL_LIKE may return a null path creating a nullpointer exception and not setting correctly the uri host and port

@cmunger cmunger requested a review from a team November 4, 2022 12:14
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 4, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

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

Thanks!
Can you also add a test case that covers this scenario?

@cmunger
Copy link
Author

cmunger commented Nov 7, 2022

Well i tried to add a testcase but had really hard time with the build and setting up groovy in my IDE, after some time i gave up.. let me know if the testcase is mandatory for this small change

@trask
Copy link
Member

trask commented Nov 8, 2022

@cmunger can you give an example of a jdbc url that will throw NullPointerException here? I can plug add it as a test case in JdbcConnectionUrlParserTest if you are still having trouble.

@cmunger
Copy link
Author

cmunger commented Nov 9, 2022

Hello trask thanks for your proposal as i've really struggled to setup the dev env :

[otel.javaagent 2022-11-09 09:13:29:864 +0100] [main] DEBUG io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser - null
java.lang.NullPointerException
	at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser$1.doParse(JdbcConnectionUrlParser.java:52)
	at io.opentelemetry.javaagent.shaded.instrumentation.jdbc.internal.JdbcConnectionUrlParser.parse(JdbcConnectionUrlParser.java:874)
	at zzz.zzzzzzzzz.zzz.zzz.ProxyDriver.connect(ProxyDriver.java:xxx)
	at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319)
	at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212)
	at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:744)

we are using a proxy driver that was used for metrics and we will use this kind of URL :

jdbc:proxy:jdbc:oracle:thin:@oracle-xe.docker:1521:XE

so the important point is that it uses a db driver that is not stock supported by opentelemetry (jdbc:proxy) and will end up using JdbcConnectionUrlParser.GENERIC_URL_LIKE connection parses where the NPE occurs
hope it helps

@trask
Copy link
Member

trask commented Nov 9, 2022

@cmunger I wasn't able to push to your branch, but you can cherry-pick the commit from here: trask@d2c6399

though you'll notice that even after removing the NPE, it still doesn't pick up the host/port

@cmunger
Copy link
Author

cmunger commented Nov 10, 2022

thanks @trask , i took your test and i realized that the fix for the null path is kind indeed useless and does not provides correct DBInfo for this specific case with a proxy jdbc driver, i modified as you can see the codebase and test to correctly parse the jdbc url by looking at the last index of jdbc:, all the tests with other urls where still green and it should not create side effects i think, i let your team decide if they want to take this or not. Thanks for your help

@trask
Copy link
Member

trask commented Nov 22, 2022

hey @cmunger, what is jdbc:proxy:...? maybe it makes sense to create special handling for that (similar to how other jdbc prefixes are handled)?

@cmunger
Copy link
Author

cmunger commented Nov 22, 2022

@trask this jdbc:proxy prefix is an enterprise custom made proxy driver that is used for stats and monitoring purposes over other existing jdbc drivers (like jdbc:proxy:jdbc:oracle.....), we are migrating to your stack but all app cannot be upgraded quickly to stop using this proxy driver. As this is is not a generic tool with open source code i don't think it's appropriate to create a special handling like for other jdbc drivers. With this fix the target driver connection info are correctly handled and should not create regressions in handling of other drivers db info parsing.

@mateuszrzeszutek
Copy link
Member

mateuszrzeszutek commented Nov 22, 2022

As this is is not a generic tool with open source code i don't think it's appropriate to create a special handling like for other jdbc drivers.

Consider excluding your custom proxy driver classes/package from instrumentation: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/advanced-configuration-options.md#excluding-specific-classes-from-being-instrumented

Still, even if that works for you, I do believe that we should include the if (path == null) part - throwing an NPE is a no-go, I think it's better (less bad? 😅 ) to have broken telemetry than a broken application.

(also linking related issue #5012)

@trask
Copy link
Member

trask commented Nov 23, 2022

@cmunger the current fix seems targeted at there being a second jdbc:, which doesn't seem like a typical pattern for wrappers, so not sure if we should encode that logic.

I really like @mateuszrzeszutek's suggestion, can you see if you can get that to work?

@cmunger
Copy link
Author

cmunger commented Nov 25, 2022

@mateuszrzeszutek i'll try your class exclusions setting hint, i m just worried it will stop instrumentalizing then underlying driver.. concerning the if (path == null) missing it will not crash the opentelementry app, simply will not parse correctly the dbinfo and will be missing info when data is exported from jvm to kibana apm or other system.. i guess you can close this pr then. thanks for your help

@trask trask closed this Feb 23, 2023
@trask trask mentioned this pull request Apr 3, 2023
mateuszrzeszutek pushed a commit that referenced this pull request Apr 3, 2023
this is a follow-up to #7043

I tried to add a test when that PR was opened:

*
trask@d2c6399

but it doesn't really verify anything, since the NPE is throw/caught and
same behavior occurs
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.

3 participants