justinmclean opened a new issue, #10122:
URL: https://github.com/apache/gravitino/issues/10122

   ### What would you like to be improved?
   
   JdbcCatalogMetricsSource.registerDatasourceMetrics(DataSource dataSource) 
currently performs an unconditional cast to BasicDataSource. This makes the 
method unsafe for any valid DataSource implementation, and it can fail at 
runtime with a ClassCastException. The improvement needed is to make datasource 
metric registration robust across non-DBCP DataSource instances, or at minimum 
fail safely.
   
   ### How should we improve?
   
   Update registerDatasourceMetrics to handle non-BasicDataSource inputs 
safely, rather than casting directly.
   
   Here's a unit test to show the issue:
   ```
   public class TestJdbcCatalogMetricsSource {
   
     @Test
     public void testRegisterDatasourceMetricsWithNonBasicDataSource() {
       JdbcCatalogMetricsSource source = new 
JdbcCatalogMetricsSource("metalake", "catalog");
   
       DataSource nonBasicDataSource =
           new DataSource() {
             @Override
             public Connection getConnection() {
               return null;
             }
   
             @Override
             public Connection getConnection(String username, String password) {
               return null;
             }
   
             @Override
             public PrintWriter getLogWriter() {
               return null;
             }
   
             @Override
             public void setLogWriter(PrintWriter out) {}
   
             @Override
             public void setLoginTimeout(int seconds) {}
   
             @Override
             public int getLoginTimeout() {
               return 0;
             }
   
             @Override
             public Logger getParentLogger() throws 
SQLFeatureNotSupportedException {
               return Logger.getGlobal();
             }
   
             @Override
             public <T> T unwrap(Class<T> iface) throws SQLException {
               throw new SQLException("Not a wrapper");
             }
   
             @Override
             public boolean isWrapperFor(Class<?> iface) {
               return false;
             }
           };
   
       Assertions.assertDoesNotThrow(() -> 
source.registerDatasourceMetrics(nonBasicDataSource));
     }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to