Skip to content

Commit

Permalink
Improve gRPC transport error logging (#4744)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilload authored Mar 15, 2024
1 parent c8e6ec6 commit 6fdb4ed
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 65 deletions.
21 changes: 17 additions & 4 deletions quickwit/quickwit-codegen/example/src/codegen/hello.rs

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

2 changes: 2 additions & 0 deletions quickwit/quickwit-codegen/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ mod tests {

#[tokio::test]
async fn test_transport_errors_handling() {
quickwit_common::setup_logging_for_tests();

let addr: SocketAddr = "127.0.0.1:9999".parse().unwrap();
let channel = Endpoint::from_static("http://127.0.0.1:9999")
.timeout(Duration::from_millis(100))
Expand Down
15 changes: 13 additions & 2 deletions quickwit/quickwit-codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ impl SynMethod {
}
}

fn rpc_name(&self, mock: bool) -> TokenStream {
let request_type = &self.request_type;

if mock {
quote! { super::#request_type::rpc_name() }
} else {
quote! { #request_type::rpc_name() }
}
}

fn response_type(&self, context: &CodegenContext, mock: bool) -> TokenStream {
let response_type = if mock {
let response_type = &self.response_type;
Expand Down Expand Up @@ -1158,14 +1168,15 @@ fn generate_grpc_client_adapter_methods(context: &CodegenContext) -> TokenStream
for syn_method in &context.methods {
let method_name = syn_method.name.to_token_stream();
let request_type = syn_method.request_type(false);
let rpc_name = syn_method.rpc_name(false);
let response_type = syn_method.response_type(context, false);

let into_response_type = if syn_method.server_streaming {
quote! { |response|
{
let streaming: tonic::Streaming<_> = response.into_inner();
let stream = quickwit_common::ServiceStream::from(streaming);
stream.map_err(crate::error::grpc_status_to_service_error)
stream.map_err(|status| crate::error::grpc_status_to_service_error(status, #rpc_name))
}
}
} else {
Expand All @@ -1177,7 +1188,7 @@ fn generate_grpc_client_adapter_methods(context: &CodegenContext) -> TokenStream
.#method_name(request)
.await
.map(#into_response_type)
.map_err(crate::error::grpc_status_to_service_error)
.map_err(|status| crate::error::grpc_status_to_service_error(status, #rpc_name))
}
};
stream.extend(method);
Expand Down
1 change: 1 addition & 0 deletions quickwit/quickwit-ingest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn main() {
.with_result_type_path("crate::Result")
.with_error_type_path("crate::IngestServiceError")
.with_prost_config(prost_config)
.generate_rpc_name_impls()
.run()
.unwrap();
}
31 changes: 28 additions & 3 deletions quickwit/quickwit-ingest/src/codegen/ingest_service.rs

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

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

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

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

Loading

0 comments on commit 6fdb4ed

Please sign in to comment.