Skip to content

Commit

Permalink
linera-service: enable gRPC reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
Twey committed Mar 20, 2024
1 parent cca16ef commit ea2ec89
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ thiserror = "1.0.57"
tonic = { version = "0.11", default-features = false }
tonic-build = { version = "0.11", default-features = false }
tonic-health = "0.11"
tonic-reflection = "0.11"
tonic-web = "0.11"
tonic-web-wasm-client = "0.5.1"
tokio = "1.36.0"
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
kubectl

# for Wasm testing
chromium
chromedriver
wasm-pack
];
Expand Down
3 changes: 2 additions & 1 deletion linera-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ metrics = [
"linera-views/metrics",
]

server = ["tonic-health"]
server = ["tonic-health", "tonic-reflection"]
simple-network = ["tokio-util/net"]

web = [
Expand Down Expand Up @@ -65,6 +65,7 @@ thiserror.workspace = true
tokio.workspace = true
tokio-util = { workspace = true, optional = true, features = ["codec"] }
tonic-health = { workspace = true, optional = true }
tonic-reflection = { workspace = true, optional = true }
tower.workspace = true
tracing.workspace = true

Expand Down
3 changes: 3 additions & 0 deletions linera-rpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir: std::path::PathBuf = std::env::var("OUT_DIR")?.into();

let no_includes: &[&str] = &[];
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("file_descriptor_set.bin"))
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&["proto/rpc.proto"], no_includes)?;

Expand Down
4 changes: 4 additions & 0 deletions linera-rpc/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pub enum GrpcError {

#[error(transparent)]
InvalidUri(#[from] tonic::codegen::http::uri::InvalidUri),

#[cfg(with_server)]
#[error(transparent)]
Reflection(#[from] tonic_reflection::server::Error),
}

const MEBIBYTE: usize = 1024 * 1024;
Expand Down
5 changes: 5 additions & 0 deletions linera-rpc/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ where
.max_encoding_message_size(GRPC_MAX_MESSAGE_SIZE)
.max_decoding_message_size(GRPC_MAX_MESSAGE_SIZE);

let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(crate::FILE_DESCRIPTOR_SET)
.build()?;

let handle = tokio::spawn(
tonic::transport::Server::builder()
.layer(
Expand All @@ -260,6 +264,7 @@ where
.into_inner(),
)
.add_service(health_service)
.add_service(reflection_service)
.add_service(worker_node)
.serve_with_shutdown(server_address, receiver.map(|_| ())),
);
Expand Down
2 changes: 2 additions & 0 deletions linera-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ pub struct HandleCertificateRequest {
pub wait_for_outgoing_messages: bool,
pub blobs: Vec<linera_chain::data_types::HashedValue>,
}

pub const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("file_descriptor_set");
1 change: 1 addition & 0 deletions linera-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tokio-stream.workspace = true
toml.workspace = true
tonic = { workspace = true, features = ["transport", "tls", "tls-roots"] }
tonic-health.workspace = true
tonic-reflection.workspace = true
tonic-web.workspace = true
tower.workspace = true
tower-http = { workspace = true, features = ["cors"] }
Expand Down
5 changes: 5 additions & 0 deletions linera-service/src/grpc_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,19 @@ impl GrpcProxy {
let internal_server = Server::builder()
.add_service(tonic_web::enable(self.as_notifier_service()))
.serve(self.internal_address());
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(linera_rpc::FILE_DESCRIPTOR_SET)
.build()?;
let public_server = self
.public_server()?
.layer(
ServiceBuilder::new()
.layer(PrometheusMetricsMiddlewareLayer)
.into_inner(),
)
.accept_http1(true)
.add_service(health_service)
.add_service(reflection_service)
.add_service(self.as_validator_node())
.serve(self.public_address());

Expand Down

0 comments on commit ea2ec89

Please sign in to comment.