Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
e8084e54
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8084e54
编写于
4月 19, 2017
作者:
B
baiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs
上级
085f9b69
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
337 addition
and
61 deletion
+337
-61
skywalking-sniffer/skywalking-agent/pom.xml
skywalking-sniffer/skywalking-agent/pom.xml
+1
-1
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/pom.xml
...-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/pom.xml
+6
-11
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptor.java
...kywalking/plugin/mongodb/v3/MongoDBMethodInterceptor.java
+70
-31
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBReadBindingInterceptor.java
...king/plugin/mongodb/v3/MongoDBReadBindingInterceptor.java
+2
-4
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBWriteBindingInterceptor.java
...ing/plugin/mongodb/v3/MongoDBWriteBindingInterceptor.java
+2
-5
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/OperationInfo.java
...com/a/eye/skywalking/plugin/mongodb/v3/OperationInfo.java
+1
-1
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/ReadMethod.java
...va/com/a/eye/skywalking/plugin/mongodb/v3/ReadMethod.java
+1
-1
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/WriteMethod.java
...a/com/a/eye/skywalking/plugin/mongodb/v3/WriteMethod.java
+1
-1
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3/define/MongoDBInstrumentation.java
...king/plugin/mongodb/v3/define/MongoDBInstrumentation.java
+4
-4
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/resources/skywalking-plugin.def
...ngodb-3.x-plugin/src/main/resources/skywalking-plugin.def
+1
-0
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/test/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java
...lking/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java
+125
-0
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/test/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBReadBindingInterceptorTest.java
.../plugin/mongodb/v3/MongoDBReadBindingInterceptorTest.java
+61
-0
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/test/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBWriteBindingInterceptorTest.java
...plugin/mongodb/v3/MongoDBWriteBindingInterceptorTest.java
+61
-0
skywalking-sniffer/skywalking-sdk-plugin/mongodb-plugin/src/main/resources/skywalking-plugin.def
...n/mongodb-plugin/src/main/resources/skywalking-plugin.def
+0
-1
skywalking-sniffer/skywalking-sdk-plugin/pom.xml
skywalking-sniffer/skywalking-sdk-plugin/pom.xml
+1
-1
未找到文件。
skywalking-sniffer/skywalking-agent/pom.xml
浏览文件 @
e8084e54
...
...
@@ -57,7 +57,7 @@
</dependency>
<dependency>
<groupId>
com.a.eye
</groupId>
<artifactId>
skywalking-mongodb-plugin
</artifactId>
<artifactId>
skywalking-mongodb-
3.x-
plugin
</artifactId>
<version>
${project.version}
</version>
</dependency>
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-plugin/pom.xml
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-
plugin/pom.xml
浏览文件 @
e8084e54
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<artifactId>
skywalking-sdk-plugin
</artifactId>
<groupId>
com.a.eye
</groupId>
<version>
3.0.1-2017
</version>
</parent>
<artifactId>
skywalking-mongodb-plugin
</artifactId>
<artifactId>
skywalking-mongodb-
3.x-
plugin
</artifactId>
<packaging>
jar
</packaging>
<name>
mongodb-plugin
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongo-java-driver
</artifactId>
...
...
@@ -30,7 +25,7 @@
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/MongoDBMethodInterceptor.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/MongoDBMethodInterceptor.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb
;
package
com.a.eye.skywalking.plugin.mongodb
.v3
;
import
java.util.List
;
import
org.bson.BsonDocument
;
import
com.a.eye.skywalking.api.context.ContextManager
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
...
...
@@ -9,6 +11,7 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAround
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult
;
import
com.a.eye.skywalking.trace.Span
;
import
com.a.eye.skywalking.trace.tag.Tags
;
import
com.mongodb.ReadPreference
;
import
com.mongodb.bulk.DeleteRequest
;
import
com.mongodb.bulk.InsertRequest
;
import
com.mongodb.bulk.UpdateRequest
;
...
...
@@ -29,11 +32,14 @@ import com.mongodb.operation.ListCollectionsOperation;
import
com.mongodb.operation.MapReduceToCollectionOperation
;
import
com.mongodb.operation.MapReduceWithInlineResultsOperation
;
import
com.mongodb.operation.MixedBulkWriteOperation
;
import
com.mongodb.operation.ReadOperation
;
import
com.mongodb.operation.UpdateOperation
;
import
com.mongodb.operation.WriteOperation
;
/**
* {@link MongoDBMethodInterceptor} intercept method of {@link com.mongodb.Mongo#execute(ReadOperation, ReadPreference)}
* or {@link com.mongodb.Mongo#execute(WriteOperation)}. record the mongoDB host, operation name and the key of the operation.
* or {@link com.mongodb.Mongo#execute(WriteOperation)}. record the mongoDB host, operation name and the key of the
* operation.
*
* @author baiyang
*/
...
...
@@ -42,21 +48,25 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
/**
* The key name that MongoDB host in {@link EnhancedClassInstanceContext#context}.
*/
protected
static
final
String
MONGODB_HOST
=
"MONGODB_HOST"
;
static
final
String
MONGODB_HOST
=
"MONGODB_HOST"
;
/**
* The key name that MongoDB port in {@link EnhancedClassInstanceContext#context}.
*/
protected
static
final
String
MONGODB_PORT
=
"MONGODB_PORT"
;
static
final
String
MONGODB_PORT
=
"MONGODB_PORT"
;
private
static
final
String
MONGODB_COMPONENT
=
"MongoDB"
;
private
static
final
String
METHOD
=
"MongoDB/"
;
private
static
final
int
FILTER_LENGTH_LIMIT
=
256
;
@Override
public
void
beforeMethod
(
final
EnhancedClassInstanceContext
context
,
final
InstanceMethodInvokeContext
interceptorContext
,
final
MethodInterceptResult
result
)
{
Object
[]
arguments
=
interceptorContext
.
allArguments
();
OperationInfo
operationInfo
=
this
.
getReadOperationInfo
(
arguments
[
0
]);
Span
span
=
ContextManager
.
createSpan
(
"MongoDB/"
+
operationInfo
.
getMethodName
());
Span
span
=
ContextManager
.
createSpan
(
METHOD
+
operationInfo
.
getMethodName
());
Tags
.
COMPONENT
.
set
(
span
,
MONGODB_COMPONENT
);
Tags
.
DB_TYPE
.
set
(
span
,
MONGODB_COMPONENT
);
Tags
.
SPAN_KIND
.
set
(
span
,
Tags
.
SPAN_KIND_CLIENT
);
...
...
@@ -81,58 +91,87 @@ public class MongoDBMethodInterceptor implements InstanceMethodsAroundIntercepto
}
/**
*
Convert ReadOperation interface or WriteOperation interface to the implementation class.
*
Get the method name and
filter info.
*
Convert ReadOperation interface or WriteOperation interface to the implementation class. Get the method name and
* filter info.
*/
@SuppressWarnings
(
"rawtypes"
)
private
OperationInfo
getReadOperationInfo
(
Object
obj
)
{
if
(
obj
instanceof
CountOperation
)
{
return
new
OperationInfo
(
ReadMethod
.
COUNT
.
getName
(),
((
CountOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
CountOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
ReadMethod
.
COUNT
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
DistinctOperation
)
{
return
new
OperationInfo
(
ReadMethod
.
DISTINCT
.
getName
(),
((
DistinctOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
DistinctOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
ReadMethod
.
DISTINCT
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
FindOperation
)
{
return
new
OperationInfo
(
ReadMethod
.
FIND
.
getName
(),
((
FindOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
FindOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
ReadMethod
.
FIND
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
GroupOperation
)
{
return
new
OperationInfo
(
ReadMethod
.
GROUP
.
getName
(),
((
GroupOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
GroupOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
ReadMethod
.
GROUP
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
ListCollectionsOperation
)
{
return
new
OperationInfo
(
ReadMethod
.
LIST_COLLECTIONS
.
getName
(),
((
ListCollectionsOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
ListCollectionsOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
ReadMethod
.
LIST_COLLECTIONS
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
MapReduceWithInlineResultsOperation
)
{
return
new
OperationInfo
(
ReadMethod
.
MAPREDUCE_WITHINLINE_RESULTS
.
getName
(),
((
ListCollectionsOperation
)
obj
).
getFilter
().
toString
());
}
else
if
(
obj
instanceof
DeleteOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
DELETE
.
getName
(),
((
DeleteOperation
)
obj
).
getDeleteRequests
().
toString
());
BsonDocument
filter
=
((
ListCollectionsOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
ReadMethod
.
MAPREDUCE_WITHINLINE_RESULTS
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
DeleteOperation
)
{
List
<
DeleteRequest
>
filter
=
((
DeleteOperation
)
obj
).
getDeleteRequests
();
return
new
OperationInfo
(
WriteMethod
.
DELETE
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
InsertOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
INSERT
.
getName
(),
((
InsertOperation
)
obj
).
getInsertRequests
().
toString
());
List
<
InsertRequest
>
filter
=
((
InsertOperation
)
obj
).
getInsertRequests
();
return
new
OperationInfo
(
WriteMethod
.
INSERT
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
UpdateOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
UPDATE
.
getName
(),
((
UpdateOperation
)
obj
).
getUpdateRequests
().
toString
());
List
<
UpdateRequest
>
filter
=
((
UpdateOperation
)
obj
).
getUpdateRequests
();
return
new
OperationInfo
(
WriteMethod
.
UPDATE
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
CreateCollectionOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
CREATECOLLECTION
.
getName
(),
((
CreateCollectionOperation
)
obj
).
getCollectionName
());
String
filter
=
((
CreateCollectionOperation
)
obj
).
getCollectionName
();
return
new
OperationInfo
(
WriteMethod
.
CREATECOLLECTION
.
getName
(),
limitFilter
(
filter
));
}
else
if
(
obj
instanceof
CreateIndexesOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
CREATEINDEXES
.
getName
(),
((
CreateIndexesOperation
)
obj
).
getIndexNames
().
toString
());
List
<
String
>
filter
=
((
CreateIndexesOperation
)
obj
).
getIndexNames
();
return
new
OperationInfo
(
WriteMethod
.
CREATEINDEXES
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
CreateViewOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
CREATEVIEW
.
getName
(),
((
CreateViewOperation
)
obj
).
getViewName
());
String
filter
=
((
CreateViewOperation
)
obj
).
getViewName
();
return
new
OperationInfo
(
WriteMethod
.
CREATEVIEW
.
getName
(),
limitFilter
(
filter
));
}
else
if
(
obj
instanceof
FindAndDeleteOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
FINDANDDELETE
.
getName
(),
((
FindAndDeleteOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
FindAndDeleteOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
WriteMethod
.
FINDANDDELETE
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
FindAndReplaceOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
FINDANDREPLACE
.
getName
(),
((
FindAndReplaceOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
FindAndReplaceOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
WriteMethod
.
FINDANDREPLACE
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
FindAndUpdateOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
FINDANDUPDATE
.
getName
(),
((
FindAndUpdateOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
FindAndUpdateOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
WriteMethod
.
FINDANDUPDATE
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
MapReduceToCollectionOperation
)
{
return
new
OperationInfo
(
WriteMethod
.
MAPREDUCETOCOLLECTION
.
getName
(),
((
MapReduceToCollectionOperation
)
obj
).
getFilter
().
toString
());
BsonDocument
filter
=
((
MapReduceToCollectionOperation
)
obj
).
getFilter
();
return
new
OperationInfo
(
WriteMethod
.
MAPREDUCETOCOLLECTION
.
getName
(),
limitFilter
(
filter
.
toString
()));
}
else
if
(
obj
instanceof
MixedBulkWriteOperation
)
{
List
<?
extends
WriteRequest
>
list
=
((
MixedBulkWriteOperation
)
obj
).
getWriteRequests
();
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
params
=
new
StringBuilder
();
for
(
WriteRequest
request
:
list
)
{
if
(
request
instanceof
InsertRequest
)
{
sb
.
append
(((
InsertRequest
)
request
).
getDocument
().
toString
()).
append
(
","
);
params
.
append
(((
InsertRequest
)
request
).
getDocument
().
toString
()).
append
(
","
);
}
else
if
(
request
instanceof
DeleteRequest
)
{
sb
.
append
(((
DeleteRequest
)
request
).
getFilter
()).
append
(
","
);
params
.
append
(((
DeleteRequest
)
request
).
getFilter
()).
append
(
","
);
}
else
if
(
request
instanceof
UpdateRequest
)
{
sb
.
append
(((
UpdateRequest
)
request
).
getFilter
()).
append
(
","
);
params
.
append
(((
UpdateRequest
)
request
).
getFilter
()).
append
(
","
);
}
if
(
params
.
length
()
>
FILTER_LENGTH_LIMIT
)
{
params
.
append
(
"..."
);
break
;
}
}
return
new
OperationInfo
(
WriteMethod
.
MIXEDBULKWRITE
.
getName
(),
sb
.
toString
());
return
new
OperationInfo
(
WriteMethod
.
MIXEDBULKWRITE
.
getName
(),
params
.
toString
());
}
else
{
return
new
OperationInfo
(
obj
.
getClass
().
getSimpleName
());
}
}
private
String
limitFilter
(
String
filter
)
{
final
StringBuilder
params
=
new
StringBuilder
();
if
(
filter
.
length
()
>
FILTER_LENGTH_LIMIT
)
{
return
params
.
append
(
filter
.
substring
(
0
,
FILTER_LENGTH_LIMIT
)).
append
(
"..."
).
toString
();
}
else
{
return
new
OperationInfo
(
WriteMethod
.
UNKNOW
.
getName
())
;
return
filter
;
}
}
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/MongoDBReadBindingInterceptor.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/MongoDBReadBindingInterceptor.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb
;
package
com.a.eye.skywalking.plugin.mongodb
.v3
;
import
com.a.eye.skywalking.api.context.ContextManager
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult
;
import
com.mongodb.ReadPreference
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.binding.ReadBinding
;
...
...
@@ -18,7 +18,6 @@ public class MongoDBReadBindingInterceptor implements InstanceMethodsAroundInter
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
}
/**
...
...
@@ -40,7 +39,6 @@ public class MongoDBReadBindingInterceptor implements InstanceMethodsAroundInter
@Override
public
void
handleMethodException
(
Throwable
t
,
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
)
{
ContextManager
.
activeSpan
().
log
(
t
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/MongoDBWriteBindingInterceptor.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/MongoDBWriteBindingInterceptor.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb
;
package
com.a.eye.skywalking.plugin.mongodb
.v3
;
import
com.a.eye.skywalking.api.context.ContextManager
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
...
...
@@ -9,7 +8,7 @@ import com.mongodb.ServerAddress;
import
com.mongodb.binding.WriteBinding
;
/**
* {@link MongoDBWriteBindingInterceptor} record the host and port information from {@link EnhancedClassInstanceContext#context}
,
* {@link MongoDBWriteBindingInterceptor} record the host and port information from {@link EnhancedClassInstanceContext#context}
*
* @author baiyang
*/
...
...
@@ -18,7 +17,6 @@ public class MongoDBWriteBindingInterceptor implements InstanceMethodsAroundInte
@Override
public
void
beforeMethod
(
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
,
MethodInterceptResult
result
)
{
}
/**
...
...
@@ -40,7 +38,6 @@ public class MongoDBWriteBindingInterceptor implements InstanceMethodsAroundInte
@Override
public
void
handleMethodException
(
Throwable
t
,
EnhancedClassInstanceContext
context
,
InstanceMethodInvokeContext
interceptorContext
)
{
ContextManager
.
activeSpan
().
log
(
t
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/OperationInfo.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/OperationInfo.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb
;
package
com.a.eye.skywalking.plugin.mongodb
.v3
;
/**
* {@link OperationInfo} record the methodName and filter information
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/ReadMethod.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/ReadMethod.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb
;
package
com.a.eye.skywalking.plugin.mongodb
.v3
;
/**
* {@link ReadMethod} mongoDB read method enum
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/WriteMethod.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/WriteMethod.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb
;
package
com.a.eye.skywalking.plugin.mongodb
.v3
;
/**
* {@link WriteMethod} mongoDB write method enum
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb
/define/MongoDBInstrumentation.java
→
skywalking-sniffer/skywalking-sdk-plugin/mongodb-
3.x-plugin/src/main/java/com/a/eye/skywalking/plugin/mongodb/v3
/define/MongoDBInstrumentation.java
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb.define
;
package
com.a.eye.skywalking.plugin.mongodb.
v3.
define
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
net.bytebuddy.description.method.MethodDescription
;
...
...
@@ -18,11 +18,11 @@ public class MongoDBInstrumentation extends ClassInstanceMethodsEnhancePluginDef
private
static
final
String
ENHANCE_CLASS
=
"com.mongodb.Mongo"
;
private
static
final
String
MONGDB_READ_BINDING_CLASS
=
"com.a.eye.skywalking.plugin.mongodb.MongoDBReadBindingInterceptor"
;
private
static
final
String
MONGDB_READ_BINDING_CLASS
=
"com.a.eye.skywalking.plugin.mongodb.
v3.
MongoDBReadBindingInterceptor"
;
private
static
final
String
MONGDB_WRITE_BINDING_CLASS
=
"com.a.eye.skywalking.plugin.mongodb.MongoDBWriteBindingInterceptor"
;
private
static
final
String
MONGDB_WRITE_BINDING_CLASS
=
"com.a.eye.skywalking.plugin.mongodb.
v3.
MongoDBWriteBindingInterceptor"
;
private
static
final
String
MONGDB_METHOD_INTERCET_CLASS
=
"com.a.eye.skywalking.plugin.mongodb.MongoDBMethodInterceptor"
;
private
static
final
String
MONGDB_METHOD_INTERCET_CLASS
=
"com.a.eye.skywalking.plugin.mongodb.
v3.
MongoDBMethodInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
...
...
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
e8084e54
com.a.eye.skywalking.plugin.mongodb.v3.define.MongoDBInstrumentation
\ No newline at end of file
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/test/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBMethodInterceptorTest.java
0 → 100644
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb.v3
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
org.bson.BsonDocument
;
import
org.bson.BsonString
;
import
org.hamcrest.CoreMatchers
;
import
org.hamcrest.MatcherAssert
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
com.a.eye.skywalking.api.boot.ServiceManager
;
import
com.a.eye.skywalking.api.context.TracerContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener
;
import
com.a.eye.skywalking.sniffer.mock.context.SegmentAssert
;
import
com.a.eye.skywalking.trace.LogData
;
import
com.a.eye.skywalking.trace.Span
;
import
com.a.eye.skywalking.trace.TraceSegment
;
import
com.a.eye.skywalking.trace.tag.Tags
;
import
com.mongodb.operation.FindOperation
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MongoDBMethodInterceptorTest
{
private
MongoDBMethodInterceptor
interceptor
;
private
MockTracerContextListener
mockTracerContextListener
;
@Mock
private
EnhancedClassInstanceContext
classInstanceContext
;
@Mock
private
InstanceMethodInvokeContext
methodInvokeContext
;
@SuppressWarnings
(
"rawtypes"
)
@Mock
private
FindOperation
findOperation
;
@Before
public
void
setUp
()
throws
Exception
{
ServiceManager
.
INSTANCE
.
boot
();
interceptor
=
new
MongoDBMethodInterceptor
();
mockTracerContextListener
=
new
MockTracerContextListener
();
TracerContext
.
ListenerManager
.
add
(
mockTracerContextListener
);
when
(
classInstanceContext
.
get
(
MongoDBMethodInterceptor
.
MONGODB_HOST
,
String
.
class
)).
thenReturn
(
"127.0.0.1"
);
when
(
classInstanceContext
.
get
(
MongoDBMethodInterceptor
.
MONGODB_PORT
)).
thenReturn
(
27017
);
when
(
methodInvokeContext
.
methodName
()).
thenReturn
(
"find"
);
BsonDocument
document
=
new
BsonDocument
();
document
.
append
(
"name"
,
new
BsonString
(
"by"
));
when
(
findOperation
.
getFilter
()).
thenReturn
(
document
);
when
(
methodInvokeContext
.
allArguments
()).
thenReturn
(
new
Object
[]
{
findOperation
});
}
@Test
public
void
testIntercept
()
{
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
mockTracerContextListener
.
assertSize
(
1
);
mockTracerContextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertRedisSpan
(
span
);
}
});
}
@Test
public
void
testInterceptWithException
()
{
interceptor
.
beforeMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
interceptor
.
handleMethodException
(
new
RuntimeException
(),
classInstanceContext
,
methodInvokeContext
);
interceptor
.
afterMethod
(
classInstanceContext
,
methodInvokeContext
,
null
);
mockTracerContextListener
.
assertSize
(
1
);
mockTracerContextListener
.
assertTraceSegment
(
0
,
new
SegmentAssert
()
{
@Override
public
void
call
(
TraceSegment
traceSegment
)
{
assertThat
(
traceSegment
.
getSpans
().
size
(),
is
(
1
));
Span
span
=
traceSegment
.
getSpans
().
get
(
0
);
assertRedisSpan
(
span
);
assertThat
(
span
.
getLogs
().
size
(),
is
(
1
));
assertLogData
(
span
.
getLogs
().
get
(
0
));
}
});
}
private
void
assertLogData
(
LogData
logData
)
{
MatcherAssert
.
assertThat
(
logData
.
getFields
().
size
(),
is
(
4
));
MatcherAssert
.
assertThat
(
logData
.
getFields
().
get
(
"event"
),
CoreMatchers
.<
Object
>
is
(
"error"
));
assertEquals
(
logData
.
getFields
().
get
(
"error.kind"
),
RuntimeException
.
class
.
getName
());
assertNull
(
logData
.
getFields
().
get
(
"message"
));
}
private
void
assertRedisSpan
(
Span
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"MongoDB/find"
));
assertThat
(
Tags
.
PEER_HOST
.
get
(
span
),
is
(
"127.0.0.1"
));
assertThat
(
Tags
.
PEER_PORT
.
get
(
span
),
is
(
27017
));
assertThat
(
Tags
.
COMPONENT
.
get
(
span
),
is
(
"MongoDB"
));
assertThat
(
Tags
.
DB_STATEMENT
.
get
(
span
),
is
(
"find { \"name\" : \"by\" }"
));
assertThat
(
Tags
.
DB_TYPE
.
get
(
span
),
is
(
"MongoDB"
));
assertTrue
(
Tags
.
SPAN_LAYER
.
isDB
(
span
));
}
@After
public
void
tearDown
()
throws
Exception
{
TracerContext
.
ListenerManager
.
remove
(
mockTracerContextListener
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/test/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBReadBindingInterceptorTest.java
0 → 100644
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb.v3
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.binding.ConnectionSource
;
import
com.mongodb.binding.ReadBinding
;
import
com.mongodb.connection.ServerConnectionState
;
import
com.mongodb.connection.ServerDescription
;
@RunWith
(
PowerMockRunner
.
class
)
public
class
MongoDBReadBindingInterceptorTest
{
private
MongoDBReadBindingInterceptor
interceptor
;
@Mock
private
EnhancedClassInstanceContext
instanceContext
;
@Mock
private
InstanceMethodInvokeContext
interceptorContext
;
@Mock
private
ReadBinding
readBinding
;
@Mock
private
ConnectionSource
connectionSource
;
private
ServerAddress
address
=
new
ServerAddress
(
"127.0.0.1"
,
27017
);
@Before
public
void
setUp
()
throws
Exception
{
interceptor
=
new
MongoDBReadBindingInterceptor
();
ServerDescription
serverDescription
=
ServerDescription
.
builder
().
address
(
address
).
state
(
ServerConnectionState
.
CONNECTED
).
build
();
PowerMockito
.
when
(
connectionSource
.
getServerDescription
()).
thenReturn
(
serverDescription
);
PowerMockito
.
when
(
readBinding
.
getReadConnectionSource
()).
thenReturn
(
connectionSource
);
}
@Test
public
void
afterMethodTest
()
throws
Exception
{
interceptor
.
afterMethod
(
instanceContext
,
interceptorContext
,
readBinding
);
verify
(
instanceContext
,
times
(
1
)).
set
(
MongoDBMethodInterceptor
.
MONGODB_HOST
,
"127.0.0.1"
);
verify
(
instanceContext
,
times
(
1
)).
set
(
MongoDBMethodInterceptor
.
MONGODB_PORT
,
27017
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/mongodb-3.x-plugin/src/test/java/com/a/eye/skywalking/plugin/mongodb/v3/MongoDBWriteBindingInterceptorTest.java
0 → 100644
浏览文件 @
e8084e54
package
com.a.eye.skywalking.plugin.mongodb.v3
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext
;
import
com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.binding.ConnectionSource
;
import
com.mongodb.binding.WriteBinding
;
import
com.mongodb.connection.ServerConnectionState
;
import
com.mongodb.connection.ServerDescription
;
@RunWith
(
PowerMockRunner
.
class
)
public
class
MongoDBWriteBindingInterceptorTest
{
private
MongoDBWriteBindingInterceptor
interceptor
;
@Mock
private
EnhancedClassInstanceContext
instanceContext
;
@Mock
private
InstanceMethodInvokeContext
interceptorContext
;
@Mock
private
WriteBinding
writeBinding
;
@Mock
private
ConnectionSource
connectionSource
;
private
ServerAddress
address
=
new
ServerAddress
(
"127.0.0.1"
,
27017
);
@Before
public
void
setUp
()
throws
Exception
{
interceptor
=
new
MongoDBWriteBindingInterceptor
();
ServerDescription
serverDescription
=
ServerDescription
.
builder
().
address
(
address
).
state
(
ServerConnectionState
.
CONNECTED
).
build
();
PowerMockito
.
when
(
connectionSource
.
getServerDescription
()).
thenReturn
(
serverDescription
);
PowerMockito
.
when
(
writeBinding
.
getWriteConnectionSource
()).
thenReturn
(
connectionSource
);
}
@Test
public
void
afterMethodTest
()
throws
Exception
{
interceptor
.
afterMethod
(
instanceContext
,
interceptorContext
,
writeBinding
);
verify
(
instanceContext
,
times
(
1
)).
set
(
MongoDBMethodInterceptor
.
MONGODB_HOST
,
"127.0.0.1"
);
verify
(
instanceContext
,
times
(
1
)).
set
(
MongoDBMethodInterceptor
.
MONGODB_PORT
,
27017
);
}
}
skywalking-sniffer/skywalking-sdk-plugin/mongodb-plugin/src/main/resources/skywalking-plugin.def
已删除
100644 → 0
浏览文件 @
085f9b69
com.a.eye.skywalking.plugin.mongodb.define.MongoDBInstrumentation
\ No newline at end of file
skywalking-sniffer/skywalking-sdk-plugin/pom.xml
浏览文件 @
e8084e54
...
...
@@ -17,7 +17,7 @@
<module>
jedis-2.x-plugin
</module>
<module>
tomcat-7.x-8.x-plugin
</module>
<module>
motan-plugin
</module>
<module>
mongodb-plugin
</module>
<module>
mongodb-
3.x-
plugin
</module>
</modules>
<packaging>
pom
</packaging>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录