Route by path and header
We route to services based upon URL, but we also need routing to account for revision of frontend/backend software.
Thus, on a given host we may have several microservices that will support /this-particular-route, but we've pre-identified that the client is running x-header=x_version and needs to be directed to the urlprefix-/this-particular-route & x_version
We have tags on our containers that tell us their urlprefix, version, service_type, and environment
I don't see a way to narrow the scope from urlprefix, and it sure would be handy.
I see a solution that would work as something like:
urlprefix- fabiotag-
a bonus would be the ability to support more than one additional 'fabiotag-'.
Couldn't your service announce both a generic and a specific route, i.e. p-/foo and p-/foo.v1? I'm assuming that you have another proxy in front of this which does the header parsing.
so, you're suggesting to narrow the scope of whats being routed by tagging containers with 'two' URL's, one being the real URL, and the other to aid in version identification. Then use the proxy in front to sort out the header parsing and route to the appropriate fabio instance/port?
If I'm understanding you correctly, we could use the proxy in front to sort the versioning, and container tagging to group the containers by versions within fabio, but the URL would remain the same between the proxies (I believe a re-write is a no-go with the way our services are written/structured).
Something like this could work if we could set fabio to listen for /this-url & /this-version on a specific port, and /this-url & /that-version on a different port. Is that possible?
I think now I get it. You want to route based on /path and Header: value instead of just /path. Currently, fabio routes only on /path so this won't work out of the box. Since you mention that you've identified the client before I am assuming that there is another proxy that performs the identification.
What you could do is the following:
You register all services with Header: x with x-/path, all services with Header: y with y-/path and so forth, e.g. v15-/path, v16-/path.
Then you would have to run a fabio instance per prefix by setting the register.consul.tagprefix value to either x, y, v15, v16, .... They would have to run on different ports though.
In essence you're namespacing your service URLs and your fabio instances still share the same service registry.
TBH, this sounds like a workable but not very elegant solution. Let me know whether that solves your problem for now and I'll think of something better.
Thanks, we'll try to make it work. I'm thinking that we'll need to make an array of values for register.consul.tagprefix like:
service x, y, z version v1, v2, v3 environment q1, q2, q3
so register.consul.tagprefix=urlprefix_x_v1_q1-/pathtox and register.consul.tagprefix=urlprefix_x_v2_q1-/pathtox (on different port) and so on.... three versions on each service, in 8 environments.
I think we can cover it with 3x8 ports. It sounds a little messy, but I think I can use the K/V store to set the URL Prefix/Port combinations to link the front proxy (parsing headers) to the back proxy (matching URL's to services.
I suggest to use something shorter like p_x_v1_q1-/path. It is messy but I need to wrap my head around this a bit more to come up with a better solution.
Thanks and keep me posted how it works.