Repository: pinpoint-apm/pinpoint
Issue: Why is there no Hbase plugin support?
Labels: enhancement
module:plugin

**Which module is your feature request related to?**
Plugin/Hbase

**Is your feature request related to a problem?**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
Hbase GET/PUT/DELETE/SCAN etc

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.


Issue comments:
Hello, @VictorZeng 

We hope that we can provide all the features. But unfortunately, it's not easy due to lack of time.
It would be GREAT for Pinpoint Community if you can make Hbase-plugin and share with us:)
@RoySRose I will make the Hbase-plugin.
@VictorZeng 
Oh! Perfect~! We are really looking forward to it~!

Pull request review comments:

Patch that resolved the issue:
diff --git a/plugins/hbase/pom.xml b/plugins/hbase/pom.xml
index 43e62534ee35..db1e83651b21 100644
--- a/plugins/hbase/pom.xml
+++ b/plugins/hbase/pom.xml
@@ -27,12 +27,35 @@
     <name>pinpoint-hbase-plugin</name>
     <packaging>jar</packaging>
 
+    <properties>
+        <jdk.version>1.6</jdk.version>
+        <jdk.home>${env.JAVA_7_HOME}</jdk.home>
+        <sniffer.artifactid>java17</sniffer.artifactid>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.navercorp.pinpoint</groupId>
+                <artifactId>pinpoint-plugin-bom</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
     <dependencies>
         <dependency>
             <groupId>com.navercorp.pinpoint</groupId>
             <artifactId>pinpoint-bootstrap-core</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.hbase</groupId>
+            <artifactId>hbase-shaded-client</artifactId>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/HbaseTableMethodInterceptor.java b/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/HbaseTableMethodInterceptor.java
index 28dffdcc01d4..94832444e438 100644
--- a/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/HbaseTableMethodInterceptor.java
+++ b/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/HbaseTableMethodInterceptor.java
@@ -19,6 +19,10 @@
 import com.navercorp.pinpoint.bootstrap.context.TraceContext;
 import com.navercorp.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptorForPlugin;
 import com.navercorp.pinpoint.plugin.hbase.HbasePluginConstants;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.util.Bytes;
 
 import java.util.List;
 
@@ -75,27 +79,29 @@ protected String parseAttributes(Object[] args) {
             param = args[0];
         } else if (args != null && args.length > 1) { // last param
             param = args[args.length - 1];
+        } else {
+            return null;
         }
 
-        if (param != null) {
-            // if param instanceof List.
-            if (param instanceof List) {
-                List list = (List) param;
-                return "size: " + list.size();
-            }
-            // if has getRow method. e.g. Get/Put/Delete/Append/Increment/...
-            try {
-                byte[] rowkey = (byte[]) param.getClass().getMethod("getRow").invoke(param);
-                return "rowKey: " + new String(rowkey);
-            } catch (Exception e) {
-            }
-            // if has getStartRow and getStopRow method. e.g. Scan
-            try {
-                byte[] startRowkey = (byte[]) param.getClass().getMethod("getStartRow").invoke(param);
-                byte[] stopRowkey = (byte[]) param.getClass().getMethod("getStopRow").invoke(param);
-                return "startRowKey: " + new String(startRowkey) + " stopRowKey: " + new String(stopRowkey);
-            } catch (Exception e) {
-            }
+        // Put/Delete/Append/Increment
+        if (param instanceof Mutation) {
+            Mutation mutation = (Mutation) param;
+            return "rowKey: " + Bytes.toStringBinary(mutation.getRow());
+        }
+        if (param instanceof Get) {
+            Get get = (Get) param;
+            return "rowKey: " + Bytes.toStringBinary(get.getRow());
+        }
+        if (param instanceof Scan) {
+            Scan scan = (Scan) param;
+            String startRowKey = Bytes.toStringBinary(scan.getStartRow());
+            String stopRowKey = Bytes.toStringBinary(scan.getStopRow());
+            return "startRowKey: " + startRowKey + " stopRowKey: " + stopRowKey;
+        }
+        // if param instanceof List.
+        if (param instanceof List) {
+            List list = (List) param;
+            return "size: " + list.size();
         }
         return null;
     }


Test patch:
diff --git a/agent-it/src/test/java/com/navercorp/pinpoint/plugin/hbase/HbaseClientIT.java b/agent-it/src/test/java/com/navercorp/pinpoint/plugin/hbase/HbaseClientIT.java
index f0f57f671ee9..d437fc16f414 100644
--- a/agent-it/src/test/java/com/navercorp/pinpoint/plugin/hbase/HbaseClientIT.java
+++ b/agent-it/src/test/java/com/navercorp/pinpoint/plugin/hbase/HbaseClientIT.java
@@ -20,7 +20,7 @@
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent(AgentPath.PATH)
 @JvmVersion(8)
-@Dependency({"org.apache.hbase:hbase-shaded-client:[1.2.6.1]", "org.mockito:mockito-all:1.8.4"})
+@Dependency({"org.apache.hbase:hbase-shaded-client:[1.2.6.1]", "org.mockito:mockito-core:2.7.22"})
 @PinpointConfig("hbase/pinpoint-hbase-test.config")
 public class HbaseClientIT {
 
@@ -48,8 +48,8 @@ public void testAdmin() throws Exception {
 
         verifier.printCache();
 
-        verifier.verifyTrace(event("HBASE_ADMIN", HBaseAdmin.class.getDeclaredMethod("tableExists", TableName.class),
-                annotation("hbase.params", "[test]")));
+        verifier.verifyTrace(event("HBASE_CLIENT_ADMIN", HBaseAdmin.class.getDeclaredMethod("tableExists", TableName.class),
+                annotation("hbase.client.params", "[test]")));
 
         verifier.verifyTraceCount(0);
     }
@@ -72,8 +72,8 @@ public void testTable() throws Exception {
 
         verifier.printCache();
 
-        verifier.verifyTrace(event("HBASE_TABLE", HTable.class.getDeclaredMethod("put", Put.class),
-                annotation("hbase.params", "rowKey: row")));
+        verifier.verifyTrace(event("HBASE_CLIENT_TABLE", HTable.class.getDeclaredMethod("put", Put.class),
+                annotation("hbase.client.params", "rowKey: row")));
 
         verifier.verifyTraceCount(0);
     }