diff --git a/src/py/flwr/client/grpc_rere_client/grpc_adapter.py b/src/py/flwr/client/grpc_rere_client/grpc_adapter.py index 3dce14c14956..69ea29d5b7b3 100644 --- a/src/py/flwr/client/grpc_rere_client/grpc_adapter.py +++ b/src/py/flwr/client/grpc_rere_client/grpc_adapter.py @@ -24,10 +24,14 @@ from flwr.common import log from flwr.common.constant import ( + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY, + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY, GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY, + GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY, + GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY, GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY, ) -from flwr.common.version import package_version +from flwr.common.version import package_name, package_version from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611 from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611 CreateNodeRequest, @@ -62,9 +66,16 @@ def _send_and_receive( self, request: GrpcMessage, response_type: type[T], **kwargs: Any ) -> T: # Serialize request + req_cls = request.__class__ container_req = MessageContainer( - metadata={GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY: package_version}, - grpc_message_name=request.__class__.__qualname__, + metadata={ + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY: package_name, + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY: package_version, + GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY: package_version, + GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY: req_cls.__module__, + GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY: req_cls.__qualname__, + }, + grpc_message_name=req_cls.__qualname__, grpc_message_content=request.SerializeToString(), ) diff --git a/src/py/flwr/common/constant.py b/src/py/flwr/common/constant.py index eabe324f41c5..ffd58478aa48 100644 --- a/src/py/flwr/common/constant.py +++ b/src/py/flwr/common/constant.py @@ -60,8 +60,6 @@ # IDs RUN_ID_NUM_BYTES = 8 NODE_ID_NUM_BYTES = 8 -GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY = "flower-version" -GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY = "should-exit" # Constants for FAB APP_DIR = "apps" @@ -72,8 +70,13 @@ PARTITION_ID_KEY = "partition-id" NUM_PARTITIONS_KEY = "num-partitions" -GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY = "flower-version" +# Constants for keys in `metadata` of `MessageContainer` in `grpc-adapter` +GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY = "flower-package-name" +GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY = "flower-package-version" +GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY = "flower-version" # Deprecated GRPC_ADAPTER_METADATA_SHOULD_EXIT_KEY = "should-exit" +GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY = "grpc-message-module" +GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY = "grpc-message-qualname" class MessageType: diff --git a/src/py/flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py b/src/py/flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py index dbfbb236a7e4..75aa6d370511 100644 --- a/src/py/flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +++ b/src/py/flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py @@ -21,7 +21,15 @@ import grpc from google.protobuf.message import Message as GrpcMessage +from flwr.common.constant import ( + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY, + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY, + GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY, + GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY, + GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY, +) from flwr.common.logger import log +from flwr.common.version import package_name, package_version from flwr.proto import grpcadapter_pb2_grpc # pylint: disable=E0611 from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611 from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611 @@ -52,9 +60,16 @@ def _handle( ) -> MessageContainer: req = request_type.FromString(msg_container.grpc_message_content) res = handler(req) + res_cls = res.__class__ return MessageContainer( - metadata={}, - grpc_message_name=res.__class__.__qualname__, + metadata={ + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_NAME_KEY: package_name, + GRPC_ADAPTER_METADATA_FLOWER_PACKAGE_VERSION_KEY: package_version, + GRPC_ADAPTER_METADATA_FLOWER_VERSION_KEY: package_version, + GRPC_ADAPTER_METADATA_MESSAGE_MODULE_KEY: res_cls.__module__, + GRPC_ADAPTER_METADATA_MESSAGE_QUALNAME_KEY: res_cls.__qualname__, + }, + grpc_message_name=res_cls.__qualname__, grpc_message_content=res.SerializeToString(), )