This is an automated email from the ASF dual-hosted git repository.

imbajin pushed a commit to branch pr/3003
in repository https://gitbox.apache.org/repos/asf/hugegraph.git

commit fdb114a08607061308a0514f785ed1fe8be91c98
Author: imbajin <[email protected]>
AuthorDate: Mon Apr 20 21:13:39 2026 +0800

    fix(pd): complete GET / stats fix and add test coverage
    
    - Use pdService.getMembers() for memberSize (consistent with cluster())
      instead of RaftEngine directly, as suggested in issue #3002 discussion
    - Add dataState field to BriefStatistics: exposes worst partition health
      state across all graphs, the most useful missing operational indicator
    - Align graphSize to count only user-facing graphs (endsWith("/g")),
      matching the semantics of cluster() to avoid silent count discrepancy
    - Add testQueryIndexInfo() to both RestApiTest classes to assert state,
      leader, memberSize > 0, and storeSize > 0 — catches this class of bug
    
    Closes #3002
---
 .../org/apache/hugegraph/pd/rest/IndexAPI.java     | 33 ++++++++++++++++++++--
 .../org/apache/hugegraph/pd/rest/RestApiTest.java  | 18 ++++++++++++
 .../apache/hugegraph/pd/service/RestApiTest.java   | 17 +++++++++++
 3 files changed, 66 insertions(+), 2 deletions(-)

diff --git 
a/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/IndexAPI.java
 
b/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/IndexAPI.java
index c5ce282c4..bee39f23e 100644
--- 
a/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/IndexAPI.java
+++ 
b/hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/IndexAPI.java
@@ -66,10 +66,35 @@ public class IndexAPI extends API {
         BriefStatistics statistics = new BriefStatistics();
         statistics.leader = RaftEngine.getInstance().getLeaderGrpcAddress();
         statistics.state = 
pdService.getStoreNodeService().getClusterStats().getState().toString();
-        statistics.memberSize = RaftEngine.getInstance().getMembers().size();
+
+        // Use pdService (consistent with cluster()) rather than RaftEngine 
directly
+        CallStreamObserverWrap<Pdpb.GetMembersResponse> membersResp =
+                new CallStreamObserverWrap<>();
+        pdService.getMembers(Pdpb.GetMembersRequest.newBuilder().build(), 
membersResp);
+        statistics.memberSize = 
membersResp.get().get(0).getMembersList().size();
+
         statistics.storeSize = 
pdService.getStoreNodeService().getActiveStores().size();
-        statistics.graphSize = 
pdService.getPartitionService().getGraphs().size();
+        // Filter to user-facing graphs only (consistent with cluster())
+        List<Metapb.Graph> graphs = pdRestService.getGraphs();
+        statistics.graphSize = (int) graphs.stream()
+                                           .filter(g -> g.getGraphName() != 
null &&
+                                                        
g.getGraphName().endsWith("/g"))
+                                           .count();
         statistics.partitionSize = 
pdService.getStoreNodeService().getShardGroups().size();
+
+        // Derive worst partition health state across all graphs
+        Metapb.PartitionState dataState = Metapb.PartitionState.PState_Normal;
+        for (Metapb.Graph graph : graphs) {
+            if (graph.getState() == Metapb.PartitionState.UNRECOGNIZED) {
+                continue;
+            }
+            if (graph.getState() != null &&
+                graph.getState().getNumber() > dataState.getNumber()) {
+                dataState = graph.getState();
+            }
+        }
+        statistics.dataState = dataState.name();
+
         return statistics;
 
     }
@@ -158,9 +183,13 @@ public class IndexAPI extends API {
     class BriefStatistics {
 
         String state;
+        /** Worst partition health state across all graphs (mirrors 
cluster().dataState) */
+        String dataState;
         String leader;
         int memberSize;
+        /** Active (online) store count only */
         int storeSize;
+        /** User-facing graphs count (graphName ending with /g) */
         int graphSize;
         int partitionSize;
     }
diff --git 
a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
 
b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
index 2d6f4f054..86846f218 100644
--- 
a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
+++ 
b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
@@ -29,6 +29,24 @@ import org.junit.Test;
 
 public class RestApiTest extends BaseServerTest {
 
+    @Test
+    public void testQueryIndexInfo() throws URISyntaxException, IOException, 
InterruptedException,
+                                            JSONException {
+        String url = pdRestAddr + "/";
+        HttpRequest request = HttpRequest.newBuilder()
+                                         .uri(new URI(url))
+                                         .header("Authorization", "Basic 
c3RvcmU6MTIz")
+                                         .GET()
+                                         .build();
+        HttpResponse<String> response = client.send(request, 
HttpResponse.BodyHandlers.ofString());
+        assert response.statusCode() == 200;
+        JSONObject obj = new JSONObject(response.body());
+        assert obj.getString("state") != null;
+        assert obj.getString("leader") != null;
+        assert obj.getInt("memberSize") > 0 : "memberSize should be > 0 for a 
running cluster";
+        assert obj.getInt("storeSize") > 0 : "storeSize should be > 0 for a 
running cluster";
+    }
+
     @Test
     public void testQueryClusterInfo() throws URISyntaxException, IOException, 
InterruptedException,
                                               JSONException {
diff --git 
a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java
 
b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java
index d4c9cd121..c1dcd26f1 100644
--- 
a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java
+++ 
b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java
@@ -29,6 +29,23 @@ import org.junit.Test;
 
 public class RestApiTest extends BaseServerTest {
 
+    @Test
+    public void testQueryIndexInfo() throws URISyntaxException, IOException, 
InterruptedException,
+                                            JSONException {
+        String url = pdRestAddr + "/";
+        HttpRequest request = HttpRequest.newBuilder()
+                                         .uri(new URI(url)).header(key, value)
+                                         .GET()
+                                         .build();
+        HttpResponse<String> response = client.send(request, 
HttpResponse.BodyHandlers.ofString());
+        assert response.statusCode() == 200;
+        JSONObject obj = new JSONObject(response.body());
+        assert obj.getString("state") != null;
+        assert obj.getString("leader") != null;
+        assert obj.getInt("memberSize") > 0 : "memberSize should be > 0 for a 
running cluster";
+        assert obj.getInt("storeSize") > 0 : "storeSize should be > 0 for a 
running cluster";
+    }
+
     @Test
     public void testQueryClusterInfo() throws URISyntaxException, IOException, 
InterruptedException,
                                               JSONException {

Reply via email to