-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
service-router: PrefixRewrite cannot be empty string (and docs are unclear/the example produces confusing behavior) #11000
Comments
Hi @chrisjohnson, Thank you for the detailed, thoughtful feedback on this and many other Github issues - we really appreciate it. We'll look into this more and consider what should be improved (e.g., docs/examples, handling of In the meantime, as a workaround, are you able to achieve what you want by appending a
This won't work if you need the exact path Regarding your points above:
|
That workaround is what we are currently using. You are right that it won't match the naked form (and afaik I cannot find a workaround that will support the naked form) but it helps us at least make forward progress for now. We will need the naked form supported in the near future but for today we can make progress. If the blog post structure was never correct, I might suggest simply retro-actively editing the blog post, since currently when you google for PrefixRewrite it's one of the top results and really the only firm example of how to use it that people will find. Adding another example to the config entry page would also be great. I'm down to approach the rewrite either way, either we allow you to rewrite to empty string, or we ignore the preceding slash. Just let me know where we land please :)
Tangent: We tried changing our structure to match the blog post to see if that was the cause of our problems. We manage this config entry via the consul terraform provider. When we did a terraform plan (the TFE speculative plan) it did not complain about the structure, but after merging the change and going to apply, it failed because the structure of the config entry was wrong. Should the plan step be validating the incoming structure like how the apply step does? And if so, is this a fault of the consul provider, or consul itself? Is there a place I could log a followup issue around this behavior? It's not a show-stopper but it's a pain to have already merged the PR because the speculative plan passed only to find out the apply doesn't work. |
I'd suggest posting an issue to https://github.com/hashicorp/terraform-provider-consul. From some similar posts on that provider (hashicorp/terraform-provider-consul#281 (comment), hashicorp/terraform-provider-consul#248), it seems like the plan vs apply issue may be due to the interaction of the TF provider with the flexibility of Consul's configurations, though the maintainers of that provider can give a better answer. |
@chrisjohnson: after looking into (3) a bit more, I have a solution that better satisfies your use case (but requires two routes) and an understanding of why it can't currently be done with one route. Why two routes are currently needed Because the prefix rewrite behavior configured in Consul is ultimately performed by Envoy, Consul has the same limitation (see Envoy xDS code): Lines 301 to 307 in 584faec
There may be a way for Consul to provide a better UX on top of this Envoy constraint - we'd have to think about it more. Regardless, this should be better documented in our description of A currently available solution for your use case
|
@chrisjohnson : I've got a proposal for how the configuration UX could be simplified here. Let me know your thoughts on whether this would be a relevant part of the solution (in addition to docs/example improvements) and if you have any suggestions for improvements. If you think such a change would be useful, I'll run it by engineering to double-check whether they have any technical feasibility or backwards-compatibility concerns. ProposalIf the user has a service-router configuration like below (prefix
Example service-router configuration this would apply to
Underlying Implementation ThoughtsNormally, Consul does a direct translation (1:1) of Consul service-router rule matches to Envoy route matches. However, if the user wants to replace all We can potentially make this behavior more intuitive by automatically creating the multiple Envoy route matches required when the user wants the above behavior. We can assume that user wants this behavior when all these criteria are met by the service-router configuration:
If these conditions are met, the rule matches passed to Envoy will actually be:
To-do
|
Overall it definitely makes sense to me, I understand the balance between "consul via envoy" and "envoy managed by consul" is something to be paid attention to but in this case it really feels like an envoy nuance that I think consul is right to abstract away from the user. Worst case if it does create backward compatibility issues, a flag to opt out (or in) for the behavior could be an easy way to control that. Maybe even "rewrite-mode=direct" or "rewrite-mode=auto" to allow for other operating modes in the future. |
Overview of the Issue
The docs for using PrefixRewrite are not great and it seems like there's a bug that won't allow me to use empty string as a value
1: I don't actually see where in the docs PrefixRewrite is actually clearly explained. I found the doc entry for it but it doesn't explain how it's actually used. This blog post is the only example for PrefixRewrite that I can find, and it does not have the structure that is currently in use (I'm assuming the structure changed since then?)
I did reverse engineer the logic by looking at the golang tests that involve PrefixRewrite and I was able to deduce that the PrefixRewrite value is used as the direct replacement value for whatever PathPrefix matched
2: That said, the example on that blog post as well as the golang tests all seem to use an example that works like this:
However this results in a request like this:
curl localhost:21001/sp/bar
->//bar
This is confusing. I understand that technically it is valid from consul's POV but it produces strange behavior where the request ends up with an extra slash. The tests should be changed and an example should be added to the documentation page
3: Finally, I think there may actually be a bug, because when I try to produce the expected result by using the following configuration:
It won't let me use an empty string for PrefixRewrite -- when I read the config back it shows that the PrefixRewrite was simply eliminated:
Consul info for both Client and Server
Client info
Server info
The text was updated successfully, but these errors were encountered: