Skip to content

Conversation

@linw1995
Copy link
Contributor

@linw1995 linw1995 commented Feb 16, 2023

Motivation

The request was added with the GrpcMethod extension in the gRPC client code generated on tonic-build, for this reason, we can inspect the gRPC method info within the client interceptor function. In the future, this feature could be used for supporting Prometheus middleware metrics on a common basis.

    fn client_intercept(req: Request<()>) -> Result<Request<()>, Status> {
        println!("Intercepting client request: {:?}", req);

        let gm = req.extensions().get::<GrpcMethod>().unwrap();
        assert_eq!(gm.service(), "test.Test");
        assert_eq!(gm.method(), "UnaryCall");

        Ok(req)
    }
    let mut client = TestClient::with_interceptor(channel, client_intercept);
    client.unary_call(Request::new(Input {})).await.unwrap();

Solution

Update tonic-build to generate client-side codes that support the GrpcMethod extension. Why not review the code changes in this file, tonic-health/src/generated/grpc.health.v1.rs, to see the differences? 😄

@linw1995 linw1995 requested a review from LucioFranco February 20, 2023 16:43
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, have one more request then we can merge.

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following through on this!

@LucioFranco LucioFranco added this pull request to the merge queue Feb 23, 2023
Merged via the queue into hyperium:master with commit 7a6b20d Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants