This is an automated email from the ASF dual-hosted git repository.
imbajin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new 7afce9daa fix(pd): populate memberSize in GET / endpoint response
(#3003)
7afce9daa is described below
commit 7afce9daa2ff99666d2f42d7103b7d60c3f9cfb4
Author: Çağlar Eker <[email protected]>
AuthorDate: Tue Apr 21 10:27:08 2026 +0300
fix(pd): populate memberSize in GET / endpoint response (#3003)
* 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
* fix(pd): relax storeSize assertion in PD-only test environment
---------
Co-authored-by: imbajin <[email protected]>
---
.../org/apache/hugegraph/pd/rest/IndexAPI.java | 32 +++++++++++++++++++++-
.../org/apache/hugegraph/pd/rest/RestApiTest.java | 19 +++++++++++++
.../apache/hugegraph/pd/service/RestApiTest.java | 18 ++++++++++++
3 files changed, 68 insertions(+), 1 deletion(-)
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 a0448965f..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,9 +66,35 @@ public class IndexAPI extends API {
BriefStatistics statistics = new BriefStatistics();
statistics.leader = RaftEngine.getInstance().getLeaderGrpcAddress();
statistics.state =
pdService.getStoreNodeService().getClusterStats().getState().toString();
+
+ // 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;
}
@@ -157,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..fb2b71d48 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,25 @@ 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";
+ // storeSize can be 0 in PD-only test environments with no store nodes
registered
+ assert obj.getInt("storeSize") >= 0;
+ }
+
@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..b899c0919 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,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(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";
+ // storeSize can be 0 in PD-only test environments with no store nodes
registered
+ assert obj.getInt("storeSize") >= 0;
+ }
+
@Test
public void testQueryClusterInfo() throws URISyntaxException, IOException,
InterruptedException,
JSONException {