-
Notifications
You must be signed in to change notification settings - Fork 124
Implement Strict Routing Semantics for Routing Rules #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ | |
| import jakarta.annotation.Nullable; | ||
| import jakarta.annotation.PreDestroy; | ||
| import jakarta.ws.rs.HttpMethod; | ||
| import jakarta.ws.rs.WebApplicationException; | ||
| import jakarta.ws.rs.core.Response; | ||
|
|
||
| import java.net.HttpURLConnection; | ||
| import java.net.URI; | ||
|
|
@@ -42,6 +44,8 @@ | |
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static jakarta.ws.rs.core.Response.Status.NOT_FOUND; | ||
|
|
||
| /** | ||
| * This class performs health check, stats counts for each backend and provides a backend given | ||
| * request object. Default implementation comes here. | ||
|
|
@@ -99,15 +103,21 @@ public ProxyBackendConfiguration provideDefaultBackendConfiguration(String user) | |
| } | ||
|
|
||
| /** | ||
| * Performs routing to a given cluster group. This falls back to a default backend, if no scheduled | ||
| * backend is found. | ||
| * Performs routing to a given cluster group. This falls back to a default backend if the target group | ||
| * has no suitable backend unless {@code strictRouting} is true, in which case a 404 is returned. | ||
| */ | ||
| @Override | ||
| public ProxyBackendConfiguration provideBackendConfiguration(String routingGroup, String user) | ||
| public ProxyBackendConfiguration provideBackendConfiguration(String routingGroup, String user, Boolean strictRouting) | ||
| { | ||
| List<ProxyBackendConfiguration> backends = gatewayBackendManager.getActiveBackends(routingGroup).stream() | ||
| .filter(backEnd -> isBackendHealthy(backEnd.getName())) | ||
| .toList(); | ||
| if (backends.isEmpty() && strictRouting) { | ||
| throw new WebApplicationException( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why WebApplicationException and not IllegalStateException like in IllegalStateException("Number of active backends found zero")) or maybe a custom Explicit Exception inherited from RouterException?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add a WARN or ERROR with context when the 404 is triggered? Also +1 on maybe making it a |
||
| Response.status(NOT_FOUND) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client did nothing wrong and shouldn't receive a 4xx error. We should return a 5XX indicate a server side error, maybe |
||
| .entity(String.format("No healthy backends available for routing group '%s' under strict routing for user '%s'", routingGroup, user)) | ||
| .build()); | ||
| } | ||
| return selectBackend(backends, user).orElseGet(() -> provideDefaultBackendConfiguration(user)); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a nitpick, but evaluating
strictRoutingfirst can short circuit thebackends.isEmpty()one, in case it's false. A teeny performance optimization would be to re-order these so it'sif (strictRouting && backends.isEmpty())