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)
```
This commit is contained in:
parent
49d19464a7
commit
f971bcf0fd
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue