Rewriting Path based on Load Balancing

Good morning!

I’m using kong to split traffic between a new API endpoint and an old one. This is pretty easy to set up by configuring the service/path and attaching the two separate upstreams with respective weights.

However, up to this point, it appears that Kong assumes that the API paths will be the same. Is there a way to rewrite the path on one upstream or the other depending on which upstream the load balancer decides to forward it to?

Example:
Kong is at path /app/submit
Upstream A (old) is at path /some/folder/submit.php (weight 80)
Upstream B (new) is at path /api/v2/submit (weight 20)

(POST payloads to each are the same)

Is this possible? I know it’s a bit odd, but otherwise it means that I’d have to deploy Kong and then do a series of URL rewrites on the backend web server.

Thanks in advance!

No this is not possible currently but this is a known ask and we are tracking this internally. (cc @hisham)

@Tieske might have some ideas on how to do this if it is even possible today.

The load balancer operates on L4, so no path rewrites since that is an L7 property. This is an L7 routing problem.

The way to do this with Kong is to create 2 upstreams (load balancers) and then use the Canary plugin, configured to update both the path and the hostname.

Unfortunately the path updating is still stuck on https://github.com/Kong/kong/pull/4653 (ping @hisham )

But if you have a specific use case, it can easily be done with a custom plugin.


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