From f971bcf0fd666fae73821e94f00fd20840d91113 Mon Sep 17 00:00:00 2001 From: Evgeniy Devyatykh Date: Wed, 7 May 2025 18:14:51 +0500 Subject: [PATCH] To prevent NPE use pool name for metrics if JDBC URL is not set. (#754) HikariCP pool can be configured using JDBC URL: ``` HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://localhost:3306/simpsons"); ``` or using data source properties ``` Properties props = new Properties(); props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource"); props.setProperty("dataSource.serverName", "localhost"); ... HikariConfig config = new HikariConfig(props); HikariDataSource ds = new HikariDataSource(config) ``` --- CHANGES.md | 1 + .../apm/plugin/hikaricp/PoolingSealInterceptor.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1f4fb1347..aa57174d6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ Release Notes. * Add the virtual thread executor plugin * Fix Conflicts apm-jdk-threadpool-plugin conflicts with apm-jdk-forkjoinpool-plugin +* Fix NPE in hikaricp-plugin if JDBC URL is not set All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/236?closed=1) diff --git a/apm-sniffer/apm-sdk-plugin/hikaricp-3.x-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hikaricp/PoolingSealInterceptor.java b/apm-sniffer/apm-sdk-plugin/hikaricp-3.x-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hikaricp/PoolingSealInterceptor.java index 7be4b562c..a2673afbf 100644 --- a/apm-sniffer/apm-sdk-plugin/hikaricp-3.x-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hikaricp/PoolingSealInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/hikaricp-3.x-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hikaricp/PoolingSealInterceptor.java @@ -49,8 +49,13 @@ public class PoolingSealInterceptor implements InstanceMethodsAroundInterceptor public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { HikariDataSource hikariDataSource = (HikariDataSource) objInst; - ConnectionInfo connectionInfo = URLParser.parser(hikariDataSource.getJdbcUrl()); - String tagValue = connectionInfo.getDatabaseName() + "_" + connectionInfo.getDatabasePeer(); + String tagValue; + if (hikariDataSource.getJdbcUrl() != null) { + ConnectionInfo connectionInfo = URLParser.parser(hikariDataSource.getJdbcUrl()); + tagValue = connectionInfo.getDatabaseName() + "_" + connectionInfo.getDatabasePeer(); + } else { + tagValue = hikariDataSource.getPoolName(); + } final Map>> poolMetricMap = getPoolMetrics(); final Map>> metricConfigMap = getConfigMetrics(); poolMetricMap.forEach((key, value) -> MeterFactory.gauge(METER_NAME, value.apply(hikariDataSource.getHikariPoolMXBean()))