Skip to content

Commit 44b8f66

Browse files
authored
Optimize ElasticSearch 6.x 7.x plugin compatibility (#607)
1 parent bc7447a commit 44b8f66

60 files changed

Lines changed: 935 additions & 170 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Release Notes.
66
------------------
77

88
* Fix hbase onConstruct NPE in the file configuration scenario
9+
* Optimize ElasticSearch 6.x 7.x plugin compatibility
910

1011
#### Documentation
1112

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
</properties>
3737

3838
<dependencies>
39+
<dependency>
40+
<groupId>org.apache.skywalking</groupId>
41+
<artifactId>elasticsearch-common</artifactId>
42+
<version>${project.version}</version>
43+
<scope>provided</scope>
44+
</dependency>
3945
<dependency>
4046
<groupId>org.elasticsearch.client</groupId>
4147
<artifactId>elasticsearch-rest-high-level-client</artifactId>

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/IndicesClientInstrumentation.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.skywalking.apm.plugin.elasticsearch.v6.define;
2020

2121
import static net.bytebuddy.matcher.ElementMatchers.named;
22+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
2223
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
2324

2425
import net.bytebuddy.description.method.MethodDescription;
@@ -56,7 +57,8 @@ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
5657
new InstanceMethodsInterceptPoint() {
5758
@Override
5859
public ElementMatcher<MethodDescription> getMethodsMatcher() {
59-
return named("create").or(named("createAsync"));
60+
return named("create").or(named("createAsync"))
61+
.and(takesArgument(0, named(Constants.CREATE_INDEX_REQUEST_WITNESS_CLASS)));
6062
}
6163

6264
@Override
@@ -72,7 +74,8 @@ public boolean isOverrideArgs() {
7274
new InstanceMethodsInterceptPoint() {
7375
@Override
7476
public ElementMatcher<MethodDescription> getMethodsMatcher() {
75-
return named("delete").or(named("deleteAsync"));
77+
return named("delete").or(named("deleteAsync"))
78+
.and(takesArgument(0, named(Constants.DELETE_INDEX_REQUEST_WITNESS_CLASS)));
7679
}
7780

7881
@Override
@@ -88,7 +91,8 @@ public boolean isOverrideArgs() {
8891
new InstanceMethodsInterceptPoint() {
8992
@Override
9093
public ElementMatcher<MethodDescription> getMethodsMatcher() {
91-
return named("analyze").or(named("analyzeAsync"));
94+
return named("analyze").or(named("analyzeAsync"))
95+
.and(takesArgument(0, named(Constants.ANALYZE_REQUEST_WITNESS_CLASS)));
9296
}
9397

9498
@Override
@@ -100,12 +104,39 @@ public String getMethodsInterceptor() {
100104
public boolean isOverrideArgs() {
101105
return false;
102106
}
103-
}
107+
},
108+
new InstanceMethodsInterceptPoint() {
109+
@Override
110+
public ElementMatcher<MethodDescription> getMethodsMatcher() {
111+
return named("refresh").or(named("refreshAsync"))
112+
.and(takesArgument(0, named(Constants.REFRESH_REQUEST_WITNESS_CLASS)));
113+
}
114+
115+
@Override
116+
public String getMethodsInterceptor() {
117+
return Constants.INDICES_CLIENT_REFRESH_METHODS_INTERCEPTOR;
118+
}
119+
120+
@Override
121+
public boolean isOverrideArgs() {
122+
return false;
123+
}
124+
}
104125
};
105126
}
106127

107128
@Override
108129
public StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
109130
return new StaticMethodsInterceptPoint[0];
110131
}
132+
133+
@Override
134+
protected String[] witnessClasses() {
135+
return new String[] {
136+
Constants.ANALYZE_REQUEST_WITNESS_CLASS,
137+
Constants.CREATE_INDEX_REQUEST_WITNESS_CLASS,
138+
Constants.DELETE_INDEX_REQUEST_WITNESS_CLASS,
139+
Constants.REFRESH_REQUEST_WITNESS_CLASS
140+
};
141+
}
111142
}

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/RestHighLevelClientInstrumentation.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants;
2929

3030
import static net.bytebuddy.matcher.ElementMatchers.named;
31-
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
32-
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
31+
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
3332
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3433

3534
/**
@@ -60,7 +59,7 @@ public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
6059
new ConstructorInterceptPoint() {
6160
@Override
6261
public ElementMatcher<MethodDescription> getConstructorMatcher() {
63-
return takesArguments(1);
62+
return takesArgument(0, named("org.elasticsearch.client.RestClient"));
6463
}
6564

6665
@Override
@@ -74,22 +73,6 @@ public String getConstructorInterceptor() {
7473
@Override
7574
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
7675
return new InstanceMethodsInterceptPoint[] {
77-
new InstanceMethodsInterceptPoint() {
78-
@Override
79-
public ElementMatcher<MethodDescription> getMethodsMatcher() {
80-
return named("performRequestAndParseEntity").and(takesArgumentWithType(0, "org.elasticsearch.client.indices.CreateIndexRequest"));
81-
}
82-
83-
@Override
84-
public String getMethodsInterceptor() {
85-
return Constants.INDICES_CLIENT_CREATE_METHODS_INTERCEPTOR;
86-
}
87-
88-
@Override
89-
public boolean isOverrideArgs() {
90-
return false;
91-
}
92-
},
9376
new InstanceMethodsInterceptPoint() {
9477
@Override
9578
public ElementMatcher<MethodDescription> getMethodsMatcher() {

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/define/TransportActionNodeProxyInstrumentation.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,46 @@
2020

2121
import net.bytebuddy.description.method.MethodDescription;
2222
import net.bytebuddy.matcher.ElementMatcher;
23+
import net.bytebuddy.matcher.ElementMatchers;
2324
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
2425
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
2526
import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
2627
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine;
2728
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2829
import org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants;
2930

30-
import static net.bytebuddy.matcher.ElementMatchers.any;
3131
import static net.bytebuddy.matcher.ElementMatchers.named;
3232
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3333

3434
public class TransportActionNodeProxyInstrumentation extends ClassEnhancePluginDefine {
3535

3636
public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.TransportActionNodeProxyExecuteMethodsInterceptor";
37+
public static final String THREE_ARGS_CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.TransportActionNodeProxyThreeArgsConstructorInterceptor";
38+
public static final String TWO_ARGS_CONSTRUCTOR2_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.TransportActionNodeProxyTwoArgsConstructorInterceptor";
3739
public static final String ENHANC_CLASS = "org.elasticsearch.action.TransportActionNodeProxy";
40+
public static final String CONSTRUCTOR_ARG_CLASS = "org.elasticsearch.transport.TransportService";
3841

3942
@Override
4043
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
4144
return new ConstructorInterceptPoint[]{
4245
new ConstructorInterceptPoint() {
4346
@Override public ElementMatcher<MethodDescription> getConstructorMatcher() {
44-
return any();
47+
return ElementMatchers.takesArgument(2, named(CONSTRUCTOR_ARG_CLASS));
4548
}
4649

4750
@Override public String getConstructorInterceptor() {
48-
return INTERCEPTOR_CLASS;
51+
return THREE_ARGS_CONSTRUCTOR_INTERCEPTOR_CLASS;
52+
}
53+
},
54+
new ConstructorInterceptPoint() {
55+
@Override
56+
public ElementMatcher<MethodDescription> getConstructorMatcher() {
57+
return ElementMatchers.takesArgument(1, named(CONSTRUCTOR_ARG_CLASS));
58+
}
59+
60+
@Override
61+
public String getConstructorInterceptor() {
62+
return TWO_ARGS_CONSTRUCTOR2_INTERCEPTOR_CLASS;
4963
}
5064
}
5165
};

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientGetSettingsMethodsInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2828
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2929
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
30-
import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo;
30+
import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo;
3131

3232
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE;
3333

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientHealthMethodsInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2828
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2929
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
30-
import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo;
30+
import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo;
3131

3232
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE;
3333

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2828
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2929
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
30-
import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo;
30+
import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo;
3131
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
3232
import org.elasticsearch.common.settings.Settings;
3333

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/Constants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class Constants {
2727
public static final String INDICES_CLIENT_CREATE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientCreateMethodsInterceptor";
2828
public static final String INDICES_CLIENT_DELETE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientDeleteMethodsInterceptor";
2929
public static final String INDICES_CLIENT_ANALYZE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientAnalyzeMethodsInterceptor";
30+
public static final String INDICES_CLIENT_REFRESH_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.IndicesClientRefreshMethodsInterceptor";
3031
public static final String REST_HIGH_LEVEL_CLIENT_SEARCH_SCROLL_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.RestHighLevelClientSearchScrollMethodsInterceptor";
3132
public static final String REST_HIGH_LEVEL_CLIENT_SEARCH_TEMPLATE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.RestHighLevelClientSearchTemplateMethodsInterceptor";
3233
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 {
4546
public static final String TASK_TRANSPORT_CHANNEL_WITNESS_CLASSES = "org.elasticsearch.transport.TaskTransportChannel";
4647
public static final String SEARCH_HITS_WITNESS_CLASSES = "org.elasticsearch.search.SearchHits";
4748
public static final String CREATE_INDEX_RESPONSE_WITNESS_CLASSES = "org.elasticsearch.client.indices.CreateIndexResponse";
49+
public static final String CREATE_INDEX_REQUEST_WITNESS_CLASS = "org.elasticsearch.client.indices.CreateIndexRequest";
50+
public static final String DELETE_INDEX_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest";
51+
public static final String ANALYZE_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest";
52+
public static final String REFRESH_REQUEST_WITNESS_CLASS = "org.elasticsearch.action.admin.indices.refresh.RefreshRequest";
4853

4954
//es operator name
5055
public static final String CREATE_OPERATOR_NAME = "Elasticsearch/CreateRequest";
5156
public static final String DELETE_OPERATOR_NAME = "Elasticsearch/DeleteRequest";
5257
public static final String ANALYZE_OPERATOR_NAME = "Elasticsearch/AnalyzeRequest";
58+
public static final String REFRESH_OPERATOR_NAME = "Elasticsearch/RefreshRequest";
5359
public static final String GET_OPERATOR_NAME = "Elasticsearch/GetRequest";
5460
public static final String INDEX_OPERATOR_NAME = "Elasticsearch/IndexRequest";
5561
public static final String SEARCH_OPERATOR_NAME = "Elasticsearch/SearchRequest";

apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientAnalyzeMethodsInterceptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
2424
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
2525
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
26+
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
27+
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
2628
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
2729
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
2830
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
2931
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
30-
import org.apache.skywalking.apm.plugin.elasticsearch.v6.RestClientEnhanceInfo;
32+
import org.apache.skywalking.apm.plugin.elasticsearch.common.RestClientEnhanceInfo;
3133
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
3234

3335
import java.lang.reflect.Method;
@@ -36,6 +38,7 @@
3638
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE;
3739

3840
public class IndicesClientAnalyzeMethodsInterceptor implements InstanceMethodsAroundInterceptor {
41+
private static final ILog LOGGER = LogManager.getLogger(IndicesClientAnalyzeMethodsInterceptor.class);
3942

4043
private static final AbstractTag<String> ANALYZER_TAG = Tags.ofKey("analyzer");
4144

0 commit comments

Comments
 (0)