Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/sdk/metric v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
go.temporal.io/api v1.53.1-0.20250930223154-d26cf6ca688f
go.temporal.io/api v1.54.1-0.20251016004347-cf9c3e8c6ed7
go.temporal.io/sdk v1.35.0
go.uber.org/fx v1.23.0
go.uber.org/mock v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
go.temporal.io/api v1.53.1-0.20250930223154-d26cf6ca688f h1:pSyTFJpS7c8FpoGA/JJ8Jc2aH8cDNYGW5//L9P0TAZE=
go.temporal.io/api v1.53.1-0.20250930223154-d26cf6ca688f/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
go.temporal.io/api v1.54.1-0.20251016004347-cf9c3e8c6ed7 h1:HnyFCXUWchiduyC1qav0Mt/w0q0Sva6t/JSa0Zw8jvQ=
go.temporal.io/api v1.54.1-0.20251016004347-cf9c3e8c6ed7/go.mod h1:iaxoP/9OXMJcQkETTECfwYq4cw/bj4nwov8b3ZLVnXM=
go.temporal.io/sdk v1.35.0 h1:lRNAQ5As9rLgYa7HBvnmKyzxLcdElTuoFJ0FXM/AsLQ=
go.temporal.io/sdk v1.35.0/go.mod h1:1q5MuLc2MEJ4lneZTHJzpVebW2oZnyxoIOWX3oFVebw=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down
2 changes: 2 additions & 0 deletions service/frontend/nexus_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (c *operationContext) capturePanicAndRecordMetrics(ctxPtr *context.Context,
}

