FrankChen021 commented on code in PR #19564:
URL: https://github.com/apache/druid/pull/19564#discussion_r3369495224


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/consul/ConsulClusterResource.java:
##########
@@ -106,6 +123,96 @@ protected GenericContainer<?> createContainer()
     }
   }
 
+  private void waitForConsulApi()
+  {
+    final long deadline = System.nanoTime() + READINESS_TIMEOUT.toNanos();
+    final HttpClient httpClient;
+    Exception lastException = null;
+
+    try {
+      httpClient = createHttpClient();
+    }
+    catch (Exception e) {
+      throw new RuntimeException("Failed to create Consul readiness client", 
e);
+    }
+
+    while (System.nanoTime() < deadline) {
+      try {
+        final HttpRequest request = 
HttpRequest.newBuilder(getHttpUri("/v1/status/leader"))
+                                               .timeout(Duration.ofSeconds(5))
+                                               .GET()
+                                               .build();
+        final HttpResponse<String> response = httpClient.send(request, 
HttpResponse.BodyHandlers.ofString());
+        if (response.statusCode() == 200 && response.body() != null && 
!response.body().trim().isEmpty()) {

Review Comment:
   [P2] Reject empty JSON leader before declaring Consul ready
   
   Consul's /v1/status/leader returns an empty JSON string while a server has 
not elected a leader. At this layer response.body().trim() is still not empty 
for that response, so this condition can treat a not-ready leader response as 
ready and start Druid during the same leader-election race this PR is trying to 
remove. Parse the JSON string or explicitly reject the empty JSON string before 
returning.



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