From 0c08e7dc2dd2529d00284a73c03d0efcffb578f7 Mon Sep 17 00:00:00 2001 From: Neng Wan Date: Mon, 21 Aug 2023 14:50:36 +0800 Subject: [PATCH 1/2] feat: enable grpc reflection --- requirements.txt | 1 + sea/server/multiprocessing.py | 3 +++ sea/server/threading.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/requirements.txt b/requirements.txt index 435170c..33aef38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ grpcio>=1.27.0,<1.49.0 grpcio-tools>=1.27.0,<1.49.0 +grpcio-reflection protobuf<4.0.0 pendulum blinker diff --git a/sea/server/multiprocessing.py b/sea/server/multiprocessing.py index 7d125f9..623cd62 100644 --- a/sea/server/multiprocessing.py +++ b/sea/server/multiprocessing.py @@ -45,6 +45,9 @@ def _run_server(self, bind_address): ], ) self.server = server # set server in slave process + if self.app.config.get("GRPC_REFLECTION", True): + from grpc_reflection.v1alpha import reflection + reflection.enable_server_reflection((reflection.SERVICE_NAME,), server) for _, (add_func, servicer) in self.app.servicers.items(): add_func(servicer(), server) diff --git a/sea/server/threading.py b/sea/server/threading.py index 820e070..bfeea43 100644 --- a/sea/server/threading.py +++ b/sea/server/threading.py @@ -28,6 +28,9 @@ def run(self): from prometheus_client import start_http_server start_http_server(self.app.config["PROMETHEUS_PORT"]) + if self.app.config.get("GRPC_REFLECTION", True): + from grpc_reflection.v1alpha import reflection + reflection.enable_server_reflection((reflection.SERVICE_NAME,), self.server) # run grpc server for name, (add_func, servicer) in self.app.servicers.items(): add_func(servicer(), self.server) From bf31059d6cb7f420f1829a42045b1f3fbe288419 Mon Sep 17 00:00:00 2001 From: Neng Wan Date: Mon, 21 Aug 2023 17:22:13 +0800 Subject: [PATCH 2/2] fix: register service names --- CHANGELOG.md | 6 ++++-- sea/server/multiprocessing.py | 7 ++++--- sea/server/threading.py | 7 ++++--- tests/wd/configs/default/__init__.py | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86ba007..83cedf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,15 @@ # CHANGELOG -## [Unreleased] - 2022-10-25 +## [Unreleased] - 2023-08-21 +### Added +- Support grpc reflection +## [3.1.0] - 2022-11-10 ### Changed - Upgrade depebdebcies to support python 3.10+ - Changed CI from Travis CI to Github Actions ## [3.0.0] - 2022-06-24 - ### Added - Added multiprocessing worker class ### Changed diff --git a/sea/server/multiprocessing.py b/sea/server/multiprocessing.py index 623cd62..7b491b3 100644 --- a/sea/server/multiprocessing.py +++ b/sea/server/multiprocessing.py @@ -9,6 +9,7 @@ from typing import List import grpc +from grpc_reflection.v1alpha import reflection from sea import signals @@ -45,9 +46,9 @@ def _run_server(self, bind_address): ], ) self.server = server # set server in slave process - if self.app.config.get("GRPC_REFLECTION", True): - from grpc_reflection.v1alpha import reflection - reflection.enable_server_reflection((reflection.SERVICE_NAME,), server) + # register reflection service + if self.app.config.get("GRPC_REFLECTION_SERVICES"): + reflection.enable_server_reflection((reflection.SERVICE_NAME, *self.app.config["GRPC_REFLECTION_SERVICES"]), self.server) for _, (add_func, servicer) in self.app.servicers.items(): add_func(servicer(), server) diff --git a/sea/server/threading.py b/sea/server/threading.py index bfeea43..4fa29b5 100644 --- a/sea/server/threading.py +++ b/sea/server/threading.py @@ -3,6 +3,7 @@ from concurrent import futures import grpc +from grpc_reflection.v1alpha import reflection from sea import signals @@ -28,9 +29,9 @@ def run(self): from prometheus_client import start_http_server start_http_server(self.app.config["PROMETHEUS_PORT"]) - if self.app.config.get("GRPC_REFLECTION", True): - from grpc_reflection.v1alpha import reflection - reflection.enable_server_reflection((reflection.SERVICE_NAME,), self.server) + # register reflection service + if self.app.config.get("GRPC_REFLECTION_SERVICES"): + reflection.enable_server_reflection((reflection.SERVICE_NAME, *self.app.config["GRPC_REFLECTION_SERVICES"]), self.server) # run grpc server for name, (add_func, servicer) in self.app.servicers.items(): add_func(servicer(), self.server) diff --git a/tests/wd/configs/default/__init__.py b/tests/wd/configs/default/__init__.py index f74b4f8..63f3d64 100644 --- a/tests/wd/configs/default/__init__.py +++ b/tests/wd/configs/default/__init__.py @@ -14,4 +14,5 @@ TIMEZONE = "Asia/Shanghai" GRPC_GRACE = 0 +GRPC_REFLECTION_SERVICES = ["helloworld.Greeter"] PROMETHEUS_SCRAPE = True