Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
润土的好友猹
SkyWalking
提交
aa9a7c44
S
SkyWalking
项目概览
润土的好友猹
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
9
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,发现更多精彩内容 >>
提交
aa9a7c44
编写于
12月 07, 2018
作者:
X
Xin,Zhang
提交者:
wu-sheng
12月 07, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the NPE about elasticsearch plugin (#1985)
上级
45f44544
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
354 addition
and
114 deletion
+354
-114
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/AddTransportAddressesInterceptor.java
...in/elasticsearch/v5/AddTransportAddressesInterceptor.java
+49
-0
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/Constants.java
...che/skywalking/apm/plugin/elasticsearch/v5/Constants.java
+0
-2
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/ElasticSearchEnhanceInfo.java
...apm/plugin/elasticsearch/v5/ElasticSearchEnhanceInfo.java
+8
-9
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/GenericActionConstructorInterceptor.java
...elasticsearch/v5/GenericActionConstructorInterceptor.java
+28
-0
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/RemoveTransportAddressInterceptor.java
...n/elasticsearch/v5/RemoveTransportAddressInterceptor.java
+49
-0
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportActionNodeProxyInterceptor.java
...elasticsearch/v5/TransportActionNodeProxyInterceptor.java
+19
-12
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportAddressCache.java
...ng/apm/plugin/elasticsearch/v5/TransportAddressCache.java
+60
-0
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportProxyClientInterceptor.java
...gin/elasticsearch/v5/TransportProxyClientInterceptor.java
+25
-39
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/GenericActionInstrumentation.java
...elasticsearch/v5/define/GenericActionInstrumentation.java
+19
-26
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/TransportActionNodeProxyInstrumentation.java
...ch/v5/define/TransportActionNodeProxyInstrumentation.java
+17
-3
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/TransportClientNodesServiceInstrumentation.java
...v5/define/TransportClientNodesServiceInstrumentation.java
+74
-0
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/TransportProxyClientInstrumentation.java
...search/v5/define/TransportProxyClientInstrumentation.java
+4
-22
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/resources/skywalking-plugin.def
...earch-5.x-plugin/src/main/resources/skywalking-plugin.def
+2
-1
未找到文件。
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/AddTransportAddressesInterceptor.java
0 → 100644
浏览文件 @
aa9a7c44
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.elasticsearch.common.transport.TransportAddress
;
public
class
AddTransportAddressesInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
TransportAddressCache
transportAddressCache
=
(
TransportAddressCache
)
objInst
.
getSkyWalkingDynamicField
();
if
(
transportAddressCache
==
null
)
{
transportAddressCache
=
new
TransportAddressCache
();
}
transportAddressCache
.
addDiscoveryNode
((
TransportAddress
[])
allArguments
[
0
]);
objInst
.
setSkyWalkingDynamicField
(
transportAddressCache
);
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/Constants.java
浏览文件 @
aa9a7c44
...
...
@@ -27,8 +27,6 @@ class Constants {
static
final
String
ELASTICSEARCH_DB_OP_PREFIX
=
"Elasticsearch/"
;
static
final
String
ES_ENHANCE_INFO
=
"es_enhance_info"
;
static
final
String
BASE_FUTURE_METHOD
=
"actionGet"
;
static
final
String
ES_NODE
=
"node.address"
;
...
...
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/ElasticSearchEnhanceInfo.java
浏览文件 @
aa9a7c44
...
...
@@ -18,14 +18,12 @@
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
/**
* @author oatiz.
*/
public
class
ElasticSearchEnhanceInfo
{
/**
* elasticsearch host and port
*/
private
String
transportAddress
;
/**
* elasticsearch cluster name
*/
...
...
@@ -47,12 +45,10 @@ public class ElasticSearchEnhanceInfo {
*/
private
String
source
;
public
String
getTransportAddress
()
{
return
transportAddress
;
}
private
EnhancedInstance
transportAddressHolder
;
public
void
setTransportAddress
(
String
transportAddress
)
{
this
.
transportAddress
=
transportAddress
;
public
String
transportAddresses
(
)
{
return
((
TransportAddressCache
)
transportAddressHolder
.
getSkyWalkingDynamicField
()).
transportAddress
()
;
}
public
String
getClusterName
()
{
...
...
@@ -95,4 +91,7 @@ public class ElasticSearchEnhanceInfo {
this
.
source
=
source
;
}
public
void
setTransportAddressHolder
(
EnhancedInstance
service
)
{
this
.
transportAddressHolder
=
service
;
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/
ActionRequestBuilde
rInterceptor.java
→
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/
GenericActionConstructo
rInterceptor.java
浏览文件 @
aa9a7c44
...
...
@@ -6,60 +6,23 @@
* (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
*
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.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.elasticsearch.client.transport.TransportClient
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
ES_ENHANCE_INFO
;
/**
* @author oatiz.
*/
public
class
ActionRequestBuilderInterceptor
implements
InstanceConstructorInterceptor
{
public
class
GenericActionConstructorInterceptor
implements
InstanceConstructorInterceptor
{
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
ElasticSearchEnhanceInfo
enhanceInfo
=
new
ElasticSearchEnhanceInfo
();
parseClientInfo
(
allArguments
[
0
],
enhanceInfo
);
ContextManager
.
getRuntimeContext
().
put
(
ES_ENHANCE_INFO
,
enhanceInfo
);
}
private
void
parseClientInfo
(
Object
client
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
if
(
client
instanceof
TransportClient
)
{
TransportClient
transportClient
=
(
TransportClient
)
client
;
StringBuilder
builder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
transportClient
.
transportAddresses
().
size
();
i
++)
{
if
(
i
!=
transportClient
.
transportAddresses
().
size
()
-
1
)
{
builder
.
append
(
transportClient
.
transportAddresses
().
get
(
i
).
toString
()).
append
(
","
);
}
else
{
builder
.
append
(
transportClient
.
transportAddresses
().
get
(
i
).
toString
());
}
}
enhanceInfo
.
setTransportAddress
(
builder
.
toString
());
}
else
{
// avoid NPE
enhanceInfo
.
setTransportAddress
(
""
);
}
//DO Nothing, just for pass parameter
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/RemoveTransportAddressInterceptor.java
0 → 100644
浏览文件 @
aa9a7c44
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.elasticsearch.common.transport.TransportAddress
;
public
class
RemoveTransportAddressInterceptor
implements
InstanceMethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
TransportAddressCache
transportAddressCache
=
(
TransportAddressCache
)
objInst
.
getSkyWalkingDynamicField
();
if
(
transportAddressCache
==
null
)
{
transportAddressCache
=
new
TransportAddressCache
();
}
transportAddressCache
.
removeDiscoveryNode
((
TransportAddress
)
allArguments
[
0
]);
objInst
.
setSkyWalkingDynamicField
(
transportAddressCache
);
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportActionNodeProxyInterceptor.java
浏览文件 @
aa9a7c44
...
...
@@ -18,60 +18,67 @@
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
java.lang.reflect.Method
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.tag.Tags
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.elasticsearch.cluster.node.DiscoveryNode
;
import
java.lang.reflect.Method
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
conf
.
Config
.
Plugin
.
Elasticsearch
.
TRACE_DSL
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.*;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
DB_TYPE
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
ELASTICSEARCH_DB_OP_PREFIX
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
ES_INDEX
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
ES_NODE
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
ES_TYPE
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Util
.
wrapperNullStringValue
;
/**
* @author oatiz.
*/
public
class
TransportActionNodeProxyInterceptor
implements
InstanceMethodsAroundInterceptor
{
public
class
TransportActionNodeProxyInterceptor
implements
Instance
ConstructorInterceptor
,
Instance
MethodsAroundInterceptor
{
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ElasticSearchEnhanceInfo
enhanceInfo
=
(
ElasticSearchEnhanceInfo
)
ContextManager
.
getRuntimeContext
().
get
(
ES_ENHANCE_INFO
);
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ElasticSearchEnhanceInfo
enhanceInfo
=
(
ElasticSearchEnhanceInfo
)((
EnhancedInstance
)
objInst
.
getSkyWalkingDynamicField
()).
getSkyWalkingDynamicField
();
String
opType
=
allArguments
[
1
].
getClass
().
getSimpleName
();
String
operationName
=
ELASTICSEARCH_DB_OP_PREFIX
+
opType
;
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
operationName
,
enhanceInfo
.
getTransportAddres
s
());
AbstractSpan
span
=
ContextManager
.
createExitSpan
(
operationName
,
enhanceInfo
.
transportAddresse
s
());
span
.
setComponent
(
ComponentsDefine
.
TRANSPORT_CLIENT
);
Tags
.
DB_TYPE
.
set
(
span
,
DB_TYPE
);
Tags
.
DB_INSTANCE
.
set
(
span
,
enhanceInfo
.
getClusterName
());
if
(
TRACE_DSL
)
{
Tags
.
DB_STATEMENT
.
set
(
span
,
enhanceInfo
.
getSource
());
}
span
.
tag
(
ES_NODE
,
((
DiscoveryNode
)
allArguments
[
0
]).
getAddress
().
toString
());
span
.
tag
(
ES_NODE
,
((
DiscoveryNode
)
allArguments
[
0
]).
getAddress
().
toString
());
span
.
tag
(
ES_INDEX
,
wrapperNullStringValue
(
enhanceInfo
.
getIndices
()));
span
.
tag
(
ES_TYPE
,
wrapperNullStringValue
(
enhanceInfo
.
getTypes
()));
SpanLayer
.
asDB
(
span
);
ContextManager
.
getRuntimeContext
().
remove
(
ES_ENHANCE_INFO
);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
ContextManager
.
stopSpan
();
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
(
t
);
}
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
EnhancedInstance
actions
=
(
EnhancedInstance
)
allArguments
[
1
];
objInst
.
setSkyWalkingDynamicField
(
actions
);
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportAddressCache.java
0 → 100644
浏览文件 @
aa9a7c44
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.elasticsearch.common.transport.TransportAddress
;
public
class
TransportAddressCache
{
private
List
<
TransportAddress
>
transportAddresses
=
new
ArrayList
<
TransportAddress
>();
private
String
transportAddressesStr
;
public
synchronized
void
addDiscoveryNode
(
TransportAddress
...
transportAddress
)
{
transportAddresses
.
addAll
(
Arrays
.
asList
(
transportAddress
));
transportAddressesStr
=
format
();
}
public
synchronized
void
removeDiscoveryNode
(
TransportAddress
transportAddress
)
{
List
<
TransportAddress
>
nodesBuilder
=
new
ArrayList
<
TransportAddress
>();
for
(
TransportAddress
otherNode
:
transportAddresses
)
{
if
(!
otherNode
.
getAddress
().
equals
(
transportAddress
.
getAddress
()))
{
nodesBuilder
.
add
(
otherNode
);
}
}
transportAddresses
=
nodesBuilder
;
transportAddressesStr
=
format
();
}
private
String
format
()
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
TransportAddress
node
:
transportAddresses
)
{
stringBuilder
.
append
(
node
.
getAddress
()).
append
(
":"
).
append
(
node
.
getPort
()).
append
(
";"
);
}
return
stringBuilder
.
toString
();
}
public
String
transportAddress
()
{
return
transportAddressesStr
;
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportProxyClientInterceptor.java
浏览文件 @
aa9a7c44
...
...
@@ -6,26 +6,25 @@
* (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
*
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.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
java.io.IOException
;
import
java.util.List
;
import
org.apache.skywalking.apm.agent.core.logging.api.ILog
;
import
org.apache.skywalking.apm.agent.core.logging.api.LogManager
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.util.StringUtil
;
import
org.elasticsearch.action.GenericAction
;
import
org.elasticsearch.action.delete.DeleteRequest
;
import
org.elasticsearch.action.get.GetRequest
;
import
org.elasticsearch.action.index.IndexRequest
;
...
...
@@ -34,45 +33,32 @@ import org.elasticsearch.action.update.UpdateRequest;
import
org.elasticsearch.common.settings.Settings
;
import
org.elasticsearch.common.xcontent.XContentFactory
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
conf
.
Config
.
Plugin
.
Elasticsearch
.
TRACE_DSL
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Constants
.
ES_ENHANCE_INFO
;
import
static
org
.
apache
.
skywalking
.
apm
.
plugin
.
elasticsearch
.
v5
.
Util
.
wrapperNullStringValue
;
/**
* @author oatiz.
* @author oatiz
, zhang xin
.
*/
public
class
TransportProxyClientInterceptor
implements
InstanceConstructorInterceptor
,
InstanceMethodsAroundInterceptor
{
public
class
TransportProxyClientInterceptor
implements
InstanceConstructorInterceptor
{
private
static
final
ILog
logger
=
LogManager
.
getLogger
(
TransportProxyClientInterceptor
.
class
);
@Override
public
void
onConstruct
(
EnhancedInstance
objInst
,
Object
[]
allArguments
)
{
Settings
settings
=
(
Settings
)
allArguments
[
0
];
Settings
settings
=
(
Settings
)
allArguments
[
0
];
String
clusterName
=
settings
.
get
(
"cluster.name"
);
objInst
.
setSkyWalkingDynamicField
(
wrapperNullStringValue
(
clusterName
));
}
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
ElasticSearchEnhanceInfo
enhanceInfo
=
(
ElasticSearchEnhanceInfo
)
ContextManager
.
getRuntimeContext
().
get
(
ES_ENHANCE_INFO
);
enhanceInfo
.
setClusterName
((
String
)
objInst
.
getSkyWalkingDynamicField
());
parseRequestInfo
(
allArguments
[
1
],
enhanceInfo
);
}
EnhancedInstance
nodeService
=
(
EnhancedInstance
)
allArguments
[
2
];
List
<
GenericAction
>
genericActions
=
(
List
<
GenericAction
>)
allArguments
[
3
];
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
return
ret
;
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
ContextManager
.
activeSpan
().
errorOccurred
().
log
(
t
);
for
(
GenericAction
action
:
genericActions
)
{
if
(
action
instanceof
EnhancedInstance
)
{
ElasticSearchEnhanceInfo
elasticSearchEnhanceInfo
=
new
ElasticSearchEnhanceInfo
();
elasticSearchEnhanceInfo
.
setClusterName
(
clusterName
);
parseRequestInfo
(
action
,
elasticSearchEnhanceInfo
);
elasticSearchEnhanceInfo
.
setTransportAddressHolder
(
nodeService
);
((
EnhancedInstance
)
action
).
setSkyWalkingDynamicField
(
elasticSearchEnhanceInfo
);
}
}
}
private
void
parseRequestInfo
(
Object
request
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
...
...
@@ -103,7 +89,7 @@ public class TransportProxyClientInterceptor implements InstanceConstructorInter
}
private
void
parseSearchRequest
(
Object
request
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
SearchRequest
searchRequest
=
(
SearchRequest
)
request
;
SearchRequest
searchRequest
=
(
SearchRequest
)
request
;
enhanceInfo
.
setIndices
(
StringUtil
.
join
(
','
,
searchRequest
.
indices
()));
enhanceInfo
.
setTypes
(
StringUtil
.
join
(
','
,
searchRequest
.
types
()));
if
(
TRACE_DSL
)
{
...
...
@@ -112,7 +98,7 @@ public class TransportProxyClientInterceptor implements InstanceConstructorInter
}
private
void
parseGetRequest
(
Object
request
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
GetRequest
getRequest
=
(
GetRequest
)
request
;
GetRequest
getRequest
=
(
GetRequest
)
request
;
enhanceInfo
.
setIndices
(
StringUtil
.
join
(
','
,
getRequest
.
indices
()));
enhanceInfo
.
setTypes
(
getRequest
.
type
());
if
(
TRACE_DSL
)
{
...
...
@@ -121,7 +107,7 @@ public class TransportProxyClientInterceptor implements InstanceConstructorInter
}
private
void
parseIndexRequest
(
Object
request
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
IndexRequest
indexRequest
=
(
IndexRequest
)
request
;
IndexRequest
indexRequest
=
(
IndexRequest
)
request
;
enhanceInfo
.
setIndices
(
StringUtil
.
join
(
','
,
indexRequest
.
indices
()));
enhanceInfo
.
setTypes
(
indexRequest
.
type
());
if
(
TRACE_DSL
)
{
...
...
@@ -130,7 +116,7 @@ public class TransportProxyClientInterceptor implements InstanceConstructorInter
}
private
void
parseUpdateRequest
(
Object
request
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
UpdateRequest
updateRequest
=
(
UpdateRequest
)
request
;
UpdateRequest
updateRequest
=
(
UpdateRequest
)
request
;
enhanceInfo
.
setIndices
(
StringUtil
.
join
(
','
,
updateRequest
.
indices
()));
enhanceInfo
.
setTypes
(
updateRequest
.
type
());
if
(
TRACE_DSL
)
{
...
...
@@ -145,7 +131,7 @@ public class TransportProxyClientInterceptor implements InstanceConstructorInter
}
private
void
parseDeleteRequest
(
Object
request
,
ElasticSearchEnhanceInfo
enhanceInfo
)
{
DeleteRequest
deleteRequest
=
(
DeleteRequest
)
request
;
DeleteRequest
deleteRequest
=
(
DeleteRequest
)
request
;
enhanceInfo
.
setIndices
(
StringUtil
.
join
(
','
,
deleteRequest
.
indices
()));
enhanceInfo
.
setTypes
(
deleteRequest
.
type
());
if
(
TRACE_DSL
)
{
...
...
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/
ActionRequestBuilder
Instrumentation.java
→
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/
GenericAction
Instrumentation.java
浏览文件 @
aa9a7c44
...
...
@@ -6,14 +6,13 @@
* (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
*
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.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5.define
;
...
...
@@ -22,43 +21,37 @@ import net.bytebuddy.description.method.MethodDescription;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* @author oatiz.
*/
public
class
ActionRequestBuilderInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
HierarchyMatch
.
byHierarchyMatch
;
private
static
final
String
ENHANCE_CLASS
=
"org.apache.skywalking.apm.plugin.elasticsearch.v5.ActionRequestBuilderInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]{
public
class
GenericActionInstrumentation
extends
ClassEnhancePluginDefine
{
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
ENHANCE_CLASS
;
@Override
public
String
getConstructorInterceptor
()
{
return
"org.apache.skywalking.apm.plugin.elasticsearch.v5.GenericActionConstructorInterceptor"
;
}
}
};
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[
0
];
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
"org.elasticsearch.action.ActionRequestBuilder"
);
@Override
protected
StaticMethodsInterceptPoint
[]
getStaticMethodsInterceptPoints
()
{
return
new
StaticMethodsInterceptPoint
[
0
];
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byHierarchyMatch
(
new
String
[]
{
"org.elasticsearch.action.GenericAction"
});
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/TransportActionNodeProxyInstrumentation.java
浏览文件 @
aa9a7c44
...
...
@@ -26,6 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInte
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
...
...
@@ -34,9 +35,22 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName
*/
public
class
TransportActionNodeProxyInstrumentation
extends
ClassEnhancePluginDefine
{
public
static
final
String
INTERCEPTOR_CLASS
=
"org.apache.skywalking.apm.plugin.elasticsearch.v5.TransportActionNodeProxyInterceptor"
;
public
static
final
String
ENHANC_CLASS
=
"org.elasticsearch.action.TransportActionNodeProxy"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
return
new
ConstructorInterceptPoint
[]{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
return
any
();
}
@Override
public
String
getConstructorInterceptor
()
{
return
INTERCEPTOR_CLASS
;
}
}
};
}
@Override
...
...
@@ -50,7 +64,7 @@ public class TransportActionNodeProxyInstrumentation extends ClassEnhancePluginD
@Override
public
String
getMethodsInterceptor
()
{
return
"org.apache.skywalking.apm.plugin.elasticsearch.v5.TransportActionNodeProxyInterceptor"
;
return
INTERCEPTOR_CLASS
;
}
@Override
...
...
@@ -68,6 +82,6 @@ public class TransportActionNodeProxyInstrumentation extends ClassEnhancePluginD
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
"org.elasticsearch.action.TransportActionNodeProxy"
);
return
byName
(
ENHANC_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/TransportClientNodesServiceInstrumentation.java
0 → 100644
浏览文件 @
aa9a7c44
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.skywalking.apm.plugin.elasticsearch.v5.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
public
class
TransportClientNodesServiceInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
public
static
final
String
ADD_TRANSPORT_ADDRESSES_INTERCEPTOR
=
"org.apache.skywalking.apm.plugin.elasticsearch.v5.AddTransportAddressesInterceptor"
;
public
static
final
String
REMOVE_TRANSPORT_ADDRESS_INTERCEPTOR
=
"org.apache.skywalking.apm.plugin.elasticsearch.v5.RemoveTransportAddressInterceptor"
;
public
static
final
String
ENHANCE_CLASS
=
"org.elasticsearch.client.transport.TransportClientNodesService"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
}
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"addTransportAddresses"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
ADD_TRANSPORT_ADDRESSES_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
},
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"removeTransportAddress"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
REMOVE_TRANSPORT_ADDRESS_INTERCEPTOR
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
protected
ClassMatch
enhanceClass
()
{
return
byName
(
ENHANCE_CLASS
);
}
}
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/define/TransportProxyClientInstrumentation.java
浏览文件 @
aa9a7c44
...
...
@@ -23,23 +23,22 @@ import net.bytebuddy.matcher.ElementMatcher;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.Class
InstanceMethods
EnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
any
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* @author oatiz.
*/
public
class
TransportProxyClientInstrumentation
extends
ClassEnhancePluginDefine
{
public
class
TransportProxyClientInstrumentation
extends
Class
InstanceMethods
EnhancePluginDefine
{
private
static
final
String
ENHANCE_CLASS
=
"org.apache.skywalking.apm.plugin.elasticsearch.v5.TransportProxyClientInterceptor"
;
@Override
protected
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[]{
return
new
ConstructorInterceptPoint
[]
{
new
ConstructorInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getConstructorMatcher
()
{
...
...
@@ -56,24 +55,7 @@ public class TransportProxyClientInstrumentation extends ClassEnhancePluginDefin
@Override
protected
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"execute"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
ENHANCE_CLASS
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
return
new
InstanceMethodsInterceptPoint
[
0
];
}
@Override
...
...
apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
aa9a7c44
...
...
@@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
elasticsearch-5.x=org.apache.skywalking.apm.plugin.elasticsearch.v5.define.ActionRequestBuilderInstrumentation
elasticsearch-5.x=org.apache.skywalking.apm.plugin.elasticsearch.v5.define.TransportProxyClientInstrumentation
elasticsearch-5.x=org.apache.skywalking.apm.plugin.elasticsearch.v5.define.TransportActionNodeProxyInstrumentation
elasticsearch-5.x=org.apache.skywalking.apm.plugin.elasticsearch.v5.define.PlainListenableActionFutureInstrumentation
elasticsearch-5.x=org.apache.skywalking.apm.plugin.elasticsearch.v5.define.GenericActionInstrumentation
elasticsearch-5.x=org.apache.skywalking.apm.plugin.elasticsearch.v5.define.TransportClientNodesServiceInstrumentation
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录