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

feat: add GrpcMethod extension into request for client #1275

Merged
merged 5 commits into from
Feb 23, 2023

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? 😄

tonic/src/extensions.rs Outdated Show resolved Hide resolved
tonic-build/src/client.rs Outdated Show resolved Hide resolved
tonic-build/src/client.rs Outdated Show resolved Hide resolved
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.

tonic/src/extensions.rs Show resolved Hide resolved
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