Skip to content

Commit 9c75cd6

Browse files
authored
Forward Nexus requests using same dispatch type as original request (#8199)
## What changed? When forwarding Nexus requests that were originally sent to the `DispatchByEndpoint` URL, the forwarding URL will also be constructed to send the request to the `DispatchByEndpoint` URL on the remote cluster. Previously, we were always sending forwarding requests using `DispatchByNamespaceAndTaskQueue` ## Why? bug fix ## How did you test it? existing tests
1 parent 21f556c commit 9c75cd6

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

service/frontend/nexus_handler.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type nexusContext struct {
4848
namespaceName string
4949
taskQueue string
5050
endpointName string
51+
endpointID string
5152
claims *authorization.Claims
5253
namespaceValidationInterceptor *interceptor.NamespaceValidatorInterceptor
5354
namespaceRateLimitInterceptor interceptor.NamespaceRateLimitInterceptor
@@ -668,12 +669,21 @@ func (h *nexusHandler) nexusClientForActiveCluster(oc *operationContext, service
668669
return response, nil
669670
}
670671

671-
baseURL, err := url.JoinPath(
672-
httpClient.BaseURL(),
673-
commonnexus.RouteDispatchNexusTaskByNamespaceAndTaskQueue.Path(commonnexus.NamespaceAndTaskQueue{
674-
Namespace: oc.namespaceName,
675-
TaskQueue: oc.taskQueue,
676-
}))
672+
var baseURL string
673+
if oc.endpointID != "" {
674+
// If the request was originally dispatched by endpoint, forward by endpoint as well.
675+
baseURL, err = url.JoinPath(httpClient.BaseURL(),
676+
commonnexus.RouteDispatchNexusTaskByEndpoint.Path(oc.endpointID))
677+
} else {
678+
// Fallback to dispatch by namespace and task queue since those have already been resolved by this point.
679+
baseURL, err = url.JoinPath(
680+
httpClient.BaseURL(),
681+
commonnexus.RouteDispatchNexusTaskByNamespaceAndTaskQueue.Path(commonnexus.NamespaceAndTaskQueue{
682+
Namespace: oc.namespaceName,
683+
TaskQueue: oc.taskQueue,
684+
}))
685+
}
686+
677687
if err != nil {
678688
oc.logger.Error("failed to forward Nexus request. error constructing ServiceBaseURL",
679689
tag.URL(httpClient.BaseURL()),

service/frontend/nexus_http_handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func (h *NexusHTTPHandler) nexusContextFromEndpoint(entry *persistencespb.NexusE
269269
nc.namespaceName = nsName.String()
270270
nc.taskQueue = v.Worker.GetTaskQueue()
271271
nc.endpointName = entry.Endpoint.Spec.Name
272+
nc.endpointID = entry.Id
272273
return nc, true
273274
default:
274275
h.writeNexusFailure(w, http.StatusBadRequest, &nexus.Failure{Message: "invalid endpoint target"})

0 commit comments

Comments
 (0)