Copilot commented on code in PR #342:
URL: https://github.com/apache/hugegraph-ai/pull/342#discussion_r3345966103


##########
hugegraph-python-client/src/tests/api/test_metric.py:
##########
@@ -74,10 +109,48 @@ def test_metrics_operations(self):
         self.assertIsInstance(statistics, dict)
 
         backend_metrics = self.metrics.get_backend_metrics()
-        # In HugeGraph 1.7.0+, the backend_metrics structure changed
-        # It's still a dict, but the "hugegraph" key may not exist in the same 
format
-        self.assertIsInstance(backend_metrics, dict)
-        self.assertTrue(backend_metrics, "backend metrics should not be empty")
-        # Only assert on the "hugegraph" key if it exists (for backward 
compatibility)
-        if "hugegraph" in backend_metrics:
-            self.assertGreater(len(backend_metrics["hugegraph"]), 1)
+
+        # HugeGraph 1.7.0 backend_metrics shape (top-level key may be 
"<cluster>-<graph>"):
+        # { "<cluster>-<graph>": { "backend": str, "nodes": int, "cluster_id": 
str,
+        #                          "servers": { "<server_name>": { <metrics> } 
} } }
+        self.assertIsInstance(backend_metrics, dict, "backend_metrics should 
be a dict")
+        self.assertTrue(backend_metrics, "backend_metrics should not be empty")
+
+        # Select the graph entry deterministically using the configured graph 
name
+        graph_name = ClientUtils.GRAPH
+        graph_key = next(
+            (k for k in backend_metrics if graph_name in k),
+            None,
+        )

Review Comment:
   Graph selection is not actually deterministic: it uses the ClientUtils.GRAPH 
*class* constant (always "hugegraph"), ignoring the graph name that may be 
configured via env vars/service in the ClientUtils instance. Also, `if 
graph_name in k` can match multiple keys (or the wrong key) when the cluster 
prefix contains the graph substring, making the chosen entry dependent on dict 
insertion order.



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