You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/11/01 18:03:31 UTC

[GitHub] sijie commented on a change in pull request #2883: Add healthcheck HTTP endpoint

sijie commented on a change in pull request #2883: Add healthcheck HTTP endpoint
URL: https://github.com/apache/pulsar/pull/2883#discussion_r230138671
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
 ##########
 @@ -196,4 +207,42 @@ public InternalConfigurationData getInternalConfigurationData() {
             conf.getZkLedgersRootPath());
     }
 
+    @GET
+    @Path("/health")
+    @ApiOperation(value = "Run a healthcheck against the broker")
+    @ApiResponses(value = { @ApiResponse(code = 200, message = "Everything is OK"),
+                            @ApiResponse(code = 403, message = "Don't have admin permission"),
+                            @ApiResponse(code = 404, message = "Cluster doesn't exist") })
+    public void healthcheck(@Suspended AsyncResponse asyncResponse) throws Exception {
+        validateSuperUserAccess();
+        pulsar().getExecutor().submit(() -> {
+                String heartbeatNamespace = NamespaceService.getHeartbeatNamespace(
+                        pulsar().getAdvertisedAddress(), pulsar().getConfiguration());
+                String topic = String.format("persistent://%s/healthcheck", heartbeatNamespace);
+                try {
+                    PulsarClient client = pulsar().getClient();
+
+                    try (Producer<String> producer = client.newProducer(Schema.STRING).topic(topic).create();
 
 Review comment:
   Can we rewrite this logic in async way? I know writing sync code is easy, but running blocking operations in pulsar executor is not a good practice. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services