From 5c84f6e90e7ef8a37844c16f189a027f5df3bc50 Mon Sep 17 00:00:00 2001 From: Rui Hu Date: Tue, 8 Jul 2025 17:47:07 +0800 Subject: [PATCH] fix(General): fix for cm-dev deployment --- amqp/adapter/cleverthis_service_adapter.py | 3 +++ amqp/service/amq_message_handler.py | 10 ++-------- demo.py | 5 +++-- otdemo/otdemo.properties | 5 ++++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/amqp/adapter/cleverthis_service_adapter.py b/amqp/adapter/cleverthis_service_adapter.py index 3e4c66b..a9c370f 100644 --- a/amqp/adapter/cleverthis_service_adapter.py +++ b/amqp/adapter/cleverthis_service_adapter.py @@ -491,6 +491,9 @@ class CleverThisServiceAdapter: _routes = self.routes.get(method, []) _path, _args = AMQDataParser.parse_get_url(message.path()) for _route in _routes: + # TODO: here the regex will match with path prefix, + # but it might not be a stable feature that we could rely on. + # Need to figure out something stable for the prefix path. _match = _route.path_regex.match(_path) if _match: _args.update(_match.groupdict()) diff --git a/amqp/service/amq_message_handler.py b/amqp/service/amq_message_handler.py index 790a330..b30429c 100644 --- a/amqp/service/amq_message_handler.py +++ b/amqp/service/amq_message_handler.py @@ -125,10 +125,7 @@ class DataMessageHandler: """ # Increment the counter for parallel executions and check resource availability self.backpressure_handler.increase_parallel_executions() - await self.backpressure_handler.check_resource_availability( - self.backpressure_handler.current_parallel_executions, - self.backpressure_handler.parallel_workers, - ) + await self.backpressure_handler.check_overload_condition() logging_info( f"PARALLEL: Current Capacity [{self.backpressure_handler.current_parallel_executions}] of [{self.backpressure_handler.parallel_workers}]" ) @@ -159,10 +156,7 @@ class DataMessageHandler: logging_error(f"Request handler: {e}") self.backpressure_handler.decrease_parallel_executions() - await self.backpressure_handler.check_resource_availability( - self.backpressure_handler.current_parallel_executions, - self.backpressure_handler.parallel_workers, - ) + await self.backpressure_handler.check_overload_condition() async def reconstitute_data_message( self, message: AbstractIncomingMessage diff --git a/demo.py b/demo.py index 0bd10be..42ae999 100644 --- a/demo.py +++ b/demo.py @@ -94,6 +94,7 @@ internal_api_call_duration_histogram = meter.create_histogram( app = FastAPI( title="CleverMicro Document Service Demo", description="A FastAPI application demonstrating OpenTelemetry integration with Jaeger and Prometheus.", + # root_path="/otdemo", # This won't affect router path ) # Instrument FastAPI: Automatically creates spans for incoming requests @@ -105,8 +106,6 @@ HTTPXClientInstrumentor().instrument() UPLOAD_DIR = "/tmp/clevermicro_documents" os.makedirs(UPLOAD_DIR, exist_ok=True) -otadapter = OTDemoAmqpAdapter(AMQConfiguration("otdemo/otdemo.properties"), app.routes) - @app.post("/api/v3/documents") async def upload_document( @@ -223,6 +222,8 @@ async def get_documents(): return {"documents": documents} +# Need to place below all route methods, otherwise the routes are incomplete +otadapter = OTDemoAmqpAdapter(AMQConfiguration("otdemo/otdemo.properties"), app.routes) # --- How to Run the Demo --- # 1. Save the code: # Save the Python code above as `main.py` in a new directory. diff --git a/otdemo/otdemo.properties b/otdemo/otdemo.properties index 5fb0120..0b65f97 100644 --- a/otdemo/otdemo.properties +++ b/otdemo/otdemo.properties @@ -11,7 +11,10 @@ cm.amq-adapter.generator-id=1 # Route mapping. For route detail description see section 3.1 in Onboarding Guide for Python: # https://docs.cleverthis.com/en/architecture/microservices/onboarding/python # NOTE: this is a comma-separated list of route mappings (multiple, comma-separated routes are allowed here) -cm.amq-adapter.route-mapping=otdemo::otdemo:otdemo.localhost.#:5:0 +# cm-dev route +cm.amq-adapter.route-mapping=otdemo::otdemo:api.cm.dev.cleverthis.com.test-python.#:5:0 +# local route +#cm.amq-adapter.route-mapping=otdemo::otdemo:api.dev.localhost.otdemo.#:5:0 # Indicate if AMQ Adapter should respond with HTTP 401 Unauthorized if the request does not contain valid JWT token cm.amq-adapter.require-authenticated-user=false