From 51b60ae2181c0157bf956efa08548d1638354c79 Mon Sep 17 00:00:00 2001 From: Stephen Ni Date: Thu, 25 Mar 2021 14:08:31 +0800 Subject: [PATCH] Update the agent HBase plugin to support HBase Client 2.x (#6577) --- CHANGES.md | 1 + .../pom.xml | 6 +- .../plugin/hbase/HTable100Interceptor.java | 41 ++++++++++++++ .../plugin/hbase/HTable200Interceptor.java | 41 ++++++++++++++ .../plugin/hbase/HTable220Interceptor.java | 43 ++++++++++++++ .../apm/plugin/hbase/HTableInterceptor.java | 0 .../hbase/define/HTableInstrumentation.java | 56 ++++++++++++++++--- .../src/main/resources/skywalking-plugin.def | 2 +- apm-sniffer/apm-sdk-plugin/pom.xml | 2 +- .../service-agent/java-agent/Plugin-list.md | 2 +- .../java-agent/Supported-list.md | 2 +- .../hbase-scenario/configuration.yml | 2 +- .../hbase-scenario/support-version.list | 4 +- 13 files changed, 186 insertions(+), 16 deletions(-) rename apm-sniffer/apm-sdk-plugin/{hbase-1.x-plugin => hbase-1.x-2.x-plugin}/pom.xml (90%) create mode 100644 apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable100Interceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable200Interceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable220Interceptor.java rename apm-sniffer/apm-sdk-plugin/{hbase-1.x-plugin => hbase-1.x-2.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{hbase-1.x-plugin => hbase-1.x-2.x-plugin}/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java (58%) rename apm-sniffer/apm-sdk-plugin/{hbase-1.x-plugin => hbase-1.x-2.x-plugin}/src/main/resources/skywalking-plugin.def (90%) diff --git a/CHANGES.md b/CHANGES.md index 35a7d9b15c..986942efa2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ Release Notes. * Collect and report agent starting / shutdown events. * Support jedis pipeline in jedis-2.x-plugin. * Fix apm-toolkit-log4j-2.x-activation no trace Id in async log. +* Replace hbase-1.x-plugin with hbase-1.x-2.x-plugin to adapt hbase client 2.x #### OAP-Backend * Allow user-defined `JAVA_OPTS` in the startup script. diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/pom.xml similarity index 90% rename from apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/pom.xml rename to apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/pom.xml index 415be34578..8913440eed 100644 --- a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/pom.xml @@ -26,12 +26,12 @@ 8.5.0-SNAPSHOT - apm-hbase-1.x-plugin + apm-hbase-1.x-2.x-plugin jar - hbase-1.x-plugin + hbase-1.x-2.x-plugin - 1.4.9 + 2.4.1 diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable100Interceptor.java b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable100Interceptor.java new file mode 100644 index 0000000000..3b3528a8e2 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable100Interceptor.java @@ -0,0 +1,41 @@ +/* + * 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.hbase; + +import java.lang.reflect.Field; +import java.util.Properties; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.ClusterConnection; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.util.StringUtil; + +public class HTable100Interceptor extends HTableInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + Configuration configuration = ((ClusterConnection) allArguments[1]).getConfiguration(); + Field field = configuration.getClass().getDeclaredField("overlay"); + field.setAccessible(true); + Properties properties = (Properties) field.get(configuration); + String value = properties.getProperty("hbase.zookeeper.quorum"); + if (StringUtil.isNotBlank(value)) { + objInst.setSkyWalkingDynamicField(value); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable200Interceptor.java b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable200Interceptor.java new file mode 100644 index 0000000000..be23cba600 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable200Interceptor.java @@ -0,0 +1,41 @@ +/* + * 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.hbase; + +import java.lang.reflect.Field; +import java.util.Properties; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.ClusterConnection; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.util.StringUtil; + +public class HTable200Interceptor extends HTableInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + Configuration configuration = ((ClusterConnection) allArguments[0]).getConfiguration(); + Field field = configuration.getClass().getDeclaredField("overlay"); + field.setAccessible(true); + Properties properties = (Properties) field.get(configuration); + String value = properties.getProperty("hbase.zookeeper.quorum"); + if (StringUtil.isNotBlank(value)) { + objInst.setSkyWalkingDynamicField(value); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable220Interceptor.java b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable220Interceptor.java new file mode 100644 index 0000000000..4d8e224410 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTable220Interceptor.java @@ -0,0 +1,43 @@ +/* + * 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.hbase; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Properties; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.util.StringUtil; + +public class HTable220Interceptor extends HTableInterceptor { + + @Override + public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable { + Method getConfigurationMethod = Connection.class.getMethod("getConfiguration"); + Configuration configuration = (Configuration) getConfigurationMethod.invoke(allArguments[0]); + Field field = configuration.getClass().getDeclaredField("overlay"); + field.setAccessible(true); + Properties properties = (Properties) field.get(configuration); + String value = properties.getProperty("hbase.zookeeper.quorum"); + if (StringUtil.isNotBlank(value)) { + objInst.setSkyWalkingDynamicField(value); + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java rename to apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/HTableInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java similarity index 58% rename from apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java index af73efc9ac..7ca5d20d8f 100644 --- a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/hbase/define/HTableInstrumentation.java @@ -47,11 +47,22 @@ import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +/** + * There have several interceptors to adapt different version hbase client. We use the minimal compatible version to + * name the Interceptor. eg. + *

HTable100Interceptor, 100 means version 1.0.0, compatible with version [1.0.0, 2.0.0)

+ *

HTable200Interceptor, 200 means version 2.0.0, compatible with version [2.0.0, 2.2.0)

+ *

HTable220Interceptor, 220 means version 2.2.0, compatible with version [2.2.0, )

+ */ public class HTableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { private static final String ENHANCE_CLASS = "org.apache.hadoop.hbase.client.HTable"; private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hbase.HTableInterceptor"; + private static final String INTERCEPT_CLASS_100 = "org.apache.skywalking.apm.plugin.hbase.HTable100Interceptor"; + private static final String INTERCEPT_CLASS_200 = "org.apache.skywalking.apm.plugin.hbase.HTable200Interceptor"; + private static final String INTERCEPT_CLASS_220 = "org.apache.skywalking.apm.plugin.hbase.HTable220Interceptor"; @Override protected ClassMatch enhanceClass() { @@ -60,16 +71,44 @@ public class HTableInstrumentation extends ClassInstanceMethodsEnhancePluginDefi @Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[]{ + return new ConstructorInterceptPoint[] { + // compatible with version [1.0.0, 2.0.0) new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return takesArguments(6); + return takesArguments(6) + .and(takesArgumentWithType(0, "org.apache.hadoop.hbase.TableName")); } @Override public String getConstructorInterceptor() { - return INTERCEPT_CLASS; + return INTERCEPT_CLASS_100; + } + }, + // compatible with version [2.0.0, 2.2.0) + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArguments(5) + .and(takesArgumentWithType(0, "org.apache.hadoop.hbase.client.ClusterConnection")); + } + + @Override + public String getConstructorInterceptor() { + return INTERCEPT_CLASS_200; + } + }, + // compatible with version [2.2.0, ) + new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArguments(5) + .and(takesArgumentWithType(0, "org.apache.hadoop.hbase.client.ConnectionImplementation")); + } + + @Override + public String getConstructorInterceptor() { + return INTERCEPT_CLASS_220; } } }; @@ -77,13 +116,16 @@ public class HTableInstrumentation extends ClassInstanceMethodsEnhancePluginDefi @Override public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{ + return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named("delete").or(named("put")).or(isPublic().and(named("get"))) - .or(named("getScanner").and(takesArguments(1)) - .and(takesArgument(0, named("org.apache.hadoop.hbase.client.Scan")))); + return named("delete") + .or(named("put")) + .or(isPublic().and(named("get"))) + .or(named("getScanner") + .and(takesArguments(1)) + .and(takesArgument(0, named("org.apache.hadoop.hbase.client.Scan")))); } @Override() diff --git a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/resources/skywalking-plugin.def similarity index 90% rename from apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/resources/skywalking-plugin.def index aad5b0238c..7e1acdded3 100644 --- a/apm-sniffer/apm-sdk-plugin/hbase-1.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -14,4 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -hbase-1.x=org.apache.skywalking.apm.plugin.hbase.define.HTableInstrumentation \ No newline at end of file +hbase-1.x/2.x=org.apache.skywalking.apm.plugin.hbase.define.HTableInstrumentation \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 202ddef850..2676756b95 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -97,7 +97,7 @@ mariadb-2.x-plugin influxdb-2.x-plugin baidu-brpc-plugin - hbase-1.x-plugin + hbase-1.x-2.x-plugin graphql-plugin xxl-job-2.x-plugin thrift-plugin diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md index b8e7c2bd6d..41ba14d95e 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -23,7 +23,7 @@ - grpc-1.x - gson-2.8.x - h2-1.x -- hbase-1.x +- hbase-1.x/2.x - httpasyncclient-4.x - httpclient-3.x - httpclient-4.x diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index dfc01aa05a..6b9ee71862 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -83,7 +83,7 @@ metrics based on the tracing data. * [Cassandra](https://github.com/apache/cassandra) 3.x * [cassandra-java-driver](https://github.com/datastax/java-driver) 3.7.0-3.7.2 * HBase - * [hbase-client](https://github.com/apache/hbase) HTable 1.x + * [hbase-client](https://github.com/apache/hbase) HTable 1.0.0-2.4.2 * Service Discovery * [Netflix Eureka](https://github.com/Netflix/eureka) * Distributed Coordination diff --git a/test/plugin/scenarios/hbase-scenario/configuration.yml b/test/plugin/scenarios/hbase-scenario/configuration.yml index 952b5c9b89..7cbd923948 100644 --- a/test/plugin/scenarios/hbase-scenario/configuration.yml +++ b/test/plugin/scenarios/hbase-scenario/configuration.yml @@ -24,7 +24,7 @@ depends_on: - hbase-server dependencies: hbase-server: - image: harisekhon/hbase:1.4 + image: harisekhon/hbase:2.1 hostname: hbase-server expose: - "2181" diff --git a/test/plugin/scenarios/hbase-scenario/support-version.list b/test/plugin/scenarios/hbase-scenario/support-version.list index 6e0034bc11..230dce131c 100644 --- a/test/plugin/scenarios/hbase-scenario/support-version.list +++ b/test/plugin/scenarios/hbase-scenario/support-version.list @@ -16,4 +16,6 @@ 1.2.6 1.3.1 -1.4.9 \ No newline at end of file +1.4.9 +2.1.10 +2.4.2 \ No newline at end of file -- GitLab