Optimization: don't use regex location when avoidable #10808
Labels
kind/feature
Categorizes issue or PR as related to a new feature.
lifecycle/frozen
Indicates that an issue or PR should not be auto-closed due to staleness.
needs-priority
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
History & Current state
Since ingress-nginx 0.22, rewrite target requires the use of regex (#3174 (comment)) and since this change #3078 in version 1.0.0, every location of a server block uses regex if one ingress uses rewrite-target. I use version 1.9.4.
That can lead to inefficiencies, as regex based locations are slower and not indexed (regex are just tested in order).
Rewrite-target usage is quite common for webservice use cases, and the most common use-case is to strip the beginning of the path.
Eg, going from
api.example.com/service-a/apiCall
to/apiCall
for the final service.We don't need to use regex for that.
Would work just fine, without the need of a regex location.
For my use case, we have 400 paths on a location, so regex based routing is not optimal.
What do you want to happen?
Allow to strip the prefix of a path, without relying on a regex location for all locations.
Technical proposals
Proposal 1: via a dedicated option, like
nginx.ingress.kubernetes.io/strip-prefix: boolean
That new
nginx.ingress.kubernetes.io/strip-prefix: boolean
option would work just like the pre-0.22 rewrite-target option: the location would be a fixed stirng prefix, and the rewrite would be automatically populated withrewrite "(?i)/<prefix>(.*)" /$1 break;
Pros:
Cons:
Proposal 1-b: via a dedicated option, like
nginx.ingress.kubernetes.io/rewrite-prefix: string
Same as proposal 1, but allow to change the prefix instead of just stripping it.
Pros:
Cons:
rewrite-target
andrewrite-prefix
Proposal 2: detect the srip prefix use case
For this second technical proposal, we could check if the prefix ends with
(.*)
and the rest of the prefix doesn't contain any regex special character.If that's the case, we can use a string based prefix instead of the regex automatically.
Pros:
Cons:
\.
) in the PrefixProposal 3: Add a
nginx.ingress.kubernetes.io/rewrite-source: string
optionAdd a
nginx.ingress.kubernetes.io/rewrite-source: string
option, that would come along with thenginx.ingress.kubernetes.io/rewrite-target: string
option.That would allow to define the source and target of the rewrite:
The prefix option would always be considered as a plain string, unless the
use-regex
option is used.To make that change non breaking, the new behaviour can be enabled only if
nginx.ingress.kubernetes.io/rewrite-source:
is defined. If not, consider the Prefix of the ingress asnginx.ingress.kubernetes.io/rewrite-source
and force enableuse-regex
.The usage of
nginx.ingress.kubernetes.io/rewrite-target: string
withoutnginx.ingress.kubernetes.io/rewrite-source: string
might be deprecated.Pros:
use-regex
option is setCons:
If this new feature is added, I would favor this latest proposal.
Is there currently another issue associated with this?
#8425
#10563 (not sure for this one)
#3078
Does it require a particular kubernetes version?
No
Sorry for the long post, I made it as clear as I can
The text was updated successfully, but these errors were encountered: