diff --git a/CHANGES.md b/CHANGES.md index d1f433d3d..8cb79d44f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Release Notes. ------------------ * Fix hbase onConstruct NPE in the file configuration scenario +* Optimize ElasticSearch 6.x 7.x plugin compatibility #### Documentation diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/pom.xml index 6fa29f8ef..c9b091cbe 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/pom.xml @@ -36,6 +36,12 @@ + + org.apache.skywalking + elasticsearch-common + ${project.version} + provided + org.elasticsearch.client elasticsearch-rest-high-level-client diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/IndicesClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/IndicesClientInstrumentation.java index fa011776f..0031efb96 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/IndicesClientInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/IndicesClientInstrumentation.java @@ -19,6 +19,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.define; import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; import net.bytebuddy.description.method.MethodDescription; @@ -56,7 +57,8 @@ public class IndicesClientInstrumentation extends ClassEnhancePluginDefine { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("create").or(named("createAsync")); + return named("create").or(named("createAsync")) + .and(takesArgument(0, named(Constants.CREATE_INDEX_REQUEST_WITNESS_CLASS))); } @Override @@ -72,7 +74,8 @@ public class IndicesClientInstrumentation extends ClassEnhancePluginDefine { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("delete").or(named("deleteAsync")); + return named("delete").or(named("deleteAsync")) + .and(takesArgument(0, named(Constants.DELETE_INDEX_REQUEST_WITNESS_CLASS))); } @Override @@ -88,7 +91,8 @@ public class IndicesClientInstrumentation extends ClassEnhancePluginDefine { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("analyze").or(named("analyzeAsync")); + return named("analyze").or(named("analyzeAsync")) + .and(takesArgument(0, named(Constants.ANALYZE_REQUEST_WITNESS_CLASS))); } @Override @@ -100,7 +104,24 @@ public class IndicesClientInstrumentation extends ClassEnhancePluginDefine { public boolean isOverrideArgs() { return false; } - } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("refresh").or(named("refreshAsync")) + .and(takesArgument(0, named(Constants.REFRESH_REQUEST_WITNESS_CLASS))); + } + + @Override + public String getMethodsInterceptor() { + return Constants.INDICES_CLIENT_REFRESH_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } }; } @@ -108,4 +129,14 @@ public class IndicesClientInstrumentation extends ClassEnhancePluginDefine { public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { return new StaticMethodsInterceptPoint[0]; } + + @Override + protected String[] witnessClasses() { + return new String[] { + Constants.ANALYZE_REQUEST_WITNESS_CLASS, + Constants.CREATE_INDEX_REQUEST_WITNESS_CLASS, + Constants.DELETE_INDEX_REQUEST_WITNESS_CLASS, + Constants.REFRESH_REQUEST_WITNESS_CLASS + }; + } } diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/RestHighLevelClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/RestHighLevelClientInstrumentation.java index 772844903..818592618 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/RestHighLevelClientInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/RestHighLevelClientInstrumentation.java @@ -28,8 +28,7 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants; import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** @@ -60,7 +59,7 @@ public class RestHighLevelClientInstrumentation extends ClassEnhancePluginDefine new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return takesArguments(1); + return takesArgument(0, named("org.elasticsearch.client.RestClient")); } @Override @@ -74,22 +73,6 @@ public class RestHighLevelClientInstrumentation extends ClassEnhancePluginDefine @Override public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { return new InstanceMethodsInterceptPoint[] { - new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("performRequestAndParseEntity").and(takesArgumentWithType(0, "org.elasticsearch.client.indices.CreateIndexRequest")); - } - - @Override - public String getMethodsInterceptor() { - return Constants.INDICES_CLIENT_CREATE_METHODS_INTERCEPTOR; - } - - @Override - public boolean isOverrideArgs() { - return false; - } - }, new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/TransportActionNodeProxyInstrumentation.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/TransportActionNodeProxyInstrumentation.java index 0caf481de..99c0a9584 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/TransportActionNodeProxyInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/TransportActionNodeProxyInstrumentation.java @@ -20,6 +20,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; +import net.bytebuddy.matcher.ElementMatchers; 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; @@ -27,25 +28,38 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnha import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants; -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; public class TransportActionNodeProxyInstrumentation extends ClassEnhancePluginDefine { public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.TransportActionNodeProxyExecuteMethodsInterceptor"; + public static final String THREE_ARGS_CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.TransportActionNodeProxyThreeArgsConstructorInterceptor"; + public static final String TWO_ARGS_CONSTRUCTOR2_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.TransportActionNodeProxyTwoArgsConstructorInterceptor"; public static final String ENHANC_CLASS = "org.elasticsearch.action.TransportActionNodeProxy"; + public static final String CONSTRUCTOR_ARG_CLASS = "org.elasticsearch.transport.TransportService"; @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[]{ new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return any(); + return ElementMatchers.takesArgument(2, named(CONSTRUCTOR_ARG_CLASS)); } @Override public String getConstructorInterceptor() { - return INTERCEPTOR_CLASS; + return THREE_ARGS_CONSTRUCTOR_INTERCEPTOR_CLASS; + } + }, + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return ElementMatchers.takesArgument(1, named(CONSTRUCTOR_ARG_CLASS)); + } + + @Override + public String getConstructorInterceptor() { + return TWO_ARGS_CONSTRUCTOR2_INTERCEPTOR_CLASS; } } }; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptor.java index b4ad1fa82..427a2bdf6 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptor.java index 4842ce446..25a011da9 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java index d5813aa86..8f81bda64 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.common.settings.Settings; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/Constants.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/Constants.java index 0819a5326..bf9322ed7 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/Constants.java @@ -27,6 +27,7 @@ public class Constants { public static final String INDICES_CLIENT_CREATE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientCreateMethodsInterceptor"; public static final String INDICES_CLIENT_DELETE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientDeleteMethodsInterceptor"; public static final String INDICES_CLIENT_ANALYZE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientAnalyzeMethodsInterceptor"; + public static final String INDICES_CLIENT_REFRESH_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientRefreshMethodsInterceptor"; public static final String REST_HIGH_LEVEL_CLIENT_SEARCH_SCROLL_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.RestHighLevelClientSearchScrollMethodsInterceptor"; public static final String REST_HIGH_LEVEL_CLIENT_SEARCH_TEMPLATE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.RestHighLevelClientSearchTemplateMethodsInterceptor"; public static final String REST_HIGH_LEVEL_CLIENT_CLEAR_SCROLL_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.RestHighLevelClientClearScrollMethodsInterceptor"; @@ -45,11 +46,16 @@ public class Constants { public static final String TASK_TRANSPORT_CHANNEL_WITNESS_CLASSES = "org.elasticsearch.transport.TaskTransportChannel"; public static final String SEARCH_HITS_WITNESS_CLASSES = "org.elasticsearch.search.SearchHits"; public static final String CREATE_INDEX_RESPONSE_WITNESS_CLASSES = "org.elasticsearch.client.indices.CreateIndexResponse"; + public static final String CREATE_INDEX_REQUEST_WITNESS_CLASS = "org.elasticsearch.client.indices.CreateIndexRequest"; + public static final String DELETE_INDEX_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest"; + public static final String ANALYZE_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest"; + public static final String REFRESH_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.refresh.RefreshRequest"; //es operator name public static final String CREATE_OPERATOR_NAME = "Elasticsearch/CreateRequest"; public static final String DELETE_OPERATOR_NAME = "Elasticsearch/DeleteRequest"; public static final String ANALYZE_OPERATOR_NAME = "Elasticsearch/AnalyzeRequest"; + public static final String REFRESH_OPERATOR_NAME = "Elasticsearch/RefreshRequest"; public static final String GET_OPERATOR_NAME = "Elasticsearch/GetRequest"; public static final String INDEX_OPERATOR_NAME = "Elasticsearch/IndexRequest"; public static final String SEARCH_OPERATOR_NAME = "Elasticsearch/SearchRequest"; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptor.java index 0ffb9ec59..8ab77d4e8 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptor.java @@ -23,11 +23,13 @@ import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag; 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.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.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; import java.lang.reflect.Method; @@ -36,6 +38,7 @@ import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPlu import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; public class IndicesClientAnalyzeMethodsInterceptor implements InstanceMethodsAroundInterceptor { + private static final ILog LOGGER = LogManager.getLogger(IndicesClientAnalyzeMethodsInterceptor.class); private static final AbstractTag ANALYZER_TAG = Tags.ofKey("analyzer"); diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java index 6fbeb59c9..ae17f85d7 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.client.indices.CreateIndexRequest; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptor.java index c565b4846..454afa08b 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptor.java @@ -28,7 +28,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientRefreshMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientRefreshMethodsInterceptor.java new file mode 100644 index 000000000..9e3cb6fc1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientRefreshMethodsInterceptor.java @@ -0,0 +1,88 @@ +/* + * 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.v6.interceptor; + +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.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; + +import java.lang.reflect.Method; + +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; + +public class IndicesClientRefreshMethodsInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + RefreshRequest request = (RefreshRequest) (allArguments[0]); + + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + AbstractSpan span = ContextManager.createExitSpan(Constants.REFRESH_OPERATOR_NAME, restClientEnhanceInfo.getPeers()); + span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT); + + Tags.DB_TYPE.set(span, DB_TYPE); + Tags.DB_INSTANCE.set(span, buildIndicesString(request.indices())); + SpanLayer.asDB(span); + } + } + + private String buildIndicesString(String[] indices) { + if (indices == null || indices.length == 0) { + return ""; + } + + StringBuilder sb = new StringBuilder(); + int n = indices.length; + for (int i = 0; i < n; i++) { + sb.append(indices[i]); + if (i < n - 1) { + sb.append(','); + } + } + return sb.toString(); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); + if (restClientEnhanceInfo != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); + if (restClientEnhanceInfo != null) { + ContextManager.activeSpan().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptor.java index 72771ac46..d1099f8eb 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptor.java @@ -26,7 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.search.ClearScrollRequest; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptor.java index 59c245235..ddfd8cc95 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptor.java @@ -18,17 +18,15 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -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.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.client.Node; import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestClientBuilder; public class RestHighLevelClientConInterceptor implements InstanceConstructorInterceptor { @@ -36,19 +34,13 @@ public class RestHighLevelClientConInterceptor implements InstanceConstructorInt @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - RestClientBuilder restClientBuilder = (RestClientBuilder) allArguments[0]; - RestClient restClient = restClientBuilder.build(); + RestClient restClient = (RestClient) allArguments[0]; RestClientEnhanceInfo restClientEnhanceInfo = new RestClientEnhanceInfo(); List nodeList = restClient.getNodes(); for (Node node : nodeList) { - restClientEnhanceInfo.addHttpHost(node.getHost()); + restClientEnhanceInfo.addHttpHost(node.getHost().getHostName(), node.getHost().getPort()); } objInst.setSkyWalkingDynamicField(restClientEnhanceInfo); - try { - restClient.close(); - } catch (IOException e) { - LOGGER.error("close restClient error , error message is " + e.getMessage(), e); - } } } diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptor.java index c1fb69720..654c7df7b 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptor.java @@ -26,7 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.index.reindex.DeleteByQueryRequest; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java index 46c737c9c..171bd2980 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.get.GetRequest; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java index e80166fa8..c2075207d 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.index.IndexRequest; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java index c2b5ae3a2..cc709d627 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java @@ -28,7 +28,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.search.SearchRequest; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptor.java index 96e722638..64d503618 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptor.java @@ -26,7 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.search.SearchScrollRequest; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptor.java index fe3d7f634..f57a652b1 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptor.java @@ -26,7 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.script.mustache.SearchTemplateRequest; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java index 864821ecc..b3a34e1aa 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI 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.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.update.UpdateRequest; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java index 5e926513c..9a6c5a090 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java @@ -24,7 +24,6 @@ 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; @@ -41,7 +40,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; -public class TransportActionNodeProxyExecuteMethodsInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { +public class TransportActionNodeProxyExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, @@ -74,12 +73,6 @@ public class TransportActionNodeProxyExecuteMethodsInterceptor implements Instan ContextManager.activeSpan().log(t); } - @Override - public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { - EnhancedInstance actions = (EnhancedInstance) allArguments[2]; - objInst.setSkyWalkingDynamicField(actions.getSkyWalkingDynamicField()); - } - private void parseRequestInfo(ActionRequest request, AbstractSpan span) { // search request if (request instanceof SearchRequest) { diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyThreeArgsConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyThreeArgsConstructorInterceptor.java new file mode 100644 index 000000000..0a6515eb1 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyThreeArgsConstructorInterceptor.java @@ -0,0 +1,33 @@ +/* + * 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.v6.interceptor; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class TransportActionNodeProxyThreeArgsConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + // (Settings settings, GenericAction action, TransportService transportService) + EnhancedInstance actions = (EnhancedInstance) allArguments[2]; + objInst.setSkyWalkingDynamicField(actions.getSkyWalkingDynamicField()); + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyTwoArgsConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyTwoArgsConstructorInterceptor.java new file mode 100644 index 000000000..490236ff5 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyTwoArgsConstructorInterceptor.java @@ -0,0 +1,33 @@ +/* + * 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.v6.interceptor; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class TransportActionNodeProxyTwoArgsConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + // after 7.11 version + // (ActionType action, TransportService transportService) + EnhancedInstance actions = (EnhancedInstance) allArguments[1]; + objInst.setSkyWalkingDynamicField(actions.getSkyWalkingDynamicField()); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptorTest.java index a75691144..3c1b640c1 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptorTest.java index 2ddb460e7..8d1966a66 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java index 3eff5a18f..c57297f0e 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java @@ -35,7 +35,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.common.settings.Settings; import org.junit.Assert; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptorTest.java index faa1779f7..7068fd55c 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java index a3c4ae589..c7b9fdb4b 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.common.bytes.BytesReference; import org.junit.Assert; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptorTest.java index e5938e0dc..b03412dde 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientDeleteMethodsInterceptorTest.java @@ -33,7 +33,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptorTest.java index c60a60c52..83eb39316 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientClearScrollMethodsInterceptorTest.java @@ -35,7 +35,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.search.ClearScrollRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptorTest.java index 6b38b8847..0030c6f7b 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientConInterceptorTest.java @@ -25,10 +25,9 @@ import java.util.List; import org.apache.http.HttpHost; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.client.Node; import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestClientBuilder; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -42,9 +41,6 @@ public class RestHighLevelClientConInterceptorTest { @Rule public MockitoRule rule = MockitoJUnit.rule(); - @Mock - private RestClientBuilder restClientBuilder; - @Mock private RestClient restClient; @@ -58,9 +54,8 @@ public class RestHighLevelClientConInterceptorTest { nodeList.add(new Node(new HttpHost("127.0.0.1", 9200))); nodeList.add(new Node(new HttpHost("127.0.0.1", 9300))); restHighLevelClientConInterceptor = new RestHighLevelClientConInterceptor(); - when(restClientBuilder.build()).thenReturn(restClient); when(restClient.getNodes()).thenReturn(nodeList); - allArguments = new Object[] {restClientBuilder}; + allArguments = new Object[] {restClient}; } @Test diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptorTest.java index 8ee7e22f3..ac65d8ce9 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientDeleteByQueryMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.index.reindex.DeleteByQueryRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java index c67fa8b8f..2c23ca336 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.get.GetRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java index 5d0af33fc..fe75d3da9 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.index.IndexRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java index 152674b5b..b0fa64aa3 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.search.SearchRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptorTest.java index 80ffc0aa1..6cc57cd30 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchScrollMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.search.SearchScrollRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptorTest.java index a1c0c68ad..57fcc5f2e 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchTemplateMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.script.mustache.SearchTemplateRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java index 52c1ddf8b..5d29c751c 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java @@ -34,7 +34,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; -import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; import org.elasticsearch.action.update.UpdateRequest; import org.junit.Assert; import org.junit.Before; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java index cafd86233..48cbe1734 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java @@ -121,7 +121,7 @@ public class TransportActionNodeProxyExecuteMethodsInterceptorTest { } @Test - public void testConstruct() { + public void testConstruct() throws Throwable { final EnhancedInstance objInst1 = new EnhancedInstance() { private Object object = null; @@ -158,7 +158,8 @@ public class TransportActionNodeProxyExecuteMethodsInterceptorTest { objInst1 }; - interceptor.onConstruct(objInst2, allArguments); + TransportActionNodeProxyThreeArgsConstructorInterceptor constructorInterceptor = new TransportActionNodeProxyThreeArgsConstructorInterceptor(); + constructorInterceptor.onConstruct(objInst2, allArguments); assertThat(objInst1.getSkyWalkingDynamicField(), is(objInst2.getSkyWalkingDynamicField())); } diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/pom.xml index c07b3f20f..0f97dd12b 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/pom.xml @@ -32,10 +32,16 @@ UTF-8 - 7.2.1 + 7.17.12 + + org.apache.skywalking + elasticsearch-common + ${project.version} + provided + org.elasticsearch.client elasticsearch-rest-high-level-client diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/Constants.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/Constants.java index 2809f2a91..b7408b7c9 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/Constants.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/Constants.java @@ -23,13 +23,27 @@ import org.apache.skywalking.apm.agent.core.context.tag.Tags; public class Constants { + public static final String INDICES_CLIENT_CREATE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v7.interceptor.IndicesClientCreateMethodsInterceptor"; + public static final String INDICES_CLIENT_DELETE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v7.interceptor.IndicesClientDeleteMethodsInterceptor"; + public static final String INDICES_CLIENT_ANALYZE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v7.interceptor.IndicesClientAnalyzeMethodsInterceptor"; + public static final String INDICES_CLIENT_REFRESH_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v7.interceptor.IndicesClientRefreshMethodsInterceptor"; + //witnessClasses public static final String TASK_TRANSPORT_CHANNEL_WITNESS_CLASSES = "org.elasticsearch.transport.TaskTransportChannel"; public static final String SEARCH_HITS_WITNESS_CLASSES = "org.elasticsearch.search.SearchHits"; + public static final String CREATE_INDEX_REQUEST_WITNESS_CLASS = "org.elasticsearch.client.indices.CreateIndexRequest"; + public static final String DELETE_INDEX_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest"; + public static final String ANALYZE_REQUEST_WITNESS_CLASS = "org.elasticsearch.client.indices.AnalyzeRequest"; + public static final String REFRESH_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.refresh.RefreshRequest"; public static final String DB_TYPE = "Elasticsearch"; public static final String BASE_FUTURE_METHOD = "actionGet"; + public static final String CREATE_OPERATOR_NAME = "Elasticsearch/CreateRequest"; + public static final String DELETE_OPERATOR_NAME = "Elasticsearch/DeleteRequest"; + public static final String ANALYZE_OPERATOR_NAME = "Elasticsearch/AnalyzeRequest"; + public static final String REFRESH_OPERATOR_NAME = "Elasticsearch/RefreshRequest"; + //tags public static final AbstractTag ES_TOOK_MILLIS = Tags.ofKey("es.took_millis"); public static final AbstractTag ES_TOTAL_HITS = Tags.ofKey("es.total_hits"); diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/define/IndicesClientInstrumentation.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/define/IndicesClientInstrumentation.java new file mode 100644 index 000000000..158a3b1ce --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/define/IndicesClientInstrumentation.java @@ -0,0 +1,136 @@ +/* + * 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.v7.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.StaticMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +public class IndicesClientInstrumentation extends ClassEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.elasticsearch.client.IndicesClient"; + + @Override + protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("create").or(named("createAsync")) + .and(takesArgument(0, named(Constants.CREATE_INDEX_REQUEST_WITNESS_CLASS))); + } + + @Override + public String getMethodsInterceptor() { + return Constants.INDICES_CLIENT_CREATE_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("delete").or(named("deleteAsync")) + .and(takesArgument(0, named(Constants.DELETE_INDEX_REQUEST_WITNESS_CLASS))); + } + + @Override + public String getMethodsInterceptor() { + return Constants.INDICES_CLIENT_DELETE_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("analyze").or(named("analyzeAsync")) + .and(takesArgument(0, named(Constants.ANALYZE_REQUEST_WITNESS_CLASS))); + } + + @Override + public String getMethodsInterceptor() { + return Constants.INDICES_CLIENT_ANALYZE_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("refresh").or(named("refreshAsync")) + .and(takesArgument(0, named(Constants.REFRESH_REQUEST_WITNESS_CLASS))); + } + + @Override + public String getMethodsInterceptor() { + return Constants.INDICES_CLIENT_REFRESH_METHODS_INTERCEPTOR; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() { + return new StaticMethodsInterceptPoint[0]; + } + + @Override + protected String[] witnessClasses() { + return new String[] { + Constants.ANALYZE_REQUEST_WITNESS_CLASS, + Constants.CREATE_INDEX_REQUEST_WITNESS_CLASS, + Constants.DELETE_INDEX_REQUEST_WITNESS_CLASS, + Constants.REFRESH_REQUEST_WITNESS_CLASS + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java index b9e3b6bb4..c460d2eac 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java @@ -21,6 +21,8 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v7.interceptor; 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.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.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; @@ -35,12 +37,17 @@ import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.update.UpdateResponse; +import java.lang.reflect.Field; import java.lang.reflect.Method; import static org.apache.skywalking.apm.plugin.elasticsearch.v7.ElasticsearchPluginConfig.Plugin.Elasticsearch.ELASTICSEARCH_DSL_LENGTH_THRESHOLD; import static org.apache.skywalking.apm.plugin.elasticsearch.v7.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceMethodsAroundInterceptor { + private static final ILog LOGGER = LogManager.getLogger(AdapterActionFutureActionGetMethodsInterceptor.class); + + private static final Field SEARCH_RESPONSE_TOOK_FIELD = getTookField(SearchResponse.class); + private static final Field BULK_RESPONSE_TOOK_FIELD = getTookField(BulkResponse.class); @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, @@ -111,7 +118,7 @@ public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceM } private void parseSearchResponse(SearchResponse searchResponse, AbstractSpan span) { - span.tag(Constants.ES_TOOK_MILLIS, Long.toString(searchResponse.getTook().getMillis())); + tagEsTookMillis(SEARCH_RESPONSE_TOOK_FIELD, searchResponse, span); span.tag(Constants.ES_TOTAL_HITS, Long.toString(searchResponse.getHits().getTotalHits().value)); if (TRACE_DSL) { String tagValue = searchResponse.toString(); @@ -121,7 +128,7 @@ public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceM } private void parseBulkResponse(BulkResponse bulkResponse, AbstractSpan span) { - span.tag(Constants.ES_TOOK_MILLIS, Long.toString(bulkResponse.getTook().getMillis())); + tagEsTookMillis(BULK_RESPONSE_TOOK_FIELD, bulkResponse, span); span.tag(Constants.ES_INGEST_TOOK_MILLIS, Long.toString(bulkResponse.getIngestTookInMillis())); if (TRACE_DSL) { String tagValue = bulkResponse.toString(); @@ -130,6 +137,17 @@ public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceM } } + private void tagEsTookMillis(Field field, Object obj, AbstractSpan span) { + if (field == null) { + return; + } + try { + span.tag(Constants.ES_TOOK_MILLIS, Long.toString(field.getLong(obj))); + } catch (Throwable t) { + LOGGER.error("get tookInMillis", t); + } + } + private void parseGetResponse(GetResponse getResponse, AbstractSpan span) { if (TRACE_DSL) { String tagValue = getResponse.toString(); @@ -161,4 +179,15 @@ public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceM Tags.DB_STATEMENT.set(span, tagValue); } } + + private static Field getTookField(Class clazz) { + try { + Field field = clazz.getDeclaredField("tookInMillis"); + field.setAccessible(true); + return field; + } catch (Throwable t) { + LOGGER.error("get tookInMillis field failed", t); + return null; + } + } } diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientAnalyzeMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientAnalyzeMethodsInterceptor.java new file mode 100644 index 000000000..15d399206 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientAnalyzeMethodsInterceptor.java @@ -0,0 +1,83 @@ +/* + * 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.v7.interceptor; + +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.AbstractTag; +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.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.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants; +import org.elasticsearch.client.indices.AnalyzeRequest; + +import java.lang.reflect.Method; + +import static org.apache.skywalking.apm.plugin.elasticsearch.v7.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants.DB_TYPE; + +public class IndicesClientAnalyzeMethodsInterceptor implements InstanceMethodsAroundInterceptor { + private static final ILog LOGGER = LogManager.getLogger(IndicesClientAnalyzeMethodsInterceptor.class); + + private static final AbstractTag ANALYZER_TAG = Tags.ofKey("analyzer"); + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + AnalyzeRequest analyzeRequest = (AnalyzeRequest) allArguments[0]; + + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + AbstractSpan span = ContextManager.createExitSpan(Constants.ANALYZE_OPERATOR_NAME, restClientEnhanceInfo.getPeers()); + span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT); + + Tags.DB_TYPE.set(span, DB_TYPE); + span.tag(ANALYZER_TAG, analyzeRequest.analyzer()); + if (TRACE_DSL) { + Tags.DB_STATEMENT.set(span, analyzeRequest.text()[0]); + } + SpanLayer.asDB(span); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + ContextManager.activeSpan().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientCreateMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientCreateMethodsInterceptor.java new file mode 100644 index 000000000..e4ef7379f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientCreateMethodsInterceptor.java @@ -0,0 +1,73 @@ +/* + * 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.v7.interceptor; + +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.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants; +import org.elasticsearch.client.indices.CreateIndexRequest; + +import java.lang.reflect.Method; + +import static org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants.DB_TYPE; + +public class IndicesClientCreateMethodsInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + CreateIndexRequest createIndexRequest = (CreateIndexRequest) (allArguments[0]); + + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + AbstractSpan span = ContextManager.createExitSpan(Constants.CREATE_OPERATOR_NAME, restClientEnhanceInfo.getPeers()); + span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT); + + Tags.DB_TYPE.set(span, DB_TYPE); + Tags.DB_INSTANCE.set(span, createIndexRequest.index()); + SpanLayer.asDB(span); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); + if (restClientEnhanceInfo != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); + if (restClientEnhanceInfo != null) { + ContextManager.activeSpan().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientDeleteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientDeleteMethodsInterceptor.java new file mode 100644 index 000000000..37ee7658f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientDeleteMethodsInterceptor.java @@ -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.v7.interceptor; + +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.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; + +import java.lang.reflect.Method; +import java.util.Arrays; + +import static org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants.DB_TYPE; + +public class IndicesClientDeleteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + DeleteIndexRequest deleteIndexRequest = (DeleteIndexRequest) allArguments[0]; + + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + AbstractSpan span = ContextManager.createExitSpan(Constants.DELETE_OPERATOR_NAME, restClientEnhanceInfo.getPeers()); + span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT); + + Tags.DB_TYPE.set(span, DB_TYPE); + Tags.DB_INSTANCE.set(span, Arrays.asList(deleteIndexRequest.indices()).toString()); + SpanLayer.asDB(span); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + ContextManager.activeSpan().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientRefreshMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientRefreshMethodsInterceptor.java new file mode 100644 index 000000000..8602be427 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/IndicesClientRefreshMethodsInterceptor.java @@ -0,0 +1,89 @@ +/* + * 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.v7.interceptor; + +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.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo; +import org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; + +import java.lang.reflect.Method; + +import static org.apache.skywalking.apm.plugin.elasticsearch.v7.Constants.DB_TYPE; + +public class IndicesClientRefreshMethodsInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + RefreshRequest request = (RefreshRequest) (allArguments[0]); + + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) objInst.getSkyWalkingDynamicField(); + if (restClientEnhanceInfo != null) { + AbstractSpan span = ContextManager.createExitSpan(Constants.REFRESH_OPERATOR_NAME, restClientEnhanceInfo.getPeers()); + span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT); + + Tags.DB_TYPE.set(span, DB_TYPE); + Tags.DB_INSTANCE.set(span, buildIndicesString(request.indices())); + SpanLayer.asDB(span); + } + } + + private String buildIndicesString(String[] indices) { + if (indices == null || indices.length == 0) { + return ""; + } + + StringBuilder sb = new StringBuilder(); + int n = indices.length; + for (int i = 0; i < n; i++) { + sb.append(indices[i]); + if (i < n - 1) { + sb.append(','); + } + } + return sb.toString(); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); + if (restClientEnhanceInfo != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField()); + if (restClientEnhanceInfo != null) { + ContextManager.activeSpan().log(t); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/resources/skywalking-plugin.def index 23fe26794..c2b34da74 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/resources/skywalking-plugin.def @@ -15,3 +15,4 @@ # limitations under the License. elasticsearch-7.x=org.apache.skywalking.apm.plugin.elasticsearch.v7.define.AdapterActionFutureInstrumentation +elasticsearch-7.x=org.apache.skywalking.apm.plugin.elasticsearch.v7.define.IndicesClientInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-common/pom.xml b/apm-sniffer/apm-sdk-plugin/elasticsearch-common/pom.xml new file mode 100644 index 000000000..fa7c65cce --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-common/pom.xml @@ -0,0 +1,32 @@ + + + + + apm-sdk-plugin + org.apache.skywalking + 9.1.0-SNAPSHOT + + 4.0.0 + + elasticsearch-common + jar + + elasticsearch-common + http://maven.apache.org + diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/RemotePeerCache.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-common/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/common/RemotePeerCache.java similarity index 95% rename from apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/RemotePeerCache.java rename to apm-sniffer/apm-sdk-plugin/elasticsearch-common/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/common/RemotePeerCache.java index e50873c88..f65c69c54 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/RemotePeerCache.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-common/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/common/RemotePeerCache.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.elasticsearch.v6; +package org.apache.skywalking.apm.plugin.elasticsearch.common; /** * Used for store ES connection related information, remotePeers will store the IP address and port, separated by commas diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/RestClientEnhanceInfo.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-common/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/common/RestClientEnhanceInfo.java similarity index 81% rename from apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/RestClientEnhanceInfo.java rename to apm-sniffer/apm-sdk-plugin/elasticsearch-common/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/common/RestClientEnhanceInfo.java index 3c0f8ee94..d852fd343 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/RestClientEnhanceInfo.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-common/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/common/RestClientEnhanceInfo.java @@ -16,16 +16,14 @@ * */ -package org.apache.skywalking.apm.plugin.elasticsearch.v6; - -import org.apache.http.HttpHost; +package org.apache.skywalking.apm.plugin.elasticsearch.common; public class RestClientEnhanceInfo { private RemotePeerCache remotePeerCache = new RemotePeerCache(); - public void addHttpHost(HttpHost httpHost) { - remotePeerCache.addRemotePeer(httpHost.getHostName(), httpHost.getPort()); + public void addHttpHost(String hostName, int port) { + remotePeerCache.addRemotePeer(hostName, port); } public String getPeers() { diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index c4daf8cae..2ecb94b31 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -66,6 +66,7 @@ hystrix-1.x-plugin sofarpc-plugin activemq-5.x-plugin + elasticsearch-common elasticsearch-5.x-plugin elasticsearch-6.x-plugin elasticsearch-7.x-plugin diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml index 53a73d5f8..af47b1b27 100644 --- a/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml @@ -72,7 +72,6 @@ segmentItems: tags: - { key: db.type, value: Elasticsearch } - { key: db.instance, value: not null } - - { key: db.statement, value: not null } skipAnalysis: 'false' - operationName: Elasticsearch/IndexRequest parentSpanId: 0 @@ -89,7 +88,7 @@ segmentItems: - { key: db.instance, value: not null } - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/GetRequest + - operationName: Elasticsearch/RefreshRequest parentSpanId: 0 spanId: 6 spanLayer: Database @@ -102,9 +101,8 @@ segmentItems: tags: - { key: db.type, value: Elasticsearch } - { key: db.instance, value: not null } - - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/SearchRequest + - operationName: Elasticsearch/GetRequest parentSpanId: 0 spanId: 7 spanLayer: Database @@ -119,7 +117,7 @@ segmentItems: - { key: db.instance, value: not null } - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/UpdateRequest + - operationName: Elasticsearch/SearchRequest parentSpanId: 0 spanId: 8 spanLayer: Database @@ -134,7 +132,7 @@ segmentItems: - { key: db.instance, value: not null } - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/DeleteRequest + - operationName: Elasticsearch/UpdateRequest parentSpanId: 0 spanId: 9 spanLayer: Database @@ -147,38 +145,38 @@ segmentItems: tags: - { key: db.type, value: Elasticsearch } - { key: db.instance, value: not null } + - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/IndexRequest + - operationName: Elasticsearch/AnalyzeRequest parentSpanId: 0 spanId: 10 spanLayer: Database startTime: nq 0 endTime: nq 0 - componentId: 48 + componentId: 77 + isError: false + spanType: Exit + peer: not null + tags: + - { key: db.type, value: Elasticsearch } + - { key: analyzer, value: not null } + - { key: db.statement, value: not null } + skipAnalysis: 'false' + - operationName: Elasticsearch/DeleteRequest + parentSpanId: 0 + spanId: 11 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 isError: false spanType: Exit peer: not null tags: - { key: db.type, value: Elasticsearch } - { key: db.instance, value: not null } - - { key: node.address, value: not null } - - { key: es.indices, value: not null } - - { key: es.types, value: not null } - - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/actionGet - parentSpanId: 0 - spanId: 11 - startTime: nq 0 - endTime: nq 0 - componentId: 48 - isError: false - spanType: Local - tags: - - { key: db.type, value: Elasticsearch } - - { key: db.statement, value: not null } - skipAnalysis: 'false' - - operationName: Elasticsearch/GetRequest + - operationName: Elasticsearch/IndexRequest parentSpanId: 0 spanId: 12 spanLayer: Database @@ -196,9 +194,21 @@ segmentItems: - { key: es.types, value: not null } - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/SearchRequest + - operationName: Elasticsearch/actionGet parentSpanId: 0 spanId: 13 + startTime: nq 0 + endTime: nq 0 + componentId: 48 + isError: false + spanType: Local + tags: + - { key: db.type, value: Elasticsearch } + - { key: db.statement, value: not null } + skipAnalysis: 'false' + - operationName: Elasticsearch/GetRequest + parentSpanId: 0 + spanId: 14 spanLayer: Database startTime: nq 0 endTime: nq 0 @@ -214,21 +224,7 @@ segmentItems: - { key: es.types, value: not null } - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/actionGet - parentSpanId: 0 - spanId: 14 - startTime: nq 0 - endTime: nq 0 - componentId: 48 - isError: false - spanType: Local - tags: - - {key: db.type, value: Elasticsearch} - - {key: es.took_millis, value: not null } - - {key: es.total_hits, value: not null } - - {key: db.statement, value: not null } - skipAnalysis: 'false' - - operationName: Elasticsearch/UpdateRequest + - operationName: Elasticsearch/SearchRequest parentSpanId: 0 spanId: 15 spanLayer: Database @@ -246,9 +242,41 @@ segmentItems: - { key: es.types, value: not null } - { key: db.statement, value: not null } skipAnalysis: 'false' - - operationName: Elasticsearch/DeleteRequest + - operationName: Elasticsearch/actionGet parentSpanId: 0 spanId: 16 + startTime: nq 0 + endTime: nq 0 + componentId: 48 + isError: false + spanType: Local + tags: + - {key: db.type, value: Elasticsearch} + - {key: es.took_millis, value: not null } + - {key: es.total_hits, value: not null } + - {key: db.statement, value: not null } + skipAnalysis: 'false' + - operationName: Elasticsearch/UpdateRequest + parentSpanId: 0 + spanId: 17 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 48 + isError: false + spanType: Exit + peer: not null + tags: + - { key: db.type, value: Elasticsearch } + - { key: db.instance, value: not null } + - { key: node.address, value: not null } + - { key: es.indices, value: not null } + - { key: es.types, value: not null } + - { key: db.statement, value: not null } + skipAnalysis: 'false' + - operationName: Elasticsearch/DeleteRequest + parentSpanId: 0 + spanId: 18 spanLayer: Database startTime: nq 0 endTime: nq 0 @@ -266,7 +294,7 @@ segmentItems: skipAnalysis: 'false' - operationName: Elasticsearch/DeleteIndexRequest parentSpanId: 0 - spanId: 17 + spanId: 19 spanLayer: Database startTime: nq 0 endTime: nq 0 diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java index 2a3bccfdb..ce4495634 100644 --- a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java @@ -19,6 +19,7 @@ package org.apache.skywalking.apm.testcase.elasticsearch; import java.io.IOException; +import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.apache.logging.log4j.LogManager; @@ -43,14 +44,13 @@ import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.indices.AnalyzeRequest; +import org.elasticsearch.client.indices.AnalyzeResponse; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexResponse; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.script.Script; @@ -71,7 +71,7 @@ public class RestHighLevelClientCase { public String healthCheck() throws Exception { ClusterHealthRequest request = new ClusterHealthRequest(); - request.timeout(TimeValue.timeValueSeconds(10)); + request.timeout("10s"); request.waitForStatus(ClusterHealthStatus.GREEN); ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT); @@ -101,6 +101,7 @@ public class RestHighLevelClientCase { // index index(indexName); + // refresh client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT); // get @@ -112,6 +113,9 @@ public class RestHighLevelClientCase { // update update(indexName); + // analyze + analyze(indexName); + // delete delete(indexName); } finally { @@ -164,27 +168,16 @@ public class RestHighLevelClientCase { private void createIndex(String indexName) throws IOException { CreateIndexRequest request = new CreateIndexRequest(indexName); - - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.startObject("properties"); - { - builder.startObject("author"); - { - builder.field("type", "keyword"); - } - builder.endObject(); - builder.startObject("title"); - { - builder.field("type", "keyword"); - } - builder.endObject(); - } - builder.endObject(); - } - builder.endObject(); - request.mapping(builder); + Map mapping = new HashMap<>(); + Map mappingProperties = new HashMap<>(); + Map mappingPropertiesAuthor = new HashMap<>(); + mappingPropertiesAuthor.put("type", "keyword"); + mappingProperties.put("author", mappingPropertiesAuthor); + Map mappingPropertiesTitle = new HashMap<>(); + mappingPropertiesTitle.put("type", "keyword"); + mappingProperties.put("title", mappingPropertiesTitle); + mapping.put("properties", mappingProperties); + request.mapping(mapping); request.settings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)); @@ -197,14 +190,10 @@ public class RestHighLevelClientCase { } private void index(String indexName) throws IOException { - XContentBuilder builder = XContentFactory.jsonBuilder(); - builder.startObject(); - { - builder.field("author", "Marker"); - builder.field("title", "Java programing."); - } - builder.endObject(); - IndexRequest indexRequest = new IndexRequest(indexName).id("1").source(builder); + Map source = new HashMap<>(); + source.put("author", "Marker"); + source.put("title", "Java programing."); + IndexRequest indexRequest = new IndexRequest(indexName).id("1").source(source); IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); if (indexResponse.status().getStatus() >= 400) { @@ -239,6 +228,16 @@ public class RestHighLevelClientCase { } } + private void analyze(String indexName) throws IOException { + AnalyzeRequest analyzeRequest = AnalyzeRequest.withIndexAnalyzer(indexName, null, "SkyWalking"); + AnalyzeResponse analyzeResponse = client.indices().analyze(analyzeRequest, RequestOptions.DEFAULT); + if (null == analyzeResponse.getTokens() || analyzeResponse.getTokens().size() < 1) { + String message = "elasticsearch analyze index fail."; + LOGGER.error(message); + throw new RuntimeException(message); + } + } + private void delete(String indexName) throws IOException { DeleteIndexRequest request = new DeleteIndexRequest(indexName); AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT); diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/TransportClientCase.java b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/TransportClientCase.java index 7dcf6b4b9..e6d56089e 100644 --- a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/TransportClientCase.java +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/TransportClientCase.java @@ -19,12 +19,13 @@ package org.apache.skywalking.apm.testcase.elasticsearch; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.xcontent.XContentFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -61,15 +62,14 @@ public class TransportClientCase { private void index(Client client, String indexName) throws IOException { try { + Map source = new HashMap<>(); + source.put("name", "mysql innodb"); + source.put("price", "0"); + source.put("language", "chinese"); client.prepareIndex(indexName, "test", "1") - .setSource(XContentFactory.jsonBuilder() - .startObject() - .field("name", "mysql innodb") - .field("price", "0") - .field("language", "chinese") - .endObject()) + .setSource(source) .get(); - } catch (IOException e) { + } catch (Exception e) { LOGGER.error("index document error.", e); throw e; } @@ -82,9 +82,9 @@ public class TransportClientCase { private void update(Client client, String indexName) throws IOException { try { client.prepareUpdate(indexName, "test", "1") - .setDoc(XContentFactory.jsonBuilder().startObject().field("price", "9.9").endObject()) + .setDoc("price", "9.9") .execute(); - } catch (IOException e) { + } catch (Exception e) { LOGGER.error("update document error.", e); throw e; } diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list b/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list index 3671af56f..54e1c1de5 100644 --- a/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list @@ -14,9 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -7.0.0 -7.1.1 -7.2.1 7.3.2 7.4.2 7.5.2 +7.6.2 +7.7.1 +7.8.1 +7.9.3 +7.10.1 +7.11.2 +7.12.1 +7.13.4 +7.14.2 +7.16.3 +7.17.12 \ No newline at end of file diff --git a/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/config/expectedData.yaml index 2afb090f7..88861a226 100644 --- a/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/config/expectedData.yaml @@ -49,7 +49,7 @@ segmentItems: - {key: db.instance, value: not null} - {key: db.statement, value: not null} skipAnalysis: 'false' - - operationName: Elasticsearch/GetRequest + - operationName: Elasticsearch/RefreshRequest parentSpanId: 0 spanId: 3 spanLayer: Database @@ -60,11 +60,10 @@ segmentItems: spanType: Exit peer: not null tags: - - {key: db.type, value: Elasticsearch} - - {key: db.instance, value: not null} - - {key: db.statement, value: not null} + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} skipAnalysis: 'false' - - operationName: Elasticsearch/SearchRequest + - operationName: Elasticsearch/GetRequest parentSpanId: 0 spanId: 4 spanLayer: Database @@ -78,6 +77,7 @@ segmentItems: - {key: db.type, value: Elasticsearch} - {key: db.instance, value: not null} - {key: db.statement, value: not null} + skipAnalysis: 'false' - operationName: Elasticsearch/SearchRequest parentSpanId: 0 spanId: 5 @@ -89,10 +89,10 @@ segmentItems: spanType: Exit peer: not null tags: - - {key: db.type, value: Elasticsearch} - - {key: db.instance, value: not null} - - {key: db.statement, value: not null} - - operationName: Elasticsearch/SearchScrollRequest + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/SearchRequest parentSpanId: 0 spanId: 6 spanLayer: Database @@ -102,13 +102,27 @@ segmentItems: isError: false spanType: Exit peer: not null + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/SearchScrollRequest + parentSpanId: 0 + spanId: 7 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + isError: false + spanType: Exit + peer: not null tags: - {key: db.type, value: Elasticsearch} - {key: db.statement, value: not null} skipAnalysis: 'false' - operationName: Elasticsearch/SearchRequest parentSpanId: 0 - spanId: 7 + spanId: 8 spanLayer: Database startTime: nq 0 endTime: nq 0 @@ -122,7 +136,7 @@ segmentItems: - {key: db.statement, value: not null} - operationName: Elasticsearch/SearchScrollRequest parentSpanId: 0 - spanId: 8 + spanId: 9 spanLayer: Database startTime: nq 0 endTime: nq 0 @@ -135,20 +149,6 @@ segmentItems: - {key: db.statement, value: not null} skipAnalysis: 'false' - operationName: Elasticsearch/SearchRequest - parentSpanId: 0 - spanId: 9 - spanLayer: Database - startTime: nq 0 - endTime: nq 0 - componentId: 77 - isError: false - spanType: Exit - peer: not null - tags: - - {key: db.type, value: Elasticsearch} - - {key: db.instance, value: not null} - - {key: db.statement, value: not null} - - operationName: Elasticsearch/ClearScrollRequest parentSpanId: 0 spanId: 10 spanLayer: Database @@ -158,13 +158,27 @@ segmentItems: isError: false spanType: Exit peer: not null + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/ClearScrollRequest + parentSpanId: 0 + spanId: 11 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + isError: false + spanType: Exit + peer: not null tags: - {key: db.type, value: Elasticsearch} - {key: db.statement, value: not null} skipAnalysis: 'false' - operationName: Elasticsearch/SearchRequest parentSpanId: 0 - spanId: 11 + spanId: 12 spanLayer: Database startTime: nq 0 endTime: nq 0 @@ -178,7 +192,7 @@ segmentItems: - {key: db.statement, value: not null} - operationName: Elasticsearch/ClearScrollRequest parentSpanId: 0 - spanId: 12 + spanId: 13 spanLayer: Database startTime: nq 0 endTime: nq 0 @@ -190,20 +204,6 @@ segmentItems: - {key: db.type, value: Elasticsearch} - {key: db.statement, value: not null} skipAnalysis: 'false' - - operationName: Elasticsearch/SearchTemplateRequest - parentSpanId: 0 - spanId: 13 - spanLayer: Database - startTime: nq 0 - endTime: nq 0 - componentId: 77 - isError: false - spanType: Exit - peer: not null - tags: - - {key: db.type, value: Elasticsearch} - - {key: db.instance, value: not null} - - {key: db.statement, value: not null} - operationName: Elasticsearch/SearchTemplateRequest parentSpanId: 0 spanId: 14 @@ -218,7 +218,7 @@ segmentItems: - {key: db.type, value: Elasticsearch} - {key: db.instance, value: not null} - {key: db.statement, value: not null} - - operationName: Elasticsearch/UpdateRequest + - operationName: Elasticsearch/SearchTemplateRequest parentSpanId: 0 spanId: 15 spanLayer: Database @@ -228,26 +228,25 @@ segmentItems: isError: false spanType: Exit peer: not null + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/UpdateRequest + parentSpanId: 0 + spanId: 16 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + isError: false + spanType: Exit + peer: not null tags: - {key: db.type, value: Elasticsearch} - {key: db.instance, value: not null} - {key: db.statement, value: not null} skipAnalysis: 'false' - - operationName: Elasticsearch/AnalyzeRequest - parentSpanId: 0 - spanId: 16 - spanLayer: Database - startTime: nq 0 - endTime: nq 0 - componentId: 77 - isError: false - spanType: Exit - peer: not null - tags: - - {key: db.type, value: Elasticsearch} - - {key: analyzer, value: ''} - - {key: db.statement, value: not null} - skipAnalysis: 'false' - operationName: Elasticsearch/AnalyzeRequest parentSpanId: 0 spanId: 17 @@ -260,10 +259,10 @@ segmentItems: peer: not null tags: - {key: db.type, value: Elasticsearch} - - {key: analyzer, value: ''} + - {key: analyzer, value: not null} - {key: db.statement, value: not null} skipAnalysis: 'false' - - operationName: Elasticsearch/DeleteByQueryRequest + - operationName: Elasticsearch/AnalyzeRequest parentSpanId: 0 spanId: 18 spanLayer: Database @@ -275,7 +274,7 @@ segmentItems: peer: not null tags: - {key: db.type, value: Elasticsearch} - - {key: db.instance, value: not null} + - {key: analyzer, value: not null} - {key: db.statement, value: not null} skipAnalysis: 'false' - operationName: Elasticsearch/DeleteByQueryRequest @@ -293,7 +292,7 @@ segmentItems: - {key: db.instance, value: not null} - {key: db.statement, value: not null} skipAnalysis: 'false' - - operationName: Elasticsearch/DeleteRequest + - operationName: Elasticsearch/DeleteByQueryRequest parentSpanId: 0 spanId: 20 spanLayer: Database @@ -303,6 +302,21 @@ segmentItems: isError: false spanType: Exit peer: not null + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + skipAnalysis: 'false' + - operationName: Elasticsearch/DeleteRequest + parentSpanId: 0 + spanId: 21 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + isError: false + spanType: Exit + peer: not null tags: - {key: db.type, value: Elasticsearch} - {key: db.instance, value: not null} diff --git a/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java b/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java index 03f5b0b8d..1a90dc93b 100644 --- a/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java +++ b/test/plugin/scenarios/elasticsearch-rest-high-level-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/RestHighLevelClientCase.java @@ -96,6 +96,7 @@ public class RestHighLevelClientCase { // index index(client, indexName); + // refresh client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT); //get