grpc-rust icon indicating copy to clipboard operation
grpc-rust copied to clipboard

Proposal: Adding User Agent Header

Open nevi-me opened this issue 6 years ago • 4 comments

Hi Stepan,

I'm learning Rust by porting some of my Kotlin code over to Rust, and so far it's been a pleasant journey (lots of Googling).

I'd like to propose adding an user-agent header to client requests, in the form user-agent : grpc-rust/0.4.0. All the other grpc libraries do so.

Here are a few examples from my server:

grpc-java-netty1.9.0
grpc-node/1.8.4 grpc-c/5.0.0 (linux; chttp2; generous)

I've manually been doing it through the below, but as I'm still a beginner, I wouldn't know how/where do to in on the code base:

let mut metadata = grpc::Metadata::new();

let value: bytes::Bytes  = bytes::Bytes::from("grpc-rust/0.4.0");

metadata.add(grpc::MetadataKey::from("user-agent"), value);

...

grpc::RequestOptions {
    metadata
}

What do you think? I presume the biggest challenge could be overriding the user-agent if the user specifies a different value.

nevi-me avatar May 28 '18 21:05 nevi-me

What do you think?

I think that's a right idea.

I presume the biggest challenge could be overriding the user-agent if the user specifies a different value.

User-agent could be a configuration option. It should be an option in rust-http library (which is used by grpc-rust).

stepancheg avatar May 28 '18 21:05 stepancheg

I wouldn't know where to start with making it happen, I'll try working on it when I understand your code base (and Rust in general) better.

As a random aside, I have a 'microservice' in Java that was using up about 450MB of RAM at peak (120MB from startup), the Rust version is using about 4MB so far, I'll be adding instrumentation on it this weekend to compare the two. I wouldn't have been able to make the transition without your grpc library, thanks a lot!

image

nevi-me avatar May 28 '18 21:05 nevi-me

OK, but please note that grpc-rust is not a perfect library (in terms of compatibility and performance).

There's also grpc-rs, which is a bindings to C implementation.

stepancheg avatar May 28 '18 21:05 stepancheg

That's okay, I understand some of the limitations. One has to start somewhere I suppose :smile:. I still have quite a lot of stuff in Java/Kotlin and NodeJS due to better library support for what I'm doing. I think having more people poke at grpc-rust will enable us to see where more can be done, and get more contributors to help you out.

nevi-me avatar May 28 '18 21:05 nevi-me