[grpc-java] Header propagation in service mesh (linkerd)

220 views
Skip to first unread message

Ankur Chauhan

unread,
Jul 28, 2017, 12:01:23 AM7/28/17
to grpc.io
Hi,

I am trying to integrate some of our grpc services with linkerd ( a service mesh ). As a part of doing that, the recommendation is that the apps should propagate any headers with "l5d-" prefix to all downstream services. I tried looking at some tests for io.grpc.Context but can't figure out what would be the best way to do this. Anyone care to comment? This should be similar to how deadlines are propagated (i think).

-- Ankur

Spencer Fang

unread,
Jul 28, 2017, 1:28:50 PM7/28/17
to Ankur Chauhan, grpc.io
Hello Ankur,
The io.grpc.Context is indeed the right thing to use here. What you want to do is to first create a ServerInterceptor that looks at the incoming headers and pulls out all "l5d-" prefixed keys. The ServerCall.Listener is how your application defines how to respond to incoming requests, so the interceptor must make sure that a io.grpc.Context containing the "l5d-" info is present whenever your code runs. Next, you need a ClientInterceptor that looks at the current io.grpc.Context, and merges "l5d-" headers into any outgoing headers.

I have created a branch on github that shows what I mean: https://github.com/grpc/grpc-java/compare/master...zpencer:grpc-io-l5d-demo?expand=1



--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/19357e59-34d8-461a-997e-287cac9f096b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Spencer Fang

Spencer Fang

unread,
Jul 28, 2017, 1:41:34 PM7/28/17
to Ankur Chauhan, grpc.io
In gist form for easier mailing list archival, because I'd probably clean up that branch at some point:
--
Spencer Fang

Ankur Chauhan

unread,
Jul 30, 2017, 3:42:37 AM7/30/17
to grpc.io, an...@malloc64.com
Thanks for the code example Spencer. This is exactly what I needed. I'll make it into a library and publish it for others to enjoy once i test it a little bit.


On Friday, July 28, 2017 at 10:41:34 AM UTC-7, Spencer Fang wrote:
In gist form for easier mailing list archival, because I'd probably clean up that branch at some point:
On Fri, Jul 28, 2017 at 10:28 AM, Spencer Fang <spenc...@google.com> wrote:
Hello Ankur,
The io.grpc.Context is indeed the right thing to use here. What you want to do is to first create a ServerInterceptor that looks at the incoming headers and pulls out all "l5d-" prefixed keys. The ServerCall.Listener is how your application defines how to respond to incoming requests, so the interceptor must make sure that a io.grpc.Context containing the "l5d-" info is present whenever your code runs. Next, you need a ClientInterceptor that looks at the current io.grpc.Context, and merges "l5d-" headers into any outgoing headers.

I have created a branch on github that shows what I mean: https://github.com/grpc/grpc-java/compare/master...zpencer:grpc-io-l5d-demo?expand=1


On Thu, Jul 27, 2017 at 9:01 PM, Ankur Chauhan <an...@malloc64.com> wrote:
Hi,

I am trying to integrate some of our grpc services with linkerd ( a service mesh ). As a part of doing that, the recommendation is that the apps should propagate any headers with "l5d-" prefix to all downstream services. I tried looking at some tests for io.grpc.Context but can't figure out what would be the best way to do this. Anyone care to comment? This should be similar to how deadlines are propagated (i think).

-- Ankur

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/19357e59-34d8-461a-997e-287cac9f096b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Spencer Fang



--
Spencer Fang

Ankur Chauhan

unread,
Jul 30, 2017, 10:38:37 PM7/30/17
to grpc.io, an...@malloc64.com
Published a cleaned out version of these interceptors at - https://github.com/ankurcha/linkerd-grpc-interceptors
Reply all
Reply to author
Forward
0 new messages