1、Modify the code review. 2、Modify V3 plugin to support all version 3.x
This commit is contained in:
parent
eb9b9a1222
commit
b63c0ac572
|
|
@ -24,9 +24,8 @@ import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoin
|
|||
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.skywalking.apm.plugin.mongodb.v2.MongoDBV2MethodInterceptor;
|
||||
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
|
@ -34,8 +33,6 @@ import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
|||
/**
|
||||
* {@link MongoDBCollectionInstrumentation} presents that skywalking intercepts {@link com.mongodb.DBCollection#find()},
|
||||
* {@link com.mongodb.DBCollection#mapReduce} by using {@link MongoDBV2MethodInterceptor}.
|
||||
*
|
||||
* @Auther liyuntao
|
||||
*/
|
||||
public class MongoDBCollectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
|
|
@ -45,7 +42,19 @@ public class MongoDBCollectionInstrumentation extends ClassInstanceMethodsEnhanc
|
|||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return null;
|
||||
return new ConstructorInterceptPoint[] {
|
||||
new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return MONGDB_METHOD_INTERCET_CLASS;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -130,7 +139,39 @@ public class MongoDBCollectionInstrumentation extends ClassInstanceMethodsEnhanc
|
|||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("insert").and(takesArgumentWithType(2, "com.mongodb.DBEncoder"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return MONGDB_METHOD_INTERCET_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("update").and(takesArgumentWithType(5, "com.mongodb.DBEncoder"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return MONGDB_METHOD_INTERCET_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoin
|
|||
import org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import org.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.skywalking.apm.plugin.mongodb.v2.MongoDBV2MethodInterceptor;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
|
@ -32,10 +31,9 @@ import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMat
|
|||
import static org.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* {@link MongoDBCollectionInstrumentation} presents that skywalking intercepts {@link com.mongodb.DBCollectionImpl#find()},
|
||||
* {@link com.mongodb.DBCollectionImpl#insertImpl} by using {@link MongoDBV2MethodInterceptor}.
|
||||
*
|
||||
* @Auther liyuntao
|
||||
* {@link MongoDBCollectionInstrumentation} presents that skywalking intercepts {@link
|
||||
* com.mongodb.DBCollectionImpl#find()}, {@link com.mongodb.DBCollectionImpl#insertImpl} by using {@link
|
||||
* MongoDBV2MethodInterceptor}.
|
||||
*/
|
||||
public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
|
|
@ -63,22 +61,7 @@ public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginD
|
|||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("find").and(takesArgumentWithType(8, "com.mongodb.DBEncoder"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return MONGDB_METHOD_INTERCET_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
|
|
@ -98,7 +81,7 @@ public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginD
|
|||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return takesArgumentWithType(1, "boolean");
|
||||
return named("remove").and(takesArgumentWithType(1, "boolean"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -117,7 +117,6 @@ public class MongoDBV2MethodInterceptorTest {
|
|||
try {
|
||||
return Mongo.class.getMethod("getWriteConcern");
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,11 +200,18 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
|
|||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
||||
Cluster cluster = (Cluster)allArguments[0];
|
||||
StringBuilder peers = new StringBuilder();
|
||||
for (ServerDescription description : cluster.getDescription().getServerDescriptions()) {
|
||||
List<ServerDescription> servers;
|
||||
try {
|
||||
cluster.getDescription().getClass().getMethod("getServerDescriptions", null);
|
||||
servers = cluster.getDescription().getServerDescriptions();
|
||||
|
||||
} catch (NoSuchMethodException e) {
|
||||
servers = cluster.getDescription().getAny();
|
||||
}
|
||||
for (ServerDescription description : servers) {
|
||||
ServerAddress address = description.getAddress();
|
||||
peers.append(address.getHost() + ":" + address.getPort() + ";");
|
||||
}
|
||||
|
||||
objInst.setSkyWalkingDynamicField(peers.subSequence(0, peers.length() - 1).toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue