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

Enable grpc server reflection for all interfaces #132

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions databroker-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
&["proto"],
)
.unwrap();
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("kuksa.val.v1_descriptor.bin"))
.compile(
&[
"proto/kuksa/val/v1/val.proto",
"proto/kuksa/val/v1/types.proto",
],
&["proto"],
)
.unwrap();
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("sdv.databroker.v1_descriptor.bin"))
.compile(
&[
"proto/sdv/databroker/v1/broker.proto",
"proto/sdv/databroker/v1/types.proto",
"proto/sdv/databroker/v1/collector.proto",
],
&["proto"],
)
.unwrap();

Ok(())
}
4 changes: 4 additions & 0 deletions databroker-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
pub mod sdv {
pub mod databroker {
pub mod v1 {
pub const FILE_DESCRIPTOR_SET: &[u8] =
tonic::include_file_descriptor_set!("sdv.databroker.v1_descriptor");
tonic::include_proto!("sdv.databroker.v1");
}
}
Expand All @@ -24,6 +26,8 @@ pub mod sdv {
pub mod kuksa {
pub mod val {
pub mod v1 {
pub const FILE_DESCRIPTOR_SET: &[u8] =
tonic::include_file_descriptor_set!("kuksa.val.v1_descriptor");
tonic::include_proto!("kuksa.val.v1");

use datapoint::Value;
Expand Down
16 changes: 11 additions & 5 deletions databroker/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ where
}
};

let mut reflection_builder = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(kuksa::val::v1::FILE_DESCRIPTOR_SET);
let mut router = server.add_optional_service(kuksa_val_v1);

if apis.contains(&Api::KuksaValV2) {
let service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(kuksa::val::v2::FILE_DESCRIPTOR_SET)
.build()
.unwrap();
reflection_builder = reflection_builder
.register_encoded_file_descriptor_set(kuksa::val::v2::FILE_DESCRIPTOR_SET);

router = router.add_service(service).add_optional_service(Some(
router = router.add_optional_service(Some(
kuksa::val::v2::val_server::ValServer::with_interceptor(
broker.clone(),
authorization.clone(),
Expand All @@ -229,6 +229,9 @@ where
}

if apis.contains(&Api::SdvDatabrokerV1) {
reflection_builder = reflection_builder
.register_encoded_file_descriptor_set(sdv::databroker::v1::FILE_DESCRIPTOR_SET);

router = router.add_optional_service(Some(
sdv::databroker::v1::broker_server::BrokerServer::with_interceptor(
broker.clone(),
Expand All @@ -243,6 +246,9 @@ where
));
}

let reflection_service = reflection_builder.build().unwrap();
router = router.add_service(reflection_service);

router
.serve_with_incoming_shutdown(incoming, shutdown(broker, signal))
.await?;
Expand Down
Loading