fix multi-db-instance on same host port (#18)
This commit is contained in:
parent
c872adc20c
commit
f191953689
|
|
@ -16,6 +16,7 @@ Release Notes.
|
|||
* Advanced Kafka Producer configuration enhancement.
|
||||
* Support mTLS for gRPC channel.
|
||||
* fix the bug that plugin record wrong time elapse for lettuce plugin
|
||||
* fix the bug that the wrong db.instance value displayed on Skywalking-UI when existing multi-database-instance on same host port pair.
|
||||
|
||||
#### Documentation
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class ConnectionCreate5xInterceptor implements StaticMethodsAroundInterce
|
|||
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Object ret) {
|
||||
if (ret instanceof EnhancedInstance) {
|
||||
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[0].toString(), allArguments[1].toString());
|
||||
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[0].toString(), allArguments[1].toString(), allArguments[3].toString());
|
||||
if (connectionInfo == null) {
|
||||
connectionInfo = URLParser.parser(allArguments[4].toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,12 @@ public class ConnectionCreateOldInterceptor implements StaticMethodsAroundInterc
|
|||
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
|
||||
Object ret) {
|
||||
if (ret instanceof EnhancedInstance) {
|
||||
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[1].toString(), allArguments[2].toString());
|
||||
String database = "";
|
||||
try {
|
||||
Method getDbMethod = parameterTypes[0].getDeclaredMethod("getDatabase");
|
||||
database = (String) getDbMethod.invoke(allArguments[0]);
|
||||
} catch (Throwable t) { }
|
||||
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[1].toString(), allArguments[2].toString(), database);
|
||||
((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo);
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class ConnectionCreateInterceptor implements StaticMethodsAroundIntercept
|
|||
Object ret) {
|
||||
if (ret instanceof EnhancedInstance) {
|
||||
final HostInfo hostInfo = (HostInfo) allArguments[0];
|
||||
ConnectionInfo connectionInfo = ConnectionCache.get(hostInfo.getHostPortPair());
|
||||
ConnectionInfo connectionInfo = ConnectionCache.get(hostInfo.getHostPortPair(), hostInfo.getDatabase());
|
||||
((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo);
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -28,19 +28,19 @@ public class ConnectionCache {
|
|||
|
||||
private static final String CONNECTION_SPLIT_STR = ",";
|
||||
|
||||
public static ConnectionInfo get(String host, String port) {
|
||||
final String hostPortPair = String.format("%s:%s", host, port);
|
||||
public static ConnectionInfo get(String host, String port, String databaseName) {
|
||||
final String hostPortPair = String.format("%s:%s/%s", host, port, databaseName);
|
||||
return CONNECTIONS_MAP.get(hostPortPair);
|
||||
}
|
||||
|
||||
public static ConnectionInfo get(String hostPortPair) {
|
||||
return CONNECTIONS_MAP.get(hostPortPair);
|
||||
public static ConnectionInfo get(String hostPortPair, String databaseName) {
|
||||
return CONNECTIONS_MAP.get(hostPortPair + "/" + databaseName);
|
||||
}
|
||||
|
||||
public static void save(ConnectionInfo connectionInfo) {
|
||||
for (String conn : connectionInfo.getDatabasePeer().split(CONNECTION_SPLIT_STR)) {
|
||||
if (!StringUtil.isEmpty(conn)) {
|
||||
CONNECTIONS_MAP.putIfAbsent(conn, connectionInfo);
|
||||
CONNECTIONS_MAP.putIfAbsent(conn + "/" + connectionInfo.getDatabaseName(), connectionInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue