提交 eb9b9a12 编写于 作者: L lytscu

add mongodb 2.x enhance plugin

上级 06c017ff
......@@ -29,7 +29,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mongodb-2.x-plugin</artifactId>
<artifactId>apm-mongodb-2.x-plugin</artifactId>
<packaging>jar</packaging>
<properties>
......
......@@ -34,6 +34,9 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptR
import org.skywalking.apm.network.trace.component.ComponentsDefine;
/**
* {@link MongoDBV2MethodInterceptor} intercept method of {@link com.mongodb.DBCollection#find()}
*or{@link com.mongodb.DBCollectionImpl#insertImpl}.... record the mongoDB host, operation name ...
*
* @Auther liyuntao
*/
......@@ -79,4 +82,5 @@ public class MongoDBV2MethodInterceptor implements InstanceMethodsAroundIntercep
objInst.setSkyWalkingDynamicField(peers.subSequence(0, peers.length() - 1).toString());
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.plugin.mongodb.v2.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
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.named;
import static org.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
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 {
private static final String ENHANCE_CLASS = "com.mongodb.DBCollection";
private static final String MONGDB_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.mongodb.v2.MongoDBV2MethodInterceptor";
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return null;
}
@Override
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("find");
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("mapReduce").and(takesArgumentWithType(0, "com.mongodb.MapReduceCommand"));
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("aggregate").and(takesArgumentWithType(1, "com.mongodb.ReadPreference"));
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("aggregate").and(takesArgumentWithType(2, "com.mongodb.ReadPreference"));
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("createIndex").and(takesArgumentWithType(2, "boolean"));
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
protected String[] witnessClasses() {
/**
* @see {@link com.mongodb.tools.ConnectionPoolStat}
*/
return new String[] {
"com.mongodb.tools.ConnectionPoolStat"
};
}
}
......@@ -24,22 +24,25 @@ 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;
/**
* {@link MongoDBCollectionInstrumentation} presents that skywalking intercepts {@link com.mongodb.DBCollectionImpl#find()},
* {@link com.mongodb.DBCollectionImpl#insertImpl} by using {@link MongoDBV2MethodInterceptor}.
*
* @Auther liyuntao
*/
public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.mongodb.DBCollection";
private static final String ENHANCE_CLASS = "com.mongodb.DBCollectionImpl";
private static final String MONGDB_METHOD_INTERCET_CLASS = "org.skywalking.apm.plugin.mongodb.v2.MongoDBV2MethodInterceptor";
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[] {
......@@ -63,7 +66,55 @@ public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginD
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("getWriteConcern");
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() {
return named("insertImpl");
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return takesArgumentWithType(1, "boolean");
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("updateImpl");
}
@Override
......@@ -79,7 +130,39 @@ public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginD
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("getReadPreference");
return named("findAndModifyImpl");
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("drop");
}
@Override
public String getMethodsInterceptor() {
return MONGDB_METHOD_INTERCET_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("createIndex");
}
@Override
......@@ -100,4 +183,14 @@ public class MongoDBV2Instrumentation extends ClassInstanceMethodsEnhancePluginD
return byName(ENHANCE_CLASS);
}
@Override
protected String[] witnessClasses() {
/**
* @see {@link com.mongodb.tools.ConnectionPoolStat}
*/
return new String[] {
"com.mongodb.tools.ConnectionPoolStat"
};
}
}
mongodb-2.x=org.skywalking.apm.plugin.mongodb.v2.define.MongoDBV2Instrumentation
mongodb-2.x=org.skywalking.apm.plugin.mongodb.v2.define.MongoDBCollectionInstrumentation
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册