xiangfu0 commented on code in PR #12389:
URL: https://github.com/apache/pinot/pull/12389#discussion_r1495134133


##########
pinot-broker/src/main/java/org/apache/pinot/broker/api/resources/PinotBrokerHealthCheck.java:
##########
@@ -79,4 +88,40 @@ public String getBrokerHealth() {
         
Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(errMessage).build();
     throw new WebApplicationException(errMessage, response);
   }
+
+  @GET
+  @Produces(MediaType.TEXT_PLAIN)
+  @Path("uptime")
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.GET_HEALTH)
+  @ApiOperation(value = "Get broker uptime")
+  public String getUptime() {
+    ServiceStatus.Status status = ServiceStatus.getServiceStatus(_instanceId);
+    if (status == ServiceStatus.Status.GOOD) {
+      _brokerMetrics.addMeteredGlobalValue(BrokerMeter.HEALTHCHECK_OK_CALLS, 
1);
+      Instant now = Instant.now();
+      Duration uptime = Duration.between(_startTime, now);
+      return "Uptime: " + uptime.getSeconds() + " seconds";
+    }
+    _brokerMetrics.addMeteredGlobalValue(BrokerMeter.HEALTHCHECK_BAD_CALLS, 1);
+    String errMessage = String.format("Cannot tell Pinot broker uptime. Pinot 
broker status is %s", status);
+    Response response =
+        
Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(errMessage).build();
+    throw new WebApplicationException(errMessage, response);
+  }
+
+  @GET
+  @Produces(MediaType.TEXT_PLAIN)
+  @Path("start-time")
+  @Authorize(targetType = TargetType.CLUSTER, action = 
Actions.Cluster.GET_HEALTH)
+  @ApiOperation(value = "Get broker start time")
+  public String getStartTime() {
+    ServiceStatus.Status status = ServiceStatus.getServiceStatus(_instanceId);
+    if (status == ServiceStatus.Status.GOOD) {
+      _brokerMetrics.addMeteredGlobalValue(BrokerMeter.HEALTHCHECK_OK_CALLS, 
1);
+    } else {
+      _brokerMetrics.addMeteredGlobalValue(BrokerMeter.HEALTHCHECK_BAD_CALLS, 
1);
+    }
+    String returnMessage = String.format("Pinot broker started at: %s. Pinot 
broker status is %s", _startTime, status);

Review Comment:
   just return _startTime epoch value is good



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