aws / aws-advanced-jdbc-wrapper

The Amazon Web Services JDBC Driver has been redesigned as an advanced JDBC wrapper. This wrapper is complementary to and extends the functionality of an existing JDBC driver to help an application take advantage of the features of clustered databases such as Amazon Aurora.
Apache License 2.0
216 stars 45 forks source link

Is there a way to read active plugins? #1115

Open KrohnicDev opened 1 month ago

KrohnicDev commented 1 month ago

Hi! I would like to read programmatically what plugins are active when wrapperPlugins property is not explicitly set, i.e. what are the default plugins. Is there an API for that?

sergiyvamz commented 1 month ago

Hi @KrohnicDev

Thank you for reaching out! Unfortunately there's no API that can help you to read a list of active plugins. Plugins are loaded based on wrapperPlugins property. Is property isn't specified then default plugins are loaded.

https://github.com/aws/aws-advanced-jdbc-wrapper/blob/84e089aac7b88abc61faf23b1c423013b548b314/wrapper/src/main/java/software/amazon/jdbc/ConnectionPluginChainBuilder.java#L114

Would you be able to provide a brief description on the issue you're trying to solve by getting a list of active plugins? Thank you!

KrohnicDev commented 1 month ago

I would like to print what plugins are active on startup AND allow use of default plugins. Currently there is no way to do both. If you want to print active plugins, you have to set them explicitly.

sergiyvamz commented 1 month ago

Hi @KrohnicDev

There's a logging of a loaded and rearranged plugins. It's a list of effective plugins that takes into account wrapperPlugins configuration parameter, plugin factories from configuration profiles and various internal defaults. You might find it useful.

2024-09-06T16:42:27.5383755Z         [2024-09-06 16:42:27.464] [FINEST ] [Test worker] [software.amazon.jdbc.ConnectionPluginChainBuilder getPlugins] : Plugins order has been rearranged. The following order is in effect: AuroraConnectionTrackerPluginFactory, FailoverConnectionPluginFactory, HostMonitoringConnectionPluginFactory  

https://github.com/aws/aws-advanced-jdbc-wrapper/blob/31436c51060829db15cad309ab265a192d494b23/wrapper/src/main/java/software/amazon/jdbc/ConnectionPluginChainBuilder.java#L168

KrohnicDev commented 3 weeks ago

Thanks. I also have a use case where I would like to execute some logic based on whether efm/efm2 plugin is active. Based on this discussion, I assume that it's currently not possible. Could you please confirm?

sergiyvamz commented 2 weeks ago

Hi @KrohnicDev

I think you can use the following workaround to check whether particular plugin is loaded. The idea is described here:

https://github.com/aws/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/using-plugins/UsingTheDeveloperPlugin.md

The code example provided on that page shows how to use unwrap() method on a database connection to access ExceptionSimulator (that is implemented by Developer Plugin). You can use the same approach to get a reference to efm/efm2 plugin instance loaded for a connection. You can use the following classes as a parameter to unwrap() method.

software.amazon.jdbc.plugin.efm.HostMonitoringConnectionPlugin software.amazon.jdbc.plugin.efm2.HostMonitoringConnectionPlugin

Please pat attention that unwrap() raises a SQLException if plugin is not presented/loaded for a particular connection.

I hope that helps.