Skip to content

Add grpc_health to be able to check the service status #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ensembl-py >= 2.1.0
ensembl-utils >= 0.5.0
mysqlclient >= 1.4.6, < 2.3.0
grpcio
grpcio-health-checking
protobuf
grpcio-tools
grpcio-reflection
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ greenlet==3.0.3
grpcio==1.66.1
# via
# -r requirements.in
# grpcio-health-checking
# grpcio-reflection
# grpcio-tools
grpcio-health-checking==1.66.1
# via -r requirements.in
grpcio-reflection==1.66.1
# via -r requirements.in
grpcio-tools==1.66.1
Expand All @@ -38,6 +41,7 @@ pluggy==1.5.0
protobuf==5.28.0
# via
# -r requirements.in
# grpcio-health-checking
# grpcio-reflection
# grpcio-tools
pytest==8.3.3
Expand Down
19 changes: 19 additions & 0 deletions src/ensembl/production/metadata/grpc/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from concurrent import futures

import grpc
from grpc_health.v1 import health, health_pb2, health_pb2_grpc
from grpc_reflection.v1alpha import reflection

from ensembl.production.metadata.grpc import ensembl_metadata_pb2_grpc, ensembl_metadata_pb2
Expand All @@ -30,17 +31,35 @@ def serve():
level=log_level,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# Creating gRPC server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

# Registering Ensembl metadata service
ensembl_metadata_pb2_grpc.add_EnsemblMetadataServicer_to_server(
EnsemblMetadataServicer(), server
)

# Adding Health Check Service
health_servicer = health.HealthServicer()
health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server)

# Setting service health status to "SERVING"
health_servicer.set('', health_pb2.HealthCheckResponse.SERVING) # Global health check
health_servicer.set('EnsemblMetadata', health_pb2.HealthCheckResponse.SERVING)

# Enabling reflection
SERVICE_NAMES = (
ensembl_metadata_pb2.DESCRIPTOR.services_by_name['EnsemblMetadata'].full_name,
health_pb2.DESCRIPTOR.services_by_name['Health'].full_name,
reflection.SERVICE_NAME
)
reflection.enable_server_reflection(SERVICE_NAMES, server)

# Starting the server
server.add_insecure_port(f"[::]:{cfg.service_port}")
server.start()

try:
logger.info(f"Starting GRPC Server on {cfg.service_port} DEBUG: {cfg.debug_mode}")
server.wait_for_termination()
Expand Down