From fc1e2a7952581cd7de2942df902b1fd35092b274 Mon Sep 17 00:00:00 2001 From: Andrei Neagu <5694077+GitHK@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:18:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20dynamic-sidecar=20rpc=20in?= =?UTF-8?q?terfce=20namespace=20is=20now=20tied=20to=20the=20node=5Fid=20(?= =?UTF-8?q?#6614)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrei Neagu --- .../api_schemas_dynamic_sidecar/__init__.py | 9 --------- .../rpc_interfaces/dynamic_sidecar/disk_usage.py | 16 ++++++++++------ .../api/rpc/routes.py | 10 ++++++++-- .../tests/unit/test_api_rpc__disk_usage.py | 6 +++++- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/models-library/src/models_library/api_schemas_dynamic_sidecar/__init__.py b/packages/models-library/src/models_library/api_schemas_dynamic_sidecar/__init__.py index 705c568225e..e69de29bb2d 100644 --- a/packages/models-library/src/models_library/api_schemas_dynamic_sidecar/__init__.py +++ b/packages/models-library/src/models_library/api_schemas_dynamic_sidecar/__init__.py @@ -1,9 +0,0 @@ -from typing import Final - -from pydantic import parse_obj_as - -from ..rabbitmq_basic_types import RPCNamespace - -DYNAMIC_SIDECAR_RPC_NAMESPACE: Final[RPCNamespace] = parse_obj_as( - RPCNamespace, "dynamic-sidecar" -) diff --git a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py index e8a23316e26..5938ad871ff 100644 --- a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py +++ b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/disk_usage.py @@ -1,8 +1,8 @@ import logging -from models_library.api_schemas_dynamic_sidecar import DYNAMIC_SIDECAR_RPC_NAMESPACE from models_library.api_schemas_dynamic_sidecar.telemetry import DiskUsage -from models_library.rabbitmq_basic_types import RPCMethodName +from models_library.projects_nodes_io import NodeID +from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace from pydantic import parse_obj_as from servicelib.logging_utils import log_decorator from servicelib.rabbitmq import RabbitMQRPCClient @@ -12,11 +12,15 @@ @log_decorator(_logger, level=logging.DEBUG) async def update_disk_usage( - rabbitmq_rpc_client: RabbitMQRPCClient, *, usage: dict[str, DiskUsage] + rabbitmq_rpc_client: RabbitMQRPCClient, + *, + node_id: NodeID, + usage: dict[str, DiskUsage], ) -> None: + rpc_namespace = RPCNamespace.from_entries( + {"service": "dy-sidecar", "node_id": f"{node_id}"} + ) result = await rabbitmq_rpc_client.request( - DYNAMIC_SIDECAR_RPC_NAMESPACE, - parse_obj_as(RPCMethodName, "update_disk_usage"), - usage=usage, + rpc_namespace, parse_obj_as(RPCMethodName, "update_disk_usage"), usage=usage ) assert result is None # nosec diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rpc/routes.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rpc/routes.py index 2772c9d863c..d1c0b0c2a1e 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rpc/routes.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/api/rpc/routes.py @@ -1,8 +1,9 @@ from fastapi import FastAPI -from models_library.api_schemas_dynamic_sidecar import DYNAMIC_SIDECAR_RPC_NAMESPACE +from models_library.rabbitmq_basic_types import RPCNamespace from servicelib.rabbitmq import RPCRouter from ...core.rabbitmq import get_rabbitmq_rpc_server +from ...core.settings import ApplicationSettings from . import _disk_usage ROUTERS: list[RPCRouter] = [ @@ -13,7 +14,12 @@ def setup_rpc_api_routes(app: FastAPI) -> None: async def startup() -> None: rpc_server = get_rabbitmq_rpc_server(app) + settings: ApplicationSettings = app.state.settings + + rpc_namespace = RPCNamespace.from_entries( + {"service": "dy-sidecar", "node_id": f"{settings.DY_SIDECAR_NODE_ID}"} + ) for router in ROUTERS: - await rpc_server.register_router(router, DYNAMIC_SIDECAR_RPC_NAMESPACE, app) + await rpc_server.register_router(router, rpc_namespace, app) app.add_event_handler("startup", startup) diff --git a/services/dynamic-sidecar/tests/unit/test_api_rpc__disk_usage.py b/services/dynamic-sidecar/tests/unit/test_api_rpc__disk_usage.py index cda0964a3b3..1383f165416 100644 --- a/services/dynamic-sidecar/tests/unit/test_api_rpc__disk_usage.py +++ b/services/dynamic-sidecar/tests/unit/test_api_rpc__disk_usage.py @@ -17,6 +17,7 @@ from settings_library.rabbit import RabbitSettings from settings_library.redis import RedisSettings from simcore_service_dynamic_sidecar.core.application import create_app +from simcore_service_dynamic_sidecar.core.settings import ApplicationSettings from simcore_service_dynamic_sidecar.modules.system_monitor._disk_usage import ( get_disk_usage_monitor, ) @@ -69,8 +70,11 @@ async def test_get_state(app: FastAPI, rpc_client: RabbitMQRPCClient): total=ByteSize(0), used=ByteSize(0), free=ByteSize(0), used_percent=0 ) } + settings: ApplicationSettings = app.state.settings - result = await disk_usage.update_disk_usage(rpc_client, usage=usage) + result = await disk_usage.update_disk_usage( + rpc_client, node_id=settings.DY_SIDECAR_NODE_ID, usage=usage + ) assert result is None assert get_disk_usage_monitor(app)._usage_overwrite == usage # noqa: SLF001