gzlicanyi opened a new pull request, #546:
URL: https://github.com/apache/skywalking-java/pull/546

   <!--
       ⚠️ Please make sure to read this template first, pull requests that 
don't accord with this template
       maybe closed without notice.
       Texts surrounded by `<` and `>` are meant to be replaced by you, e.g. 
<framework name>, <issue number>.
       Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]`
   -->
   
   
   ### Fix <bug description or the bug issue number or bug issue link>
   - [x] Add a unit test to verify that the fix works.
   - [x] Explain briefly why the bug exists and how to fix it.
   
   #### problem
   When using HbaseTemplate, the following error occurs:
   ```
   ERROR 2023-06-05 17:06:37.757 http-nio-0.0.0.0-80-exec-3 InstMethodsInter : 
class[class org.apache.hadoop.hbase.client.HTable] before method[getScanner] 
intercept failure 
   java.lang.IllegalStateException: Exit span doesn't include meaningful peer 
information.
           at 
org.apache.skywalking.apm.agent.core.context.TracingContext.inject(TracingContext.java:169)
           at 
org.apache.skywalking.apm.agent.core.context.TracingContext.inject(TracingContext.java:149)
           at 
org.apache.skywalking.apm.agent.core.context.ContextManager.createExitSpan(ContextManager.java:134)
           at 
org.apache.skywalking.apm.plugin.hbase.HTableInterceptor.beforeMethod(HTableInterceptor.java:72)
           at 
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:76)
           at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java)
           at 
org.springframework.data.hadoop.hbase.HbaseTemplate$1.doInTable(HbaseTemplate.java:132)
           at 
org.springframework.data.hadoop.hbase.HbaseTemplate.execute(HbaseTemplate.java:61)
           at 
org.springframework.data.hadoop.hbase.HbaseTemplate.find(HbaseTemplate.java:129)
           at 
org.springframework.data.hadoop.hbase.HbaseTemplate.find(HbaseTemplate.java:158)
   ```
   
   #### Steps to reproduce
   
   1. Using the following dependencies:
   ```xml
   <dependency>
               <groupId>org.apache.hbase</groupId>
               <artifactId>hbase-client</artifactId>
               <version>1.6.0</version>
           </dependency>
           <dependency>
               <groupId>org.springframework.data</groupId>
               <artifactId>spring-data-hadoop</artifactId>
               <version>2.5.0.RELEASE</version>
           </dependency>
   ```
   
   2. spring bean config
   ```xml
   <hdp:configuration id="hadoopConfiguration"></hdp:configuration>
       <hdp:hbase-configuration delete-connection="true" stop-proxy="false">
           hbase.zookeeper.quorum=${hbase.zookeeper.quorum}
           hbase.zookeeper.property.clientPort=${hbase.zookeeper.port}
       </hdp:hbase-configuration>
   
       <bean id="hbaseTemplate" 
class="org.springframework.data.hadoop.hbase.HbaseTemplate">
           <property name="configuration" ref="hbaseConfiguration" />
       </bean>
   ```
   
   3. using HbaseTemplate
   ```java
   hbaseTemplate.find(String tableName, final Scan scan, final RowMapper<T> 
action);
   ```
   
   #### Causes
   HbaseTemplate uses HbaseUtils to create 
[HTable](https://github.com/apache/hbase/blob/rel/1.6.0/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java),
 and the constructor used by HTable is `public HTable(Configuration conf, final 
TableName tableName)`, which is not byte code enhanced.
   
   `HbaseUtils.getHTable` source code:
   ```java
   public static HTableInterface getHTable(String tableName, Configuration 
configuration, Charset charset, HTableInterfaceFactory tableFactory) {
                if (HbaseSynchronizationManager.hasResource(tableName)) {
                        return (HTable) 
HbaseSynchronizationManager.getResource(tableName);
                }
   
                HTableInterface t = null;
                try {
                        if (tableFactory != null) {
                                t = 
tableFactory.createHTableInterface(configuration, tableName.getBytes(charset));
                        }
                        else {
                                t = new HTable(configuration, 
tableName.getBytes(charset));
                        }
   
                        return t;
   
                } catch (Exception ex) {
                        throw convertHbaseException(ex);
                }
        }
   ```
   
   #### how to fix it
   Add byte code enhancement for `public HTable(Configuration conf, final 
TableName tableName)`.
   
   
   <!-- ==== 🔌 Remove this line WHEN AND ONLY WHEN you're adding a new plugin, 
follow the checklist 👇 ====
   ### Add an agent plugin to support <framework name>
   - [ ] Add a test case for the new plugin, refer to [the 
doc](https://github.com/apache/skywalking-java/blob/main/docs/en/setup/service-agent/java-agent/Plugin-test.md)
   - [ ] Add a component id in [the 
component-libraries.yml](https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml)
   - [ ] Add a logo in [the UI 
repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets)
        ==== 🔌 Remove this line WHEN AND ONLY WHEN you're adding a new plugin, 
follow the checklist 👆 ==== -->
   
   <!-- ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the 
performance, follow the checklist 👇 ====
   ### Improve the performance of <class or module or ...>
   - [ ] Add a benchmark for the improvement, refer to [the existing 
ones](https://github.com/apache/skywalking-java/blob/main/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   - [ ] The benchmark result.
   ```text
   <Paste the benchmark results here>
   ```
   - [ ] Links/URLs to the theory proof or discussion articles/blogs. 
<links/URLs here>
        ==== 📈 Remove this line WHEN AND ONLY WHEN you're improving the 
performance, follow the checklist 👆 ==== -->
   
   <!-- ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, 
follow the checklist 👇 ====
   ### <Feature description>
   - [ ] If this is non-trivial feature, paste the links/URLs to the design doc.
   - [ ] Update the documentation to include this new feature.
   - [ ] Tests(including UT, IT, E2E) are added to verify the new feature.
   - [ ] If it's UI related, attach the screenshots below.
        ==== 🆕 Remove this line WHEN AND ONLY WHEN you're adding a new feature, 
follow the checklist 👆 ==== -->
   
   
   
   - [x] Update the [`CHANGES` 
log](https://github.com/apache/skywalking-java/blob/main/CHANGES.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to