From 1a7679bcee0554206213427498cdd5f63d3679f6 Mon Sep 17 00:00:00 2001 From: Dom Dwyer Date: Thu, 26 Jan 2023 16:18:00 +0100 Subject: [PATCH] refactor: expose underlying gRPC implementations Changes the gRPC delegate to return the underlying service (type erased) implementations instead of the RPC service wrappers. --- ioxd_router/src/lib.rs | 25 +++++++++++++++++++++---- router/src/server/grpc.rs | 34 +++++++++------------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/ioxd_router/src/lib.rs b/ioxd_router/src/lib.rs index 48624a07eb..76b106081e 100644 --- a/ioxd_router/src/lib.rs +++ b/ioxd_router/src/lib.rs @@ -7,7 +7,13 @@ use iox_catalog::interface::Catalog; use ioxd_common::{ add_service, http::error::{HttpApiError, HttpApiErrorSource}, - reexport::tonic::transport::Endpoint, + reexport::{ + generated_types::influxdata::iox::{ + catalog::v1::catalog_service_server, object_store::v1::object_store_service_server, + schema::v1::schema_service_server, + }, + tonic::transport::Endpoint, + }, rpc::RpcBuilderInput, serve_builder, server_type::{CommonServerState, RpcError, ServerType}, @@ -207,9 +213,20 @@ where /// [`RpcWriteGrpcDelegate`]: router::server::grpc::RpcWriteGrpcDelegate async fn server_grpc(self: Arc, builder_input: RpcBuilderInput) -> Result<(), RpcError> { let builder = setup_builder!(builder_input, self); - add_service!(builder, self.server.grpc().schema_service()); - add_service!(builder, self.server.grpc().catalog_service()); - add_service!(builder, self.server.grpc().object_store_service()); + add_service!( + builder, + schema_service_server::SchemaServiceServer::new(self.server.grpc().schema_service()) + ); + add_service!( + builder, + catalog_service_server::CatalogServiceServer::new(self.server.grpc().catalog_service()) + ); + add_service!( + builder, + object_store_service_server::ObjectStoreServiceServer::new( + self.server.grpc().object_store_service() + ) + ); serve_builder!(builder); Ok(()) diff --git a/router/src/server/grpc.rs b/router/src/server/grpc.rs index 273c516c08..66785eaef6 100644 --- a/router/src/server/grpc.rs +++ b/router/src/server/grpc.rs @@ -49,49 +49,33 @@ impl RpcWriteGrpcDelegate { /// Acquire a [`SchemaService`] gRPC service implementation. /// /// [`SchemaService`]: generated_types::influxdata::iox::schema::v1::schema_service_server::SchemaService. - pub fn schema_service(&self) -> schema_service_server::SchemaServiceServer { - schema_service_server::SchemaServiceServer::new(SchemaService::new(Arc::clone( - &self.catalog, - ))) + pub fn schema_service(&self) -> SchemaService { + SchemaService::new(Arc::clone(&self.catalog)) } /// Acquire a [`CatalogService`] gRPC service implementation. /// /// [`CatalogService`]: generated_types::influxdata::iox::catalog::v1::catalog_service_server::CatalogService. - pub fn catalog_service( - &self, - ) -> catalog_service_server::CatalogServiceServer - { - catalog_service_server::CatalogServiceServer::new(CatalogService::new(Arc::clone( - &self.catalog, - ))) + pub fn catalog_service(&self) -> impl catalog_service_server::CatalogService { + CatalogService::new(Arc::clone(&self.catalog)) } /// Acquire a [`ObjectStoreService`] gRPC service implementation. /// /// [`ObjectStoreService`]: generated_types::influxdata::iox::object_store::v1::object_store_service_server::ObjectStoreService. - pub fn object_store_service( - &self, - ) -> object_store_service_server::ObjectStoreServiceServer< - impl object_store_service_server::ObjectStoreService, - > { - object_store_service_server::ObjectStoreServiceServer::new(ObjectStoreService::new( - Arc::clone(&self.catalog), - Arc::clone(&self.object_store), - )) + pub fn object_store_service(&self) -> impl object_store_service_server::ObjectStoreService { + ObjectStoreService::new(Arc::clone(&self.catalog), Arc::clone(&self.object_store)) } /// Acquire a [`NamespaceService`] gRPC service implementation. /// /// [`NamespaceService`]: generated_types::influxdata::iox::namespace::v1::namespace_service_server::NamespaceService. - pub fn namespace_service( - &self, - ) -> namespace_service_server::NamespaceServiceServer { - namespace_service_server::NamespaceServiceServer::new(NamespaceService::new( + pub fn namespace_service(&self) -> impl namespace_service_server::NamespaceService { + NamespaceService::new( Arc::clone(&self.catalog), Some(self.topic_id), Some(self.query_id), - )) + ) } }