From 90502c844b25665fb66cd9fc64ca5f2235ea0a79 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Fri, 6 May 2022 11:41:16 -0400 Subject: [PATCH] refactor: Re-export crates used by the ioxd_common macros This allows the consumers of the macros to avoid including the dependencies themselves, which they otherwise wouldn't need to. --- Cargo.lock | 3 +++ ioxd_common/Cargo.toml | 11 +++++++---- ioxd_common/src/lib.rs | 12 ++++++++++++ ioxd_common/src/rpc.rs | 24 +++++++++++++++--------- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be04d5578a..6bbbee977d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2512,6 +2512,7 @@ dependencies = [ "dml", "flate2", "futures", + "generated_types", "hashbrown 0.12.0", "http", "hyper", @@ -2528,12 +2529,14 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "service_grpc_testing", "snafu", "tokio", "tokio-stream", "tokio-util 0.7.1", "tonic", "tonic-health", + "tonic-reflection", "tower", "trace", "trace_exporters", diff --git a/ioxd_common/Cargo.toml b/ioxd_common/Cargo.toml index ab9591a172..5ed68a3277 100644 --- a/ioxd_common/Cargo.toml +++ b/ioxd_common/Cargo.toml @@ -10,12 +10,14 @@ edition = "2021" clap_blocks = { path = "../clap_blocks" } data_types = { path = "../data_types" } dml = { path = "../dml" } +generated_types = { path = "../generated_types" } metric = { path = "../metric" } -observability_deps = { path = "../observability_deps" } -predicate = { path = "../predicate" } -pprof = { version = "0.8", default-features = false, features = ["flamegraph", "prost-codec"], optional = true } metric_exporters = { path = "../metric_exporters" } mutable_batch_lp = { path = "../mutable_batch_lp" } +observability_deps = { path = "../observability_deps" } +pprof = { version = "0.8", default-features = false, features = ["flamegraph", "prost-codec"], optional = true } +predicate = { path = "../predicate" } +service_grpc_testing = { path = "../service_grpc_testing" } trace = { path = "../trace" } trace_exporters = { path = "../trace_exporters" } trace_http = { path = "../trace_http" } @@ -39,10 +41,11 @@ serde_json = "1.0.81" serde_urlencoded = "0.7.0" snafu = "0.7" tokio = { version = "1.18", features = ["macros", "net", "parking_lot", "rt-multi-thread", "signal", "sync", "time"] } -tokio-util = { version = "0.7.0" } tokio-stream = { version = "0.1", features = ["net"] } +tokio-util = { version = "0.7.0" } tonic = "0.7" tonic-health = "0.6.0" +tonic-reflection = "0.4.0" tower = "0.4" workspace-hack = { path = "../workspace-hack"} diff --git a/ioxd_common/src/lib.rs b/ioxd_common/src/lib.rs index 503317f4c5..5a80a172ef 100644 --- a/ioxd_common/src/lib.rs +++ b/ioxd_common/src/lib.rs @@ -3,6 +3,18 @@ pub mod rpc; pub mod server_type; mod service; +// These crates are used by the macros we export; provide a stable +// path to use them from in downstream crates. +pub mod reexport { + pub use generated_types; + pub use service_grpc_testing; + pub use tokio_stream; + pub use tonic; + pub use tonic_health; + pub use tonic_reflection; + pub use trace_http; +} + pub use service::Service; use crate::server_type::{CommonServerState, ServerType}; diff --git a/ioxd_common/src/rpc.rs b/ioxd_common/src/rpc.rs index b3ed2e08ab..3afa80edaa 100644 --- a/ioxd_common/src/rpc.rs +++ b/ioxd_common/src/rpc.rs @@ -49,7 +49,7 @@ macro_rules! add_service { } = $builder; let service = $svc; - let status = tonic_health::ServingStatus::Serving; + let status = $crate::reexport::tonic_health::ServingStatus::Serving; health_reporter .set_service_status(service_name(&service), status) .await; @@ -75,7 +75,7 @@ macro_rules! add_service { macro_rules! setup_builder { ($input:ident, $server_type:ident) => {{ #[allow(unused_imports)] - use ioxd_common::{add_service, rpc::RpcBuilder, server_type::ServerType}; + use $crate::{add_service, rpc::RpcBuilder, server_type::ServerType}; let RpcBuilderInput { socket, @@ -83,14 +83,17 @@ macro_rules! setup_builder { shutdown, } = $input; - let (health_reporter, health_service) = tonic_health::server::health_reporter(); - let reflection_service = tonic_reflection::server::Builder::configure() - .register_encoded_file_descriptor_set(generated_types::FILE_DESCRIPTOR_SET) + let (health_reporter, health_service) = + $crate::reexport::tonic_health::server::health_reporter(); + let reflection_service = $crate::reexport::tonic_reflection::server::Builder::configure() + .register_encoded_file_descriptor_set( + $crate::reexport::generated_types::FILE_DESCRIPTOR_SET, + ) .build() .expect("gRPC reflection data broken"); - let builder = tonic::transport::Server::builder(); - let builder = builder.layer(trace_http::tower::TraceLayer::new( + let builder = $crate::reexport::tonic::transport::Server::builder(); + let builder = builder.layer($crate::reexport::trace_http::tower::TraceLayer::new( trace_header_parser, $server_type.metric_registry(), $server_type.trace_collector(), @@ -106,7 +109,10 @@ macro_rules! setup_builder { add_service!(builder, health_service); add_service!(builder, reflection_service); - add_service!(builder, service_grpc_testing::make_server()); + add_service!( + builder, + $crate::reexport::service_grpc_testing::make_server() + ); builder }}; @@ -116,7 +122,7 @@ macro_rules! setup_builder { #[macro_export] macro_rules! serve_builder { ($builder:ident) => {{ - use tokio_stream::wrappers::TcpListenerStream; + use $crate::reexport::tokio_stream::wrappers::TcpListenerStream; use $crate::rpc::RpcBuilder; let RpcBuilder {