Skip to content

Commit

Permalink
♻️ dynamic-sidecar rpc interfce namespace is now tied to the node_id (#…
Browse files Browse the repository at this point in the history
…6614)

Co-authored-by: Andrei Neagu <[email protected]>
  • Loading branch information
GitHK and Andrei Neagu authored Oct 29, 2024
1 parent e3b3673 commit fc1e2a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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"
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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] = [
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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

0 comments on commit fc1e2a7

Please sign in to comment.