func (c *operationContext) matchingRequest(req *nexuspb.Request) *matchingservice.DispatchNexusTaskRequest {
req.Endpoint = c.endpointName
return &matchingservice.DispatchNexusTaskRequest{
NamespaceId: c.namespace.ID().String(),
TaskQueue: &taskqueuepb.TaskQueue{Name: c.taskQueue, Kind: enumspb.TASK_QUEUE_KIND_NORMAL},
Expand Down Expand Up @@ -700,6 +701,7 @@ func (h *nexusHandler) nexusClientForActiveCluster(oc *operationContext, service
commonnexus.RouteDispatchNexusTaskByEndpoint.Path(oc.endpointID))
} else {
// Fallback to dispatch by namespace and task queue since those have already been resolved by this point.
// NOTE: When forwarding by namespace and task queue, the endpoint name is not preserved and cannot be provided to a worker polling.
baseURL, err = url.JoinPath(
httpClient.BaseURL(),
commonnexus.RouteDispatchNexusTaskByNamespaceAndTaskQueue.Path(commonnexus.NamespaceAndTaskQueue{
Expand Down
23 changes: 0 additions & 23 deletions service/frontend/workflow_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,29 +886,6 @@ func (wh *WorkflowHandler) PollWorkflowTaskQueue(ctx context.Context, request *w
childCtx := wh.registerOutstandingPollContext(ctx, pollerID, namespaceID.String())
defer wh.unregisterOutstandingPollContext(pollerID, namespaceID.String())

if request.WorkerHeartbeat != nil {
heartbeats := []*workerpb.WorkerHeartbeat{request.WorkerHeartbeat}
request.WorkerHeartbeat = nil // clear the heartbeat from the request to avoid sending it to matching service

// route heartbeat to the matching service only if the request is valid (all validation checks passed)
go func() {
_, err := wh.matchingClient.RecordWorkerHeartbeat(ctx, &matchingservice.RecordWorkerHeartbeatRequest{
NamespaceId: namespaceID.String(),
HeartbeartRequest: &workflowservice.RecordWorkerHeartbeatRequest{
Namespace: request.Namespace,
Identity: request.Identity,
WorkerHeartbeat: heartbeats,
},
})

if err != nil {
wh.logger.Error("Failed to record worker heartbeat.",
tag.WorkflowTaskQueueName(request.TaskQueue.GetName()),
tag.Error(err))
}
}()
}

matchingResp, err := wh.matchingClient.PollWorkflowTaskQueue(childCtx, &matchingservice.PollWorkflowTaskQueueRequest{
NamespaceId: namespaceID.String(),
PollerId: pollerID,
Expand Down
57 changes: 35 additions & 22 deletions tests/nexus_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ func (s *NexusApiTestSuite) TestNexusStartOperation_Outcomes() {
},
}
handlerNexusLink := nexusoperations.ConvertLinkWorkflowEventToNexusLink(handlerLink)
asyncSuccessEndpoint := testcore.RandomizeStr("test-endpoint")

type testcase struct {
name string
outcome string
endpoint *nexuspb.Endpoint
timeout time.Duration
handler func(*workflowservice.PollNexusTaskQueueResponse) (*nexuspb.Response, *nexuspb.HandlerError)
assertion func(*testing.T, *nexusrpc.ClientStartOperationResponse[string], error, http.Header)
name string
outcome string
endpoint *nexuspb.Endpoint
timeout time.Duration
handler func(*workflowservice.PollNexusTaskQueueResponse) (*nexuspb.Response, *nexuspb.HandlerError)
assertion func(*testing.T, *nexusrpc.ClientStartOperationResponse[string], error, http.Header)
onlyByEndpoint bool
}

testCases := []testcase{
Expand All @@ -109,12 +111,14 @@ func (s *NexusApiTestSuite) TestNexusStartOperation_Outcomes() {
},
},
{
name: "async_success",
outcome: "async_success",
endpoint: s.createNexusEndpoint(testcore.RandomizeStr("test-endpoint"), testcore.RandomizeStr("task-queue")),
name: "async_success",
outcome: "async_success",
onlyByEndpoint: true,
endpoint: s.createNexusEndpoint(asyncSuccessEndpoint, testcore.RandomizeStr("task-queue")),
handler: func(res *workflowservice.PollNexusTaskQueueResponse) (*nexuspb.Response, *nexuspb.HandlerError) {
// Choose an arbitrary test case to assert that all of the input is delivered to the
// poll response.
s.Equal(asyncSuccessEndpoint, res.Request.Endpoint)
start := res.Request.Variant.(*nexuspb.Request_StartOperation).StartOperation
s.Equal(op.Name(), start.Operation)
s.Equal("http://localhost/callback", start.Callback)
Expand Down Expand Up @@ -313,9 +317,11 @@ func (s *NexusApiTestSuite) TestNexusStartOperation_Outcomes() {

for _, tc := range testCases {
s.T().Run(tc.name, func(t *testing.T) {
t.Run("ByNamespaceAndTaskQueue", func(t *testing.T) {
testFn(t, tc, getDispatchByNsAndTqURL(s.HttpAPIAddress(), s.Namespace().String(), tc.endpoint.Spec.Target.GetWorker().TaskQueue))
})
if !tc.onlyByEndpoint {
t.Run("ByNamespaceAndTaskQueue", func(t *testing.T) {
testFn(t, tc, getDispatchByNsAndTqURL(s.HttpAPIAddress(), s.Namespace().String(), tc.endpoint.Spec.Target.GetWorker().TaskQueue))
})
}
t.Run("ByEndpoint", func(t *testing.T) {
testFn(t, tc, getDispatchByEndpointURL(s.HttpAPIAddress(), tc.endpoint.Id))
})
Expand Down Expand Up @@ -668,19 +674,24 @@ func (s *NexusApiTestSuite) TestNexusStartOperation_PayloadSizeLimit() {
}

func (s *NexusApiTestSuite) TestNexusCancelOperation_Outcomes() {
asyncSuccessEndpoint := testcore.RandomizeStr("async-success-endpoint")

type testcase struct {
outcome string
endpoint *nexuspb.Endpoint
timeout time.Duration
handler func(*workflowservice.PollNexusTaskQueueResponse) (*nexuspb.Response, *nexuspb.HandlerError)
assertion func(*testing.T, error, http.Header)
outcome string
onlyByEndpoint bool
endpoint *nexuspb.Endpoint
timeout time.Duration
handler func(*workflowservice.PollNexusTaskQueueResponse) (*nexuspb.Response, *nexuspb.HandlerError)
assertion func(*testing.T, error, http.Header)
}

testCases := []testcase{
{
outcome: "success",
endpoint: s.createNexusEndpoint(testcore.RandomizeStr("test-endpoint"), testcore.RandomizeStr("task-queue")),
outcome: "success",
onlyByEndpoint: true,
endpoint: s.createNexusEndpoint(asyncSuccessEndpoint, testcore.RandomizeStr("task-queue")),
handler: func(res *workflowservice.PollNexusTaskQueueResponse) (*nexuspb.Response, *nexuspb.HandlerError) {
s.Equal(asyncSuccessEndpoint, res.Request.Endpoint)
// Choose an arbitrary test case to assert that all of the input is delivered to the
// poll response.
op := res.Request.Variant.(*nexuspb.Request_CancelOperation).CancelOperation
Expand Down Expand Up @@ -795,9 +806,11 @@ func (s *NexusApiTestSuite) TestNexusCancelOperation_Outcomes() {

for _, tc := range testCases {
s.T().Run(tc.outcome, func(t *testing.T) {
t.Run("ByNamespaceAndTaskQueue", func(t *testing.T) {
testFn(t, tc, getDispatchByNsAndTqURL(s.HttpAPIAddress(), s.Namespace().String(), tc.endpoint.Spec.Target.GetWorker().TaskQueue))
})
if !tc.onlyByEndpoint {
t.Run("ByNamespaceAndTaskQueue", func(t *testing.T) {
testFn(t, tc, getDispatchByNsAndTqURL(s.HttpAPIAddress(), s.Namespace().String(), tc.endpoint.Spec.Target.GetWorker().TaskQueue))
})
}
t.Run("ByEndpoint", func(t *testing.T) {
testFn(t, tc, getDispatchByEndpointURL(s.HttpAPIAddress(), tc.endpoint.Id))
})
Expand Down
Loading