Istio Routing using OpenTracing Baggage/Distributed Context Propagation
Modern service mesh architectures provides several new capabilities which significantly simplify application code by removing infrastructure related dependencies. In addition to that this architecture simplifies features like canary deployment by smart routing and much more.
In this blog post we are going to look at how distributed context propagation or baggage can be used by Istio routing rules.
Imagine a scenario where you want to redirect all Safari users to a specific version of a service using the
User-Agent HTTP header. This is useful in canary deployments when a new version is rolled out for a specific subset of users. However the header is present only at the first service. If the routing rule is for a service lower in a call graph then the header has to be propagated through all intermediate services. This is a great use-case for distributed context propagation which is a feature of many tracing systems. We are going to look at OpenTracing using Jaeger implementation.
Distributed context propagation/baggage items are
key:value string pairs associated with
Span/SpanContext and are propagated in-band to all descendant spans within a trace.
If your service mesh is instrumented with OpenTracing then this feature should be available. On the other hand if your services are not instrumented then you can pass the
User-Agent header along with other tracing headers, which unfortunately requires changes in all intermediate services.
Istio by default uses B3 propagation, which does not standardize baggage header. However baggage support can be configured in the Brave (Zipkin java client) library, and often uses the header format
baggage-key:value. Jaeger implements a B3 codec that uses the same format for baggage. The current status of B3 baggage implementation can be found here.
Baggage can be set on the current active span as follows:
This has to be done in the first service. The last thing we have to do is to define a routing rule for the baggage header. The following route definition forwards all requests containing baggage with entry
Or following for newer Istio versions (after 0.8.0)
- name: v2
Now all should be configured and Safari users should be forwarded to Recommendation service of version 2.
The following video demonstrates Istio routing via OpenTracing baggage in redhat-developer-demos/istio-tutorial.
- OpenTracing: http://opentracing.io/
- OpenTracing baggage specification: https://github.com/opentracing/specification/blob/master/specification.md#set-a-baggage-item
- B3 bagggage support in Jaeger clients: https://github.com/jaegertracing/jaeger/issues/755#issuecomment-393929718
- Istio tutorial on OpenShift: https://github.com/redhat-developer-demos/istio-tutorial
- Kiali project: https://kiali.org/