Skip to content

Commit

Permalink
add health check queryParam for servers (#9129)
Browse files Browse the repository at this point in the history
* also add query param to the health endpoint

* address diff comment

Co-authored-by: Rong Rong <rongr@startree.ai>
  • Loading branch information
walterddr and Rong Rong authored Jul 30, 2022
1 parent 91289be commit 7197461
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -54,8 +56,13 @@ public class HealthCheckResource {
@ApiResponse(code = 200, message = "Server is healthy"),
@ApiResponse(code = 503, message = "Server is not healthy")
})
public String checkHealth() {
return getReadinessStatus(_instanceId);
public String checkHealth(
@ApiParam(value = "health check type: liveness or readiness") @QueryParam("checkType") String checkType) {
if ("liveness".equalsIgnoreCase(checkType)) {
return "OK";
} else {
return getReadinessStatus(_instanceId);
}
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ public void checkHealthProbes()
Assert.assertEquals(_webTarget.path(livenessPath).request().get(Response.class).getStatus(), 200);
Assert.assertEquals(_webTarget.path(healthPath).request().get(Response.class).getStatus(), 503);
Assert.assertEquals(_webTarget.path(readinessPath).request().get(Response.class).getStatus(), 503);
Assert.assertEquals(_webTarget.path(healthPath).queryParam("checkType", "readiness")
.request().get(Response.class).getStatus(), 503);
Assert.assertEquals(_webTarget.path(healthPath).queryParam("checkType", "liveness")
.request().get(Response.class).getStatus(), 200);
}
}

0 comments on commit 7197461

Please sign in to comment.