-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added grpc healthcheck by default (#67)
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/src/main/java/com/flipkart/gjex/core/healthcheck/GrpcHealthCheckService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.flipkart.gjex.core.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.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
/** | ||
* Default GRPC HealthCheck Service | ||
* @author ajay.jalgaonkar | ||
*/ | ||
|
||
@Singleton | ||
@Named("GrpcHealthCheckService") | ||
public class GrpcHealthCheckService extends HealthGrpc.HealthImplBase { | ||
private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck; | ||
|
||
@Inject | ||
public GrpcHealthCheckService(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck){ | ||
this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck; | ||
} | ||
|
||
@Override | ||
public void check(HealthCheckRequest request, | ||
StreamObserver<HealthCheckResponse> responseObserver) { | ||
HealthCheckResponse.Builder builder = HealthCheckResponse.newBuilder(); | ||
if (rotationManagementBasedHealthCheck.inRotation()) { | ||
builder.setStatus(HealthCheckResponse.ServingStatus.SERVING); | ||
} else { | ||
builder.setStatus(HealthCheckResponse.ServingStatus.NOT_SERVING); | ||
} | ||
responseObserver.onNext(builder.build()); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters