Skip to content

Commit

Permalink
Health check, updates
Browse files Browse the repository at this point in the history
* Added the grpc_health module for basic health check functionality
* Updated to latest gprc libs
  • Loading branch information
joekottke committed Aug 18, 2019
1 parent c7d8efb commit 8724961
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
FROM python:3.7.4-alpine3.10
RUN apk add --no-cache build-base
RUN mkdir /app
WORKDIR /app
RUN apk add --no-cache curl
RUN curl -O -fssL https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.3.0/grpc_health_probe-linux-amd64 && \
mv grpc_health_probe-linux-amd64 /usr/local/bin/grpc_health_probe && \
chmod 755 /usr/local/bin/grpc_health_probe
COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt
RUN apk add --no-cache --virtual build-deps build-base && \
pip install --no-cache-dir -r requirements.txt && \
apk del build-deps
RUN apk add --no-cache libstdc++
COPY src/ /app/
RUN python -m grpc_tools.protoc \
-I. \
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
grpcio==1.21.1
grpcio-tools==1.21.1
grpcio==1.23.0
grpcio-health-checking==1.23.0
grpcio-tools==1.23.0
prometheus-client==0.7.1
protobuf==3.8.0
protobuf==3.9.1
six==1.12.0
11 changes: 10 additions & 1 deletion src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import namer

from grpc_health.v1 import health, health_pb2, health_pb2_grpc

request_metric = Summary(
'english_full_name_seconds',
'Time processing EnglishFullName requests')
Expand Down Expand Up @@ -71,6 +73,10 @@ def command_args():

def serve(args):
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

health_servicer = health.HealthServicer()
health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server)

namer_pb2_grpc.add_NamerServicer_to_server(Namer(), server)

ca_cert = None
Expand Down Expand Up @@ -99,11 +105,14 @@ def serve(args):

print('Starting server. Listening on port {}...'.format(args.port))
server.start()
health_servicer.set('', health_pb2.HealthCheckResponse.SERVING)
try:
while True:
time.sleep(86400)
except KeyboardInterrupt:
server.stop(0)
health_servicer.set('', health_pb2.HealthCheckResponse.NOT_SERVING)
time.sleep(10)
server.stop(1)


if __name__ == '__main__':
Expand Down

0 comments on commit 8724961

Please sign in to comment.