You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2025/05/07 13:14:57 UTC
(skywalking-java) branch main updated: To prevent NPE use pool name for metrics if JDBC URL is not set. (#754)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git
The following commit(s) were added to refs/heads/main by this push:
new f971bcf0fd To prevent NPE use pool name for metrics if JDBC URL is not set. (#754)
f971bcf0fd is described below
commit f971bcf0fd666fae73821e94f00fd20840d91113
Author: Evgeniy Devyatykh <de...@gmail.com>
AuthorDate: Wed May 7 18:14:51 2025 +0500
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 +
.../skywalking/apm/plugin/hikaricp/PoolingSealInterceptor.java | 9 +++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 1f4fb1347f..aa57174d65 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 7be4b562c2..a2673afbf9 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<String, Function<HikariPoolMXBean, Supplier<Double>>> poolMetricMap = getPoolMetrics();
final Map<String, Function<HikariConfigMXBean, Supplier<Double>>> metricConfigMap = getConfigMetrics();
poolMetricMap.forEach((key, value) -> MeterFactory.gauge(METER_NAME, value.apply(hikariDataSource.getHikariPoolMXBean()))