Skip to content
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

♻️ dynamic-sidecar rpc interfce namespace is now tied to the node_id #6614

Merged
Merged
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
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(
GitHK marked this conversation as resolved.
Show resolved Hide resolved
{"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)
GitHK marked this conversation as resolved.
Show resolved Hide resolved

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
Loading