Home > Back-end >  Redirect request based on parameter on GCP
Redirect request based on parameter on GCP

Time:12-31

I've a small demo app which is a key-value store. I've uploaded this to GCP and I was wondering if I could redirect requests to appropriate shards. What I'm trying to do is something like this:

scheme

Although GCP's Load Balancer has URL Maps and path rules, it's mostly redirecting based on endpoint. For example for reaching a video content; v1/hd/{videoId} would redirect to HD video service and v1/uhd/{videoId} would redirect to UHD video service. In my case this does not solve my problem. I'd like Load Balancer to detect the parameter's first character, maybe a Regex like this ^([A-M]|[a-m]) or something along those lines, and if the parameter starts with a character from A to M it should redirect to service 1.

Is this something reasonable? If so, possible?

CodePudding user response:

Url maps path matcher does not support conditions or regex.

As quoted from the documentation, Path matcher has some constraints:

A path rule can only include a wildcard character (*) after a forward slash character (/). For example, /videos/* and /videos/hd/* are valid for path rules, but /videos* and /videos/hd* are not.

Path rules do not use regular expression or substring matching. For example, path rules for either /videos/hd or /videos/hd/* do not apply to a URL with the path /video/hd-abcd. However, a path rule for /video/* does apply to that path.

Path matchers (and URL maps in general) do not offer features that function like Apache LocationMatch directives. If you have an application that generates dynamic URL paths that have a common prefix, such as /videos/hd-abcd and /videos/hd-pqrs, and you need to send requests made to those paths to different backend services, you might not be able to do that with a URL map. For simple cases containing only a few possible dynamic URLs, you might be able to create a path matcher with a limited set of path rules. For more complex cases, you need to do path-based regular expression matching on your backends.


What you are looking for can be achieved by setting up Nginx or Apache webservers as the only backend for your LoadBalancer and configuring this backend to route requests with conditions and/or regex to your services.

PS: If is Evil... when used in location context

  • Related