Copilot commented on code in PR #3861:
URL: https://github.com/apache/hertzbeat/pull/3861#discussion_r2542364176


##########
hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/scheduler/CollectorJobScheduler.java:
##########
@@ -264,14 +262,14 @@ public boolean onlineCollector(String identity) {
             return false;
         }
         ServerInfo serverInfo = 
ServerInfo.builder().aesSecret(AesUtil.getDefaultSecretKey()).build();
-        ClusterMsg.Message message = ClusterMsg.Message.newBuilder()
-                .setType(ClusterMsg.MessageType.GO_ONLINE)
-                .setDirection(ClusterMsg.Direction.REQUEST)
-                .setMsg(ByteString.copyFromUtf8(JsonUtil.toJson(serverInfo)))
-                .setIdentity(identity)
+        ClusterMessage message = ClusterMessage.builder()
+                .type(ClusterMessage.MessageType.GO_ONLINE)
+                .direction(ClusterMessage.Direction.REQUEST)
+                .msg(JsonUtil.toJsonBytes(serverInfo))
+                .identity(identity)
                 .build();
-        ClusterMsg.Message response = this.manageServer.sendMsgSync(identity, 
message);
-        if (response == null || 
!String.valueOf(CommonConstants.SUCCESS_CODE).equals(response.getMsg().toStringUtf8()))
 {
+        ClusterMessage response = this.manageServer.sendMsgSync(identity, 
message);
+        if (response == null || 
!String.valueOf(CommonConstants.SUCCESS_CODE).equals(response.getMsg())) {

Review Comment:
   Type mismatch: comparing a String with byte[]. The `getMsg()` method returns 
`byte[]`, not String. Use `response.getMsgString()` instead, or convert the 
expected value to bytes for proper comparison.



##########
hertzbeat-remoting/src/test/java/org/apache/hertzbeat/remoting/RemotingServiceTest.java:
##########
@@ -120,40 +120,42 @@ public void testSendMsgSync() {
         final String requestMsg = "request";
         final String responseMsg = "response";
 
-        
this.remotingServer.registerProcessor(ClusterMsg.MessageType.HEARTBEAT, (ctx, 
message) -> {
-            Assertions.assertEquals(requestMsg, 
message.getMsg().toStringUtf8());
-            return ClusterMsg.Message.newBuilder()
-                    .setDirection(ClusterMsg.Direction.RESPONSE)
-                    .setMsg(ByteString.copyFromUtf8(responseMsg))
+        
this.remotingServer.registerProcessor(ClusterMessage.MessageType.HEARTBEAT, 
(ctx, message) -> {
+            Assertions.assertEquals(requestMsg, message.getMsgString());
+            return ClusterMessage.builder()
+                    .direction(ClusterMessage.Direction.RESPONSE)
+                    .type(ClusterMessage.MessageType.HEARTBEAT)
+                    .msg(responseMsg.getBytes(StandardCharsets.UTF_8))
                     .build();
         });
 
-        ClusterMsg.Message request = ClusterMsg.Message.newBuilder()
-                .setDirection(ClusterMsg.Direction.REQUEST)
-                .setType(ClusterMsg.MessageType.HEARTBEAT)
-                .setMsg(ByteString.copyFromUtf8(requestMsg))
+        ClusterMessage request = ClusterMessage.builder()
+                .direction(ClusterMessage.Direction.REQUEST)
+                .type(ClusterMessage.MessageType.HEARTBEAT)
+                .msg(requestMsg.getBytes(StandardCharsets.UTF_8))
                 .build();
-        ClusterMsg.Message response = this.remotingClient.sendMsgSync(request, 
3000);
-        Assertions.assertEquals(responseMsg, response.getMsg().toStringUtf8());
+        ClusterMessage response = this.remotingClient.sendMsgSync(request, 
3000);
+        Assertions.assertEquals(responseMsg, response.getMsgString());
     }
 
     @Test
     public void testNettyHook() {
         this.remotingServer.registerHook(Lists.newArrayList(
-                (ctx, message) -> Assertions.assertEquals("hello world", 
message.getMsg().toStringUtf8())
+                (ctx, message) -> Assertions.assertEquals("hello world", 
message.getMsg())

Review Comment:
   The assertion is comparing a String with byte[]. Since `getMsg()` returns 
`byte[]`, this comparison will always fail. Use `message.getMsgString()` 
instead to compare with the String value.



##########
hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/scheduler/netty/process/CollectCyclicServiceDiscoveryDataResponseProcessor.java:
##########
@@ -33,9 +34,9 @@
 @Slf4j
 public class CollectCyclicServiceDiscoveryDataResponseProcessor implements 
NettyRemotingProcessor {
     @Override
-    public ClusterMsg.Message handle(ChannelHandlerContext ctx, 
ClusterMsg.Message message) {
+    public ClusterMessage handle(ChannelHandlerContext ctx, ClusterMessage 
message) {
         CommonDataQueue dataQueue = 
SpringContextHolder.getBean(CommonDataQueue.class);
-        List<CollectRep.MetricsData> metricsDataList = 
ArrowUtil.deserializeMetricsData(message.getMsg().toByteArray());
+        List<CollectRep.MetricsData> metricsDataList = 
ArrowUtil.deserializeMetricsData(message.getMsgString().getBytes(StandardCharsets.UTF_8));

Review Comment:
   Inefficient conversion: converting byte[] to String and back to byte[]. 
Since `ArrowUtil.deserializeMetricsData` expects byte[] and `message.getMsg()` 
already returns byte[], use `message.getMsg()` directly instead of 
`message.getMsgString().getBytes(StandardCharsets.UTF_8)`.
   ```suggestion
           List<CollectRep.MetricsData> metricsDataList = 
ArrowUtil.deserializeMetricsData(message.getMsg());
   ```



##########
hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/scheduler/CollectorJobScheduler.java:
##########
@@ -243,13 +241,13 @@ public void reBalanceCollectorAssignJobs() {
 
     @Override
     public boolean offlineCollector(String identity) {
-        ClusterMsg.Message message = ClusterMsg.Message.newBuilder()
-                .setType(ClusterMsg.MessageType.GO_OFFLINE)
-                .setDirection(ClusterMsg.Direction.REQUEST)
-                .setIdentity(identity)
+        ClusterMessage message = ClusterMessage.builder()
+                .type(ClusterMessage.MessageType.GO_OFFLINE)
+                .direction(ClusterMessage.Direction.REQUEST)
+                .identity(identity)
                 .build();
-        ClusterMsg.Message response = this.manageServer.sendMsgSync(identity, 
message);
-        if (response == null || 
!String.valueOf(CommonConstants.SUCCESS_CODE).equals(response.getMsg().toStringUtf8()))
 {
+        ClusterMessage response = this.manageServer.sendMsgSync(identity, 
message);
+        if (response == null || 
!String.valueOf(CommonConstants.SUCCESS_CODE).equals(response.getMsg())) {

Review Comment:
   Type mismatch: comparing a String with byte[]. The `getMsg()` method returns 
`byte[]`, not String. Use `response.getMsgString()` instead, or convert the 
expected value to bytes for proper comparison.



##########
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/processor/GoOnlineProcessor.java:
##########
@@ -35,18 +33,19 @@
  */
 @Slf4j
 public class GoOnlineProcessor implements NettyRemotingProcessor {
-    
+
     private TimerDispatch timerDispatch;
-    
+
     @Override
-    public ClusterMsg.Message handle(ChannelHandlerContext ctx, 
ClusterMsg.Message message) {
+    public ClusterMessage handle(ChannelHandlerContext ctx, ClusterMessage 
message) {
         if (this.timerDispatch == null) {
             this.timerDispatch = 
SpringContextHolder.getBean(TimerDispatch.class);
         }
-        if (message.getMsg().isEmpty()) {
+        if (message.getMsg() == null || message.getMsgString().isEmpty()) {

Review Comment:
   Potential NullPointerException: `getMsgString()` can return null when `msg` 
is null (as seen in the implementation). Calling `.isEmpty()` on a null value 
will throw NPE. Check for null on `getMsgString()` result or use `getMsg() == 
null || getMsg().length == 0` instead.
   ```suggestion
           String msgString = message.getMsgString();
           if (message.getMsg() == null || msgString == null || 
msgString.isEmpty()) {
   ```



##########
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/processor/GoOfflineProcessor.java:
##########
@@ -36,20 +36,21 @@ public class GoOfflineProcessor implements 
NettyRemotingProcessor {
     private TimerDispatch timerDispatch;
     
     @Override
-    public ClusterMsg.Message handle(ChannelHandlerContext ctx, 
ClusterMsg.Message message) {
+    public ClusterMessage handle(ChannelHandlerContext ctx, ClusterMessage 
message) {
         if (this.timerDispatch == null) {
             this.timerDispatch = 
SpringContextHolder.getBean(TimerDispatch.class);
         }
         timerDispatch.goOffline();
         log.info("receive offline message and handle success");
-        if 
(message.getMsg().toStringUtf8().contains(CommonConstants.COLLECTOR_AUTH_FAILED))
 {
+        if 
(message.getMsgString().contains(CommonConstants.COLLECTOR_AUTH_FAILED)) {
             log.error("[Auth Failed]receive client auth failed message and go 
offline. {}", message.getMsg());

Review Comment:
   Logging byte[] directly will not produce readable output. Use 
`message.getMsgString()` for the log message to ensure proper string 
representation.
   ```suggestion
               log.error("[Auth Failed]receive client auth failed message and 
go offline. {}", message.getMsgString());
   ```



##########
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/entrance/processor/GoCloseProcessor.java:
##########
@@ -41,11 +41,11 @@ public GoCloseProcessor(final CollectServer collectServer) {
     }
 
     @Override
-    public ClusterMsg.Message handle(ChannelHandlerContext ctx, 
ClusterMsg.Message message) {
+    public ClusterMessage handle(ChannelHandlerContext ctx, ClusterMessage 
message) {
         if (this.timerDispatch == null) {
             this.timerDispatch = 
SpringContextHolder.getBean(TimerDispatch.class);
         }
-        if 
(message.getMsg().toStringUtf8().contains(CommonConstants.COLLECTOR_AUTH_FAILED))
 {
+        if 
(message.getMsgString().contains(CommonConstants.COLLECTOR_AUTH_FAILED)) {
             log.error("[Auth Failed]receive client auth failed message and go 
close. {}", message.getMsg());

Review Comment:
   Logging byte[] directly will not produce readable output. Use 
`message.getMsgString()` for the log message to ensure proper string 
representation.
   ```suggestion
               log.error("[Auth Failed]receive client auth failed message and 
go close. {}", message.getMsgString());
   ```



##########
material/licenses/backend/LICENSE:
##########
@@ -437,6 +437,7 @@ The text of each license is the standard Apache 2.0 license.
     https://mvnrepository.com/artifact/com.vesoft/client/3.6.0
     https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper/3.9.3 
Apache-2.0
     
https://mvnrepository.com/artifact/io.opentelemetry.proto/opentelemetry-proto/1.7.0-alpha
 Apache-2.0
+    https://mvnrepository.com/artifact/org.apache.fory/fory-core/0.13.1 
Apache-2.0

Review Comment:
   The artifact group ID is listed as 'org.apache.fory', but Apache Fury's 
actual group ID is 'org.apache.fury'. This should be corrected to match the 
actual Maven artifact.



##########
pom.xml:
##########
@@ -180,6 +180,7 @@
         <opentelemetry-starter.version>2.15.0</opentelemetry-starter.version>
         
<opentelemetry-logback.version>2.14.0-alpha</opentelemetry-logback.version>
         <opentelemetry-proto.version>1.3.1-alpha</opentelemetry-proto.version>
+        <fory.version>0.13.1</fory.version>

Review Comment:
   The property name 'fory.version' appears to be a typo. The library is 
'Apache Fury', not 'Fory'. Consider renaming to 'fury.version' for consistency 
with the actual library name.



##########
hertzbeat-common/pom.xml:
##########
@@ -183,6 +183,17 @@
             <version>${javaparser.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.fory</groupId>
+            <artifactId>fory-core</artifactId>
+            <version>${fory.version}</version>
+        </dependency>
+        <!-- row/arrow format support -->
+        <dependency>
+            <groupId>org.apache.fory</groupId>
+            <artifactId>fory-format</artifactId>

Review Comment:
   The Maven coordinates use 'org.apache.fory' and 'fory-core', but the correct 
Apache Fury artifact names are 'org.apache.fury' and 'fury-core'. These should 
be corrected to use the actual Maven Central artifact coordinates.
   ```suggestion
               <groupId>org.apache.fury</groupId>
               <artifactId>fury-core</artifactId>
               <version>${fory.version}</version>
           </dependency>
           <!-- row/arrow format support -->
           <dependency>
               <groupId>org.apache.fury</groupId>
               <artifactId>fury-format</artifactId>
   ```



##########
hertzbeat-remoting/src/main/java/org/apache/hertzbeat/remoting/netty/codec/ForyCodec.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.hertzbeat.remoting.netty.codec;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageCodec;
+import org.apache.fory.Fory;
+import org.apache.fory.ThreadSafeFory;
+import org.apache.fory.config.Language;
+import org.apache.hertzbeat.common.entity.message.ClusterMessage;
+
+import java.util.List;
+
+/**
+ * Netty codec for ClusterMessage using Apache fory

Review Comment:
   The comment refers to 'Apache fory' but the correct name is 'Apache Fury' 
(capitalized).



##########
hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/scheduler/CollectorJobScheduler.java:
##########
@@ -171,8 +170,7 @@ public void collectorGoOnline(String identity, 
CollectorInfo collectorInfo) {
                     }
                 });
                 appDefine.setConfigmap(configmaps);
-                long jobId = addAsyncCollectJob(appDefine, identity);
-                monitor.setJobId(jobId);
+                addAsyncCollectJob(appDefine, identity);

Review Comment:
   [nitpick] The return value of `addAsyncCollectJob` is no longer used. While 
this is intentional based on the diff context, consider documenting why the 
jobId is no longer needed or update the method signature to return void if the 
return value is never used.



##########
hertzbeat-common/pom.xml:
##########
@@ -183,6 +183,17 @@
             <version>${javaparser.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.fory</groupId>
+            <artifactId>fory-core</artifactId>
+            <version>${fory.version}</version>
+        </dependency>
+        <!-- row/arrow format support -->
+        <dependency>
+            <groupId>org.apache.fory</groupId>
+            <artifactId>fory-format</artifactId>
+            <version>${fory.version}</version>

Review Comment:
   The Maven coordinates use 'org.apache.fory' and 'fory-format', but the 
correct Apache Fury artifact names are 'org.apache.fury' and 'fury-format'. 
These should be corrected to use the actual Maven Central artifact coordinates.
   ```suggestion
               <groupId>org.apache.fury</groupId>
               <artifactId>fury-core</artifactId>
               <version>${fury.version}</version>
           </dependency>
           <!-- row/arrow format support -->
           <dependency>
               <groupId>org.apache.fury</groupId>
               <artifactId>fury-format</artifactId>
               <version>${fury.version}</version>
   ```



##########
hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/message/ClusterMessage.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.hertzbeat.common.entity.message;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.nio.charset.StandardCharsets;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * cluster message entity for fury serialization

Review Comment:
   The comment uses lowercase 'fury' when referring to the library name. It 
should be capitalized as 'Fury' for proper noun consistency.
   ```suggestion
    * cluster message entity for Fury serialization
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to