Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gdyjdao
SkyWalking
提交
ee44d7a6
S
SkyWalking
项目概览
gdyjdao
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / 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,发现更多精彩内容 >>
未验证
提交
ee44d7a6
编写于
11月 20, 2017
作者:
wu-sheng
提交者:
GitHub
11月 20, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into feature/support-mysql-5.x-plugin
上级
e9c300bb
8fe052db
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
882 addition
and
1 deletion
+882
-1
apm-collector/apm-collector-boot/bin/collectorService.bat
apm-collector/apm-collector-boot/bin/collectorService.bat
+21
-0
apm-collector/apm-collector-boot/bin/collectorService.sh
apm-collector/apm-collector-boot/bin/collectorService.sh
+34
-0
apm-collector/apm-collector-boot/bin/startup.bat
apm-collector/apm-collector-boot/bin/startup.bat
+5
-0
apm-collector/apm-collector-boot/bin/startup.sh
apm-collector/apm-collector-boot/bin/startup.sh
+7
-0
apm-collector/apm-collector-boot/pom.xml
apm-collector/apm-collector-boot/pom.xml
+52
-1
apm-collector/apm-collector-boot/src/main/assembly/assembly.xml
...llector/apm-collector-boot/src/main/assembly/assembly.xml
+67
-0
apm-collector/apm-collector-boot/src/main/assembly/log4j2.xml
...collector/apm-collector-boot/src/main/assembly/log4j2.xml
+44
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/pom.xml
+71
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java
...plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java
+102
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java
...ywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java
+38
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java
...ngodb/v2/define/MongoDBCollectionImplInstrumentation.java
+140
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java
...n/mongodb/v2/define/MongoDBCollectionInstrumentation.java
+173
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/resources/skywalking-plugin.def
...ngodb-2.x-plugin/src/main/resources/skywalking-plugin.def
+2
-0
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java
...in/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java
+125
-0
apm-sniffer/apm-sdk-plugin/pom.xml
apm-sniffer/apm-sdk-plugin/pom.xml
+1
-0
未找到文件。
apm-collector/apm-collector-boot/bin/collectorService.bat
0 → 100644
浏览文件 @
ee44d7a6
@echo
off
setlocal
set
COLLECTOR_PROCESS_TITLE
=
Skywalking
-Collector
set
COLLECTOR_HOME
=
%~dp0
%
..
set
COLLECTOR_OPTS
=
"-Xms256M -Xmx512M -Dcollector.logDir=
%COLLECTOR_HOME%
\logs"
set
CLASSPATH
=
%COLLECTOR_HOME%
\config
;
.
;
set
CLASSPATH
=
%COLLECTOR_HOME%
\libs\
*;
%CLASSPATH%
if
defined
JAVA_HOME
(
set
_EXECJAVA
=
"
%JAVA
_HOME:"
=
%
"\bin\java
)
if not defined JAVA_HOME (
echo "
JAVA_HOME
not
set
.
"
set _EXECJAVA=java
)
start "
%COLLECTOR_PROCESS_TITLE%
"
%_EXECJAVA%
"
%COLLECTOR_OPTS%
" -cp "
%CLASSPATH%
" org.skywalking.apm.collector.boot.CollectorBootStartUp
endlocal
apm-collector/apm-collector-boot/bin/collectorService.sh
0 → 100644
浏览文件 @
ee44d7a6
#!/usr/bin/env sh
PRG
=
"
$0
"
PRGDIR
=
`
dirname
"
$PRG
"
`
[
-z
"
$COLLECTOR_HOME
"
]
&&
COLLECTOR_HOME
=
`
cd
"
$PRGDIR
/.."
>
/dev/null
;
pwd
`
COLLECT_LOG_DIR
=
"
${
COLLECTOR_HOME
}
/logs"
JAVA_OPTS
=
" -Xms256M -Xmx512M"
if
[
!
-d
"
${
COLLECTOR_HOME
}
/logs"
]
;
then
mkdir
-p
"
${
COLLECT_LOG_DIR
}
"
fi
_RUNJAVA
=
${
JAVA_HOME
}
/bin/java
[
-z
"
$JAVA_HOME
"
]
&&
_RUNJAVA
=
java
CLASSPATH
=
"
$COLLECTOR_HOME
/config:
$CLASSPATH
"
for
i
in
"
$COLLECTOR_HOME
"
/libs/
*
.jar
do
CLASSPATH
=
"
$i
:
$CLASSPATH
"
done
WEBUI_OPTIONS
=
" -Dcollector.logDir=
${
COLLECT_LOG_DIR
}
"
eval exec
"
\"
$_RUNJAVA
\"
${
JAVA_OPTS
}
${
WEBUI_OPTIONS
}
-classpath
$CLASSPATH
org.skywalking.apm.collector.boot.CollectorBootStartUp
\
2>
${
COLLECT_LOG_DIR
}
/collector.log 1> /dev/null &"
if
[
$?
-eq
0
]
;
then
sleep
1
echo
"Skywalking Web started successfully!"
else
echo
"Skywalking Web started failure!"
exit
1
fi
apm-collector/apm-collector-boot/bin/startup.bat
0 → 100644
浏览文件 @
ee44d7a6
@echo
off
setlocal
call
"
%~dp0
"
\collectorService.bat
start
endlocal
apm-collector/apm-collector-boot/bin/startup.sh
0 → 100644
浏览文件 @
ee44d7a6
#!/usr/bin/env sh
PRG
=
"
$0
"
PRGDIR
=
`
dirname
"
$PRG
"
`
EXECUTABLE
=
collectorService.sh
exec
"
$PRGDIR
"
/
"
$EXECUTABLE
"
start
apm-collector/apm-collector-boot/pom.xml
浏览文件 @
ee44d7a6
...
@@ -146,4 +146,55 @@
...
@@ -146,4 +146,55 @@
</dependency>
</dependency>
<!-- cache provider -->
<!-- cache provider -->
</dependencies>
</dependencies>
</project>
\ No newline at end of file
<build>
<finalName>
Skywalking-Collector
</finalName>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
${compiler.version}
</source>
<target>
${compiler.version}
</target>
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<version>
2.4.3
</version>
<configuration>
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
<version>
2.3.2
</version>
<configuration>
<excludes>
<exclude>
application.yml
</exclude>
<exclude>
log4j2.xml
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
<executions>
<execution>
<id>
assembly
</id>
<phase>
package
</phase>
<goals>
<goal>
single
</goal>
</goals>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/assembly.xml
</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
apm-collector/apm-collector-boot/src/main/assembly/assembly.xml
0 → 100644
浏览文件 @
ee44d7a6
<!--
~ 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
-->
<assembly
xmlns=
"http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"
>
<id></id>
<formats>
<format>
zip
</format>
<format>
tar.gz
</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>
/libs
</outputDirectory>
<scope>
runtime
</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>
${project.basedir}/bin
</directory>
<outputDirectory>
/bin
</outputDirectory>
<includes>
<include>
*.sh
</include>
<include>
*.bat
</include>
</includes>
<fileMode>
0755
</fileMode>
</fileSet>
<fileSet>
<directory>
src/main/resources
</directory>
<outputDirectory>
/config
</outputDirectory>
<includes>
<include>
application.yml
</include>
</includes>
</fileSet>
<fileSet>
<directory>
src/main/assembly
</directory>
<outputDirectory>
/config
</outputDirectory>
<includes>
<include>
log4j2.xml
</include>
</includes>
</fileSet>
<fileSet>
<directory>
src/main/resources
</directory>
<includes>
<include>
application.yml
</include>
<include>
log4j2.xml
</include>
</includes>
<outputDirectory>
/config
</outputDirectory>
</fileSet>
</fileSets>
</assembly>
apm-collector/apm-collector-boot/src/main/assembly/log4j2.xml
0 → 100644
浏览文件 @
ee44d7a6
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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
-->
<Configuration
status=
"error"
>
<Properties>
<Property
name=
"log-path"
>
${sys:collector.logDir}
</Property>
</Properties>
<Appenders>
<RollingFile
name=
"RollingFile"
fileName=
"${log-path}/skywalking-web-server.log"
filePattern=
"${log-path}/skywalking-web-server-%d{yyyy-MM-dd}-%i.log"
>
<PatternLayout>
<pattern>
%d - %c -%-4r [%t] %-5p %x - %m%n
</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy
size=
"102400KB"
/>
</Policies>
<DefaultRolloverStrategy
max=
"30"
/>
</RollingFile>
</Appenders>
<Loggers>
<logger
name=
"org.skywalking.apm.ui"
level=
"debug"
>
<AppenderRef
ref=
"RollingFile"
/>
</logger>
<Root
level=
"info"
>
<AppenderRef
ref=
"RollingFile"
/>
</Root>
</Loggers>
</Configuration>
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/pom.xml
0 → 100644
浏览文件 @
ee44d7a6
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ /*
~ * 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
~ */
-->
<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"
>
<parent>
<artifactId>
apm-sdk-plugin
</artifactId>
<groupId>
org.skywalking
</groupId>
<version>
3.2.5-2017
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apm-mongodb-2.x-plugin
</artifactId>
<packaging>
jar
</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
mongo-java-driver
</artifactId>
<version>
2.14.2
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.mongodb
</groupId>
<artifactId>
bson
</artifactId>
<version>
2.14.2
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- 源码插件 -->
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>
attach-sources
</id>
<goals>
<goal>
jar
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptor.java
0 → 100644
浏览文件 @
ee44d7a6
/*
* 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
;
import
com.mongodb.AggregationOutput
;
import
com.mongodb.CommandResult
;
import
com.mongodb.DB
;
import
com.mongodb.ServerAddress
;
import
com.mongodb.WriteResult
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
org.skywalking.apm.agent.core.context.ContextCarrier
;
import
org.skywalking.apm.agent.core.context.ContextManager
;
import
org.skywalking.apm.agent.core.context.tag.Tags
;
import
org.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.skywalking.apm.network.trace.component.ComponentsDefine
;
/**
* {@link MongoDBCollectionMethodInterceptor} intercepts constructor of {@link com.mongodb.DBCollection}or {@link
* com.mongodb.DBCollectionImpl} recording the ServerAddress and creating the exit span.
*
* @author liyuntao
*/
public
class
MongoDBCollectionMethodInterceptor
implements
InstanceMethodsAroundInterceptor
,
InstanceConstructorInterceptor
{
private
static
final
String
DB_TYPE
=
"MongoDB"
;
private
static
final
String
MONGO_DB_OP_PREFIX
=
"MongoDB/"
;
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
String
remotePeer
=
(
String
)
objInst
.
getSkyWalkingDynamicField
();
String
opertaion
=
method
.
getName
();
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
MONGO_DB_OP_PREFIX
+
opertaion
,
new
ContextCarrier
(),
remotePeer
);
span
.
setComponent
(
ComponentsDefine
.
MONGODB
);
Tags
.
DB_TYPE
.
set
(
span
,
DB_TYPE
);
SpanLayer
.
asDB
(
span
);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
AbstractSpan
activeSpan
=
ContextManager
.
activeSpan
();
CommandResult
cresult
=
null
;
if
(
ret
instanceof
WriteResult
)
{
WriteResult
wresult
=
(
WriteResult
)
ret
;
cresult
=
wresult
.
getCachedLastError
();
}
else
if
(
ret
instanceof
AggregationOutput
)
{
AggregationOutput
aresult
=
(
AggregationOutput
)
ret
;
cresult
=
aresult
.
getCommandResult
();
}
if
(
null
!=
cresult
&&
!
cresult
.
ok
())
{
activeSpan
.
log
(
cresult
.
getException
());
}
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
AbstractSpan
activeSpan
=
ContextManager
.
activeSpan
();
activeSpan
.
errorOccurred
();
activeSpan
.
log
(
t
);
}
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
List
<
ServerAddress
>
servers
=
null
;
DB
db
=
(
DB
)
allArguments
[
0
];
servers
=
db
.
getMongo
().
getAllAddress
();
StringBuilder
peers
=
new
StringBuilder
();
for
(
ServerAddress
address
:
servers
)
{
peers
.
append
(
address
.
getHost
()
+
":"
+
address
.
getPort
()
+
";"
);
}
objInst
.
setSkyWalkingDynamicField
(
peers
.
subSequence
(
0
,
peers
.
length
()
-
1
).
toString
());
}
}
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/InterceptPoint.java
0 → 100644
浏览文件 @
ee44d7a6
/*
* 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
org.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
/**
* @auther liyuntao
*/
public
abstract
class
InterceptPoint
implements
InstanceMethodsInterceptPoint
{
private
static
final
String
MONGDB_METHOD_INTERCET_CLASS
=
"org.skywalking.apm.plugin.mongodb.v2.MongoDBCollectionMethodInterceptor"
;
@Override
public
String
getMethodsInterceptor
()
{
return
MONGDB_METHOD_INTERCET_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionImplInstrumentation.java
0 → 100644
浏览文件 @
ee44d7a6
/*
* 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
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
takesArguments
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* {@link MongoDBCollectionImplInstrumentation} define that the MongoDB Java Driver 2.13.x-2.14.x plugin intercepts the
* following methods in the {@link com.mongodb.DBCollectionImpl}class:
* 1. find <br/>
* 2. insert <br/>
* 3. insertImpl <br/>
* 4. update <br/>
* 5. updateImpl <br/>
* 6. remove <br/>
* 7. createIndex <br/>
*
* @author liyuntao
*/
public
class
MongoDBCollectionImplInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"com.mongodb.DBCollectionImpl"
;
private
static
final
String
MONGDB_METHOD_INTERCET_CLASS
=
"org.skywalking.apm.plugin.mongodb.v2.MongoDBCollectionMethodInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
MONGDB_METHOD_INTERCET_CLASS
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"find"
).
and
(
takesArguments
(
9
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"insert"
).
and
(
takesArguments
(
4
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"insertImpl"
);
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"update"
);
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"updateImpl"
);
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"remove"
).
and
(
takesArguments
(
4
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"createIndex"
);
}
},
};
}
@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"
};
}
}
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/java/org/skywalking/apm/plugin/mongodb/v2/define/MongoDBCollectionInstrumentation.java
0 → 100644
浏览文件 @
ee44d7a6
/*
* 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
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
takesArguments
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
bytebuddy
.
ArgumentTypeNameMatch
.
takesArgumentWithType
;
import
static
org
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* {@link MongoDBCollectionInstrumentation} define that the MongoDB Java Driver 2.13.x-2.14.x plugin intercepts the
* following methods in the {@link com.mongodb.DBCollection}class:
* 1. aggregate <br/>
* 2. findAndModify <br/>
* 3. getCount
* <br/>
* 4. drop <br/>
* 5. dropIndexes <br/>
* 6. rename <br/>
* 7. group <br/>
* 8. distinct <br/>
* 9. mapReduce <br/>
*
* @author 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.MongoDBCollectionMethodInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
MONGDB_METHOD_INTERCET_CLASS
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]
{
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"aggregate"
).
and
(
takesArgumentWithType
(
1
,
"com.mongodb.ReadPreference"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"findAndModify"
).
and
(
takesArguments
(
9
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"getCount"
).
and
(
takesArgumentWithType
(
6
,
"java.util.concurrent.TimeUnit"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"drop"
);
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"dropIndexes"
);
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"rename"
).
and
(
takesArgumentWithType
(
1
,
"boolean"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"group"
).
and
(
takesArgumentWithType
(
1
,
"boolean"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"group"
).
and
(
takesArgumentWithType
(
1
,
"com.mongodb.DBObject"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"distinct"
).
and
(
takesArgumentWithType
(
2
,
"com.mongodb.ReadPreference"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"mapReduce"
).
and
(
takesArgumentWithType
(
0
,
"com.mongodb.MapReduceCommand"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"mapReduce"
).
and
(
takesArgumentWithType
(
0
,
"com.mongodb.DBObject"
));
}
},
new
InterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"explainAggregate"
);
}
},
};
}
@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"
};
}
}
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/main/resources/skywalking-plugin.def
0 → 100644
浏览文件 @
ee44d7a6
mongodb-2.x=org.skywalking.apm.plugin.mongodb.v2.define.MongoDBCollectionInstrumentation
mongodb-2.x=org.skywalking.apm.plugin.mongodb.v2.define.MongoDBCollectionImplInstrumentation
apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java
0 → 100644
浏览文件 @
ee44d7a6
/*
* 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
;
import
com.mongodb.DBCollection
;
import
com.mongodb.DBObject
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
org.hamcrest.MatcherAssert
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.powermock.modules.junit4.PowerMockRunnerDelegate
;
import
org.skywalking.apm.agent.core.conf.Config
;
import
org.skywalking.apm.agent.core.context.trace.AbstractTracingSpan
;
import
org.skywalking.apm.agent.core.context.trace.LogDataEntity
;
import
org.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.skywalking.apm.agent.core.context.trace.TraceSegment
;
import
org.skywalking.apm.agent.core.context.util.KeyValuePair
;
import
org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.skywalking.apm.agent.test.helper.SegmentHelper
;
import
org.skywalking.apm.agent.test.helper.SpanHelper
;
import
org.skywalking.apm.agent.test.tools.AgentServiceRule
;
import
org.skywalking.apm.agent.test.tools.SegmentStorage
;
import
org.skywalking.apm.agent.test.tools.SegmentStoragePoint
;
import
org.skywalking.apm.agent.test.tools.TracingSegmentRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
skywalking
.
apm
.
agent
.
test
.
tools
.
SpanAssert
.
assertException
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockRunnerDelegate
(
TracingSegmentRunner
.
class
)
public
class
MongoDBCollectionMethodInterceptorTest
{
@SegmentStoragePoint
private
SegmentStorage
segmentStorage
;
@Rule
public
AgentServiceRule
serviceRule
=
new
AgentServiceRule
();
private
MongoDBCollectionMethodInterceptor
interceptor
;
@Mock
private
EnhancedInstance
enhancedInstance
;
private
Object
[]
arguments
=
new
Object
[
3
];
private
Class
[]
argumentTypes
;
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
@Before
public
void
setUp
()
throws
Exception
{
interceptor
=
new
MongoDBCollectionMethodInterceptor
();
Config
.
Plugin
.
MongoDB
.
TRACE_PARAM
=
true
;
when
(
enhancedInstance
.
getSkyWalkingDynamicField
()).
thenReturn
(
"127.0.0.1:27017"
);
}
@Test
public
void
testIntercept
()
throws
Throwable
{
interceptor
.
beforeMethod
(
enhancedInstance
,
getExecuteMethod
(),
null
,
null
,
null
);
interceptor
.
afterMethod
(
enhancedInstance
,
getExecuteMethod
(),
null
,
null
,
null
);
MatcherAssert
.
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertMongoSpan
(
spans
.
get
(
0
));
}
@Test
public
void
testInterceptWithException
()
throws
Throwable
{
interceptor
.
beforeMethod
(
enhancedInstance
,
getExecuteMethod
(),
null
,
null
,
null
);
interceptor
.
handleMethodException
(
enhancedInstance
,
getExecuteMethod
(),
null
,
null
,
new
RuntimeException
());
interceptor
.
afterMethod
(
enhancedInstance
,
getExecuteMethod
(),
null
,
null
,
null
);
MatcherAssert
.
assertThat
(
segmentStorage
.
getTraceSegments
().
size
(),
is
(
1
));
TraceSegment
traceSegment
=
segmentStorage
.
getTraceSegments
().
get
(
0
);
List
<
AbstractTracingSpan
>
spans
=
SegmentHelper
.
getSpans
(
traceSegment
);
assertMongoSpan
(
spans
.
get
(
0
));
List
<
LogDataEntity
>
logDataEntities
=
SpanHelper
.
getLogs
(
spans
.
get
(
0
));
assertThat
(
logDataEntities
.
size
(),
is
(
1
));
assertException
(
logDataEntities
.
get
(
0
),
RuntimeException
.
class
);
}
private
void
assertMongoSpan
(
AbstractTracingSpan
span
)
{
assertThat
(
span
.
getOperationName
(),
is
(
"MongoDB/insert"
));
assertThat
(
SpanHelper
.
getComponentId
(
span
),
is
(
9
));
List
<
KeyValuePair
>
tags
=
SpanHelper
.
getTags
(
span
);
assertThat
(
tags
.
get
(
0
).
getValue
(),
is
(
"MongoDB"
));
assertThat
(
span
.
isExit
(),
is
(
true
));
assertThat
(
SpanHelper
.
getLayer
(
span
),
is
(
SpanLayer
.
DB
));
}
private
Method
getExecuteMethod
()
{
try
{
return
DBCollection
.
class
.
getMethod
(
"insert"
,
DBObject
[].
class
);
}
catch
(
NoSuchMethodException
e
)
{
return
null
;
}
}
}
apm-sniffer/apm-sdk-plugin/pom.xml
浏览文件 @
ee44d7a6
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
<module>
h2-1.x-plugin
</module>
<module>
h2-1.x-plugin
</module>
<module>
postgresql-8.x-plugin
</module>
<module>
postgresql-8.x-plugin
</module>
<module>
oracle-10.x-plugin
</module>
<module>
oracle-10.x-plugin
</module>
<module>
mongodb-2.x-plugin
</module>
</modules>
</modules>
<packaging>
pom
</packaging>
<packaging>
pom
</packaging>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录