Add AWS X-Ray into Envoy as one of tracing providers
AWS X-Ray Integration with Envoy proxy
Description: Hello Envoy contributors, I am from AWS X-Ray team and we want to make contributions to Envoy so that customer can use X-Ray as one tracing option. Before sending out PRs, we have one design regarding sampling strategy want to discuss with the community and get some feedback.
I found out Envoy provides its own sampling strategy such as random sampling and customer can just configure the % of requests that will be traced, which is different from our current existing sampling strategy. How our sampling strategy works is that customer can provide rules for sampling request through our console. By customizing sampling rules, customers can control the amount of data that they want to record, and modify sampling behavior on the fly without modifying or redeploying their code. For example, customer can specify which URL path will be sampled, or which HTTP method(GET or POST) request contains will be sampled. Each rule will be applied to a certain group of requests. Basically, providing more options for sampling requests and customer won't need to modify their code if they want to change the sampling behavior.
The implementation of centralized sampling is that inside envoy proxy, there will be two long running processes which fetch sampling rules and statistics and update local rules which is stored in cache. The cache has high read frequencies since each sampling decision requires the xray tracer(inside Envoy) to read from the cache, which uses granular locking mechanisms to ensure the performance impact is minimal. Each rule has it's own lock to isolate the process of retrieving a rule from the cache and actually modifying/using the rule. The maximum sampling rules customer were allowed to provide is 25. If somehow centralized sampling is not working, tracer will try to use the default 5% sampling rate to all incoming request.
Above is the current design we have to sampling strategy. One concern we have is that does Envoy community accept we providing another sampling strategy inside envoy? If the community accepts the PR, how we should treat the sampling strategy that envoy original have? Should we mute that one? The other concern is about the performance impact for envoy if onboard with our centralized sampling. Currently, our centralized sampling is used by customer's web application where performance impact can be small. However, Envoy is a proxy which is lightweight, after adding centralized sampling, the performance impact can be big. Any suggestions here for us about which specific performance test item we should emphasis on?
I am new to Envoy and some understanding of Envoy might be wrong, feel free to point out and have discussion with me. Thank you very much.
[Relevant Links:] AWS X-Ray AWS X-Ray Centralized Sampling
cc @cgilmour @rnburn @objectiser for comment.
My general feeling is to build your centralized sampling directly into the x-ray tracer to begin with, so core Envoy will not be aware of it at all. There are mechanisms within Envoy such as TLS (thread local storage) that can make this type of configuration scale very well.
Hi @luluzhao I think it's fine and fits with the way envoy's sampling actually behaves.
There's configuration for random_sampling and overall_sampling etc, and they default to 100%.
The way they are applied is actually inverted.
Eg: a user configures overall_sampling to 90%. For 10% of the traffic, envoy will decide to not sample the request. The remaining 90% can be decided by the tracing extension.
In opentracing-based extensions, it happens in startSpan. It only passes the decision to not sample it.
With those config items defaulting to 100%, essentially all sampling decisions are made by the tracing extension.
Within the rest of envoy, there's only one place that tries to change the sampling decision later on: the healthcheck filter.
Overall, I think the places where envoy decides to not sample a request should be respected by the tracing extension, and for everything else the tracing extension can choose whatever behavior makes sense.
One thing that was essential for me to know when developing an integrated tracer was this:
Envoy's requirement that directly integrated tracers don't do any of their own threading or socket management.
That impacted the design for me. However the result of using thread-local storage and envoy's native HTTP facilities ended up better than what I would have crafted myself with threads, locks and an HTTP library.
Overall, I think the places where envoy decides to not sample a request should be respected by the tracing extension
One clarification with this - the reason that the sampling decision is delegated to the tracing extension is that envoy does not know if the business transaction is currently being sampled prior to arriving at the first envoy proxy. So envoy provides its suggestion based on user configuration, but ultimately the tracing extension needs to check whether the request is already being sampled (by inspecting the tracer specific headers), and if not, decide whether to accept the decision supplied by envoy, or override it.
Hello @cgilmour , thank you for your explanation and help. I really appreciate that. There is two questions I want to ask. First, how envoy decide which request to sample or not, basically, like your example, how that 10% not sampled requests been decided by envoy? I am trying to find the sampling logic inside envoy but I could not find it. Could you point out the source code where envoy make the sampling decision for a request? Second, why envoy changes sampling decision in decodeHeaders method in health check filter? Could you explain more about this to me? Thank you so much.
What's more, I agree we should use thread-local storage mechanism inside envoy. I am wondering why we cannot make our own socket management? Our current design is to use UDP socket inside envoy to send segments to daemon(running inside another sidecar container) and the daemon will do batch and rate-limit for segments. And also, daemon will also act as a proxy to fetch centralized sampling rules from our backend to let the tracer to update local in memory sampling rules. Regarding our current existing workflow for AWS X-Ray, I think managing UDP socket is a better solution rather than using HTTP library. I would like you can share more thoughts on this. :) Thank you again.
@luluzhao The details about tracing occur in a few different spots.
One spot is here, where it applies the config about tracing. It makes a decision there based on the config values (or defaults) and stores it in the outcome of that decision in the x-request-id header value.
This gets applied to the request here. It extracts the decision / tracing status from the x-request-id header and then tells the tracer that status when calling startSpan.
The implementation of startSpan is one of the parts that you'd be writing as a tracing extension.
There's other parts in Envoy that use UDP sockets, eg: one of the transports for statsd.
Hello @cgilmour @objectiser @mattklein123 , thank you for all your help and explanation. We understand that no matter what tracing extensions' implementation, if customer wants and chooses to use envoy sampling, tracers should respect it in stead of ignore it. However, we have some concerns regarding envoy default 100% sampling rate if customers choose to use X-Ray. First concern is billing. AWS X-Ray pricing model is that we charge our customer by number of traces. 100% sampling rate means all the requests come to envoy will be traced. If customers turn on AWS X-Ray tracer without modifying sampling rate, their bill can suddenly go up if their traffic is huge. That is why X-Ray default sampling rate is 5%. Second concern is deployment safety. For example, if customers uses envoy default sampling rate(100%), all the upstream applications which has X-Ray integration will have 100% sampling rate and old sampling rule will be ignored. If customers have several upstream application and do a deployment, this can be dangerous since on client side, both CPU and memory can go up dramatically due to full sampling rate.
Based on these two concerns, we give a proposal that if customers choose to use X-Ray as their tracing extension, X-Ray sampling will be default to consider. Of course, if customers still want to use envoy sampling even though they are using X-Ray tracer, X-Ray tracer should respect it by ignoring X-Ray sampling rule and instead using envoy sampling. There should be only one sampling strategy when customers use envoy since we think double sampling doesn't serve any particular use case.
Above is our thought regarding sampling and feel free to comment and address your opinion about it. We are open for discussion. Thank you so much.
@luluzhao I think it is fine for your tracer to use its own sampling strategy by default, and then provide an option that enables customers to indicate they would prefer to use envoy's decision instead.
Hey there, we noticed that envoy did 4 releases last year. Could we know what is the release plan for this year since we really want to add our X-Ray tracer into the release so that customer can start using it. Another thing is we are going to add AWS C++ SDK as one of dependency regarding implementing the our sampling strategy. Does your community could accept that we bring AWS SDK dependency into this project? Thank you.
Hello @mattklein123 , sorry for pinging you regarding my question since it has been a week no one reply for it. Our basic question is when is the next release for Envoy so that X-Ray tracer can be part of it? Thank you.
@luluzhao we do releases approximately every 3 months. You can take a look at our last release to see roughly where we are at.
Hello @mattklein123, does the community has a exact date for the upcoming March release? Could you share with my the date? Another question would be is there any possible to get virtual host name inside header map?
There is no specific date that we set, by the end of March for sure.
Another question would be is there any possible to get virtual host name inside header map?
I'm not sure what this means. Please open a separate issue for any feature requests.
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.
I'm guessing that as the product page for AppMesh mentions end-to-end visibility including AWS X-Ray, AWS must have a custom filter or build to enable this functionality.
Yes, we add AWS X-Ray support for App Mesh GA release and it based one Envoy version 1.9.0. I updated the PR today which is developed against upstream. Sorry for the delay of updating the PR.
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.
@mattklein123 @cgilmour , sorry for disconnecting a little while. Could you help me to reopen this issue. I finished all the implementation and going to submit PRs accordingly. Thank you.
BTW, I asked a question about 21 days ago on one of my closed PR and it hasn't get any replied yet. Could you help me on that? Here is the link for reference.
This is merged, we can track further work is individual issues/PRs.