This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git
The following commit(s) were added to refs/heads/main by this push:
new 5002da5a13 Feature/fix spring data hadoop (#546)
5002da5a13 is described below
commit 5002da5a130ad6e3bd0f889ce865aa2cd1a472f2
Author: gzlicanyi <[email protected]>
AuthorDate: Tue Jun 6 16:21:03 2023 +0800
Feature/fix spring data hadoop (#546)
---
CHANGES.md | 1 +
.../apm/plugin/hbase/HTable100Interceptor.java | 11 +++-
.../plugin/hbase/define/HTableInstrumentation.java | 5 +-
.../apm/plugin/hbase/HTable100InterceptorTest.java | 74 ++++++++++++++++++++++
4 files changed, 88 insertions(+), 3 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 95d404c07e..984fc42d83 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@ Release Notes.
* Support Jdk17 ZGC metric collect
* Support Jetty 11.x plugin
+* Fix the scenario of using the HBase plugin with spring-data-hadoop.
#### Documentation
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
index 3b3528a8e2..d53713a21c 100644
---
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
@@ -20,6 +20,7 @@ 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;
@@ -29,7 +30,15 @@ public class HTable100Interceptor extends HTableInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments)
throws Throwable {
- Configuration configuration = ((ClusterConnection)
allArguments[1]).getConfiguration();
+ Configuration configuration;
+ if (allArguments[1] instanceof ClusterConnection) {
+ configuration = ((ClusterConnection)
allArguments[1]).getConfiguration();
+ } else if (allArguments[0] instanceof Configuration) {
+ configuration = (Configuration) allArguments[0];
+ } else {
+ return;
+ }
+
Field field = configuration.getClass().getDeclaredField("overlay");
field.setAccessible(true);
Properties properties = (Properties) field.get(configuration);
diff --git
a/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.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
index 7ca5d20d8f..77326044af 100644
---
a/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.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
@@ -76,8 +76,9 @@ public class HTableInstrumentation extends
ClassInstanceMethodsEnhancePluginDefi
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription>
getConstructorMatcher() {
- return takesArguments(6)
- .and(takesArgumentWithType(0,
"org.apache.hadoop.hbase.TableName"));
+ return takesArguments(2)
+ .and(takesArgumentWithType(1,
"org.apache.hadoop.hbase.TableName")).or(takesArguments(6)
+ .and(takesArgumentWithType(0,
"org.apache.hadoop.hbase.TableName")));
}
@Override
diff --git
a/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hbase/HTable100InterceptorTest.java
b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hbase/HTable100InterceptorTest.java
new file mode 100644
index 0000000000..dd29489f27
--- /dev/null
+++
b/apm-sniffer/apm-sdk-plugin/hbase-1.x-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/hbase/HTable100InterceptorTest.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.hbase;
+
+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.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+
+@RunWith(MockitoJUnitRunner.class)
+public class HTable100InterceptorTest {
+
+ @Mock
+ private EnhancedInstance objectInstance;
+
+ @Mock
+ private ClusterConnection clusterConnection;
+
+ @Test
+ public void testOnConstructWithConfiguration() throws Throwable {
+
+ HTable100Interceptor interceptor = new HTable100Interceptor();
+
+ Configuration configuration = new Configuration();
+ configuration.set("hbase.zookeeper.quorum", "localhost");
+
+ //test construct: public HTable(Configuration conf, final TableName
tableName) throws IOException
+ Object[] args = new Object[]{configuration, null};
+ interceptor.onConstruct(objectInstance, args);
+ verify(objectInstance).setSkyWalkingDynamicField(any());
+ }
+
+ @Test
+ public void testOnConstructWithConnection() throws Throwable {
+ HTable100Interceptor interceptor = new HTable100Interceptor();
+
+ Configuration configuration = new Configuration();
+ configuration.set("hbase.zookeeper.quorum", "localhost");
+
Mockito.when(clusterConnection.getConfiguration()).thenReturn(configuration);
+
+ //test construct: public HTable(TableName tableName, final
ClusterConnection connection,
+ // final ConnectionConfiguration tableConfig,
+ // final RpcRetryingCallerFactory rpcCallerFactory,
+ // final RpcControllerFactory rpcControllerFactory,
+ // final ExecutorService pool) throws IOException
+
+ Object[] args = new Object[]{null, clusterConnection, null, null,
null, null};
+ interceptor.onConstruct(objectInstance, args);
+ verify(objectInstance).setSkyWalkingDynamicField(any());
+ }
+
+}
\ No newline at end of file