Skip to content

Commit

Permalink
added healthcheckregistry instead of rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-jalgaonkar committed Nov 15, 2024
1 parent d7735a5 commit 570621b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.flipkart.gjex.core.healthcheck;

import com.flipkart.gjex.core.filter.grpc.MethodFilters;
import io.dropwizard.metrics5.health.HealthCheck;
import io.grpc.health.v1.HealthCheckRequest;
import io.grpc.health.v1.HealthCheckResponse;
import io.grpc.health.v1.HealthGrpc;
import io.grpc.stub.StreamObserver;

import javax.inject.Named;
import javax.inject.Singleton;
import javax.servlet.ServletContext;
import javax.ws.rs.core.Context;
import java.util.SortedMap;

/**
* Default GRPC HealthCheck Service
Expand All @@ -18,6 +22,9 @@
@Named("GrpcHealthCheckService")
public class GrpcHealthCheckService extends HealthGrpc.HealthImplBase {

@Context
private ServletContext servletContext;

public GrpcHealthCheckService(){

}
Expand All @@ -27,7 +34,10 @@ public GrpcHealthCheckService(){
public void check(HealthCheckRequest request,
StreamObserver<HealthCheckResponse> responseObserver) {
HealthCheckResponse.Builder builder = HealthCheckResponse.newBuilder();
if (RotationManagementBasedHealthCheck.inRotation()) {
HealthCheckRegistry registry = (HealthCheckRegistry) servletContext
.getAttribute(HealthCheckRegistry.HEALTHCHECK_REGISTRY_NAME);
SortedMap<String, HealthCheck.Result> results = registry.runHealthChecks();
if (results.values().stream().anyMatch(result -> !result.isHealthy())){
builder.setStatus(HealthCheckResponse.ServingStatus.SERVING);
} else {
builder.setStatus(HealthCheckResponse.ServingStatus.NOT_SERVING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public class DashboardHealthCheckResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response performHealthChecks() {
HealthCheckRegistry registry = (HealthCheckRegistry) servletContext
.getAttribute(HealthCheckRegistry.HEALTHCHECK_REGISTRY_NAME);
SortedMap<String, HealthCheck.Result> results = registry.runHealthChecks();
return Response.status(Response.Status.OK).entity(results).build();
HealthCheckRegistry registry = (HealthCheckRegistry) servletContext
.getAttribute(HealthCheckRegistry.HEALTHCHECK_REGISTRY_NAME);
SortedMap<String, HealthCheck.Result> results = registry.runHealthChecks();
if (results.values().stream().anyMatch(result -> !result.isHealthy())){
return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(results).build();
}
return Response.status(Response.Status.OK).entity(results).build();
}

}

0 comments on commit 570621b

Please sign in to comment.