I am trying to set-up URL maps for GCP load balancers. I have Service C for static files and the two web application services A and B. C should get everything not starting with a certain path, the rest if the traffic should be divided by A and B depending on headers. If there are no headers, then the location should be decisive. A and B live in different regions but also have some different logic.
In sudo code, the URL map would be something like:
If request does not contain path /my-path then go to service C
If request contains path /my-path:
- If requests contains header A1 then go to Service A
- If requests contains header A2 then go to Service A
- If requests contains header B1 then go to Service B
- If requests contains header B2 then go to Service B
- If request contains none of headers A1, A2, B1, or B2
then go to either Service A or Service B,
preferable to the service locally closer to the origin of the request.
What I've got so far is:
defaultService: projects/my-project/global/backendServices/service-c
name: path-matcher-1
routeRules:
- description: A1 to A
matchRules:
- headerMatches:
- headerName: A1
prefixMatch: ...
prefixMatch: /my-path
priority: 1000
service: projects/my-project/global/backendServices/service-a
- description: A2 to A
matchRules:
- headerMatches:
- exactMatch: ...
headerName: A2
prefixMatch: /my-path
priority: 2000
service: projects/my-project/global/backendServices/service-a
- description: B1 to B
matchRules:
- headerMatches:
- headerName: B1
prefixMatch: ...
prefixMatch: /my-path
priority: 3000
service: projects/my-project/global/backendServices/service-b
- description: B2 to B
matchRules:
- headerMatches:
- exactMatch: ...
headerName: B2
prefixMatch: /my-path
priority: 4000
service: projects/my-project/global/backendServices/service-b
- description: Distribute everything else to closest location
matchRules:
- prefixMatch: /my-path
priority: 5000
service: projects/my-project/global/backendServices/service-a
....
# TODO!
(I have omitted the exact header name and values. Those work in general and do not matter in this context I think.)
Now I have two questions:
How do I implement the last part like distribute preferable by location, i.e. service whose region is closest to the user's IP?
Does the rest of my code achieve what I want it to do? Seems so according to my tests but not 100% sure here