Fix the NPE about elasticsearch plugin (#1985)
This commit is contained in:
parent
45f44544eb
commit
aa9a7c4437
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* 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 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 {
|
||||
|
||||
@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("");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
|
||||
public class GenericActionConstructorInterceptor implements InstanceConstructorInterceptor {
|
||||
@Override
|
||||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
||||
//DO Nothing, just for pass parameter
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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 InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor {
|
||||
|
||||
@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.getTransportAddress());
|
||||
AbstractSpan span = ContextManager.createExitSpan(operationName, enhanceInfo.transportAddresses());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
|
||||
|
||||
/**
|
||||
* @author oatiz.
|
||||
*/
|
||||
public class ActionRequestBuilderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
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"});
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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.ClassInstanceMethodsEnhancePluginDefine;
|
||||
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 ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue