Build Proto and Swagger
cd ..
git clone https://gitlab.ixcloud.ch/ix.mercurius/common
cd common/proto
protoc -I. --go_out=plugins=grpc:${GOPATH}/src/ --grpc-gateway_out=logtostderr=true:${GOPATH}/src/ --swagger_out=logtostderr=true:. input-api.proto
# or using makefile
make generate
run Locally
make run
Healthcheck
This section describes, how the Healthcheck is implemented.
Local
To verify the local running instance the probe has to be installed and executed as shown below:
go get github.com/grpc-ecosystem/grpc-health-probe
$GOPATH/bin/grpc-health-probe -addr=localhost:8082
Configuration for application and Deployment
To make use of the Healthcheck some steps are needed. Attention: the golang section is configured to respond always positive.
# deployment yaml
readinessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:8082"]
initialDelaySeconds: 5
livenessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:8082"]
initialDelaySeconds: 10
# dockerfile
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
// main.go
package main
import (
health "google.golang.org/grpc/health/grpc_health_v1"
)
func main(){
health.RegisterHealthServer(server, new(AlertService))
}
func (s *AlertService) Check(ctx context.Context, in *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
return &health.HealthCheckResponse{Status: health.HealthCheckResponse_SERVING}, nil
}
func (s *AlertService) Watch(in *health.HealthCheckRequest, _ health.Health_WatchServer) error {
// Example of how to register both methods but only implement the Check method.
return status.Error(codes.Unimplemented, "unimplemented")
}