-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add Nexus Worker interceptor #2278
Merged
Quinn-With-Two-Ns
merged 11 commits into
temporalio:master
from
Quinn-With-Two-Ns:issue-2220v2
Dec 6, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e1beb6a
Add Nexus Worker interceptor
Quinn-With-Two-Ns 45f9608
Switch to middleware approach
Quinn-With-Two-Ns 38d1a57
Update to new API
Quinn-With-Two-Ns 9ce980a
Run spotless
Quinn-With-Two-Ns 77bc027
update traces
Quinn-With-Two-Ns 04ea9c1
switch from . to /
Quinn-With-Two-Ns 7ed7c9d
update nexus sdk
Quinn-With-Two-Ns b6e8ba6
Refactor test tracer for consistency
Quinn-With-Two-Ns dd9c3b2
Disable CancelAsyncOperationTest on real server for now
Quinn-With-Two-Ns 639cc8f
Run spotless
Quinn-With-Two-Ns 8d7b91d
fix assume
Quinn-With-Two-Ns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# **💥 BREAKING CHANGES** | ||
|
||
## Update With Start **(Pre-release)** | ||
|
||
### WorkflowClient | ||
|
||
- `WorkflowClient.updateWithStart` has been renamed to `WorkflowClient.startUpdateWithStart`. | ||
- Instead of taking the workflow method, workflow arguments and a `UpdateWithStartWorkflowOperation` , `WorkflowClient.startUpdateWithStart` now takes the update method, update arguments and a `WithStartWorkflowOperation` . `WithStartWorkflowOperation` holds to the workflow method and workflow arguments to be executed together with the update request. | ||
|
||
### WorkflowStub | ||
|
||
- `WorkflowStub.updateWithStart` has been renamed to `WorkflowStub.startUpdateWithStart` | ||
- `WorkflowStub.startUpdateWithStart` now just takes the `UpdateOptions`, update arguments and workflow arguments | ||
|
||
## Update **(Public Preview)** | ||
|
||
- The SDK now preforms more rigorous type validation when registering a Workflow with an `@UpdateValidatorMethod` to make sure the type parameters match the linked `@UpdateMethod` | ||
- The SDK will no longer sometimes throw `WorkflowUpdateException` when calling `WorkflowStub.startUpdate` if the update is rejected. `WorkflowUpdateException` is now consistently throw when getting the result of the update | ||
- `UpdateOptionsBuilder` no longer generates a update ID when built. Now a unique UUID is generated when the options are used. This is similar to how `WorkflowOptions` and workflow ID work. | ||
|
||
## Nexus **(Public Preview)** | ||
|
||
- Workflow started by a Nexus operation now require the Workflow ID to be specified | ||
- The SDK now preforms more rigorous type validation when registering a Nexus Service to make sure it implements the service properly | ||
- All header maps for Nexus operations are now properly case-insensitive. | ||
|
||
# **Highlights** | ||
|
||
## Virtual Threads **(Public Preview)** | ||
|
||
The Java SDK now has experimental support for virtual threads when using a JVM with a version of 21 or higher. Virtual threads can be used inside workflows by enabling `WorkerFactoryOptions.setUsingVirtualWorkflowThreads` . Users can also use virtual threads for task processing in a worker by enabling `WorkerOptions.setUsingVirtualThreads` . | ||
|
||
## Nexus **(Public Preview)** | ||
|
||
`WorkerInterceptor` now has support for intercepting Nexus workers. | ||
|
||
## Update **(Public Preview)** | ||
|
||
`WorkflowClient` now has a set of static methods called `startUpdate` that can be used to start an update, but not immediately wait on the result. This is a type safe analog to `WorkflowStub.startUpdate`. | ||
|
||
## Workflow Metadata **(Public Preview)** | ||
|
||
- The Java SDK now exposes a fixed summary option for local and normal activities. | ||
- The Java SDK now support `__temporal_workflow_metadata` query, this query allows users to get details about a workflow like its’ current description and what signal, update, and query handlers are registered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...va/io/temporal/opentracing/internal/OpenTracingNexusOperationInboundCallsInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.opentracing.internal; | ||
|
||
import io.nexusrpc.OperationUnsuccessfulException; | ||
import io.opentracing.Scope; | ||
import io.opentracing.Span; | ||
import io.opentracing.SpanContext; | ||
import io.opentracing.Tracer; | ||
import io.temporal.common.interceptors.NexusOperationInboundCallsInterceptor; | ||
import io.temporal.common.interceptors.NexusOperationInboundCallsInterceptorBase; | ||
import io.temporal.opentracing.OpenTracingOptions; | ||
|
||
public class OpenTracingNexusOperationInboundCallsInterceptor | ||
extends NexusOperationInboundCallsInterceptorBase { | ||
private final OpenTracingOptions options; | ||
private final SpanFactory spanFactory; | ||
private final Tracer tracer; | ||
private final ContextAccessor contextAccessor; | ||
|
||
public OpenTracingNexusOperationInboundCallsInterceptor( | ||
NexusOperationInboundCallsInterceptor next, | ||
OpenTracingOptions options, | ||
SpanFactory spanFactory, | ||
ContextAccessor contextAccessor) { | ||
super(next); | ||
this.options = options; | ||
this.spanFactory = spanFactory; | ||
this.tracer = options.getTracer(); | ||
this.contextAccessor = contextAccessor; | ||
} | ||
|
||
@Override | ||
public StartOperationOutput startOperation(StartOperationInput input) | ||
throws OperationUnsuccessfulException { | ||
SpanContext rootSpanContext = | ||
contextAccessor.readSpanContextFromHeader(input.getOperationContext().getHeaders(), tracer); | ||
|
||
Span operationStartSpan = | ||
spanFactory | ||
.createStartNexusOperationSpan( | ||
tracer, | ||
input.getOperationContext().getService(), | ||
input.getOperationContext().getOperation(), | ||
rootSpanContext) | ||
.start(); | ||
try (Scope scope = tracer.scopeManager().activate(operationStartSpan)) { | ||
return super.startOperation(input); | ||
} catch (Throwable t) { | ||
spanFactory.logFail(operationStartSpan, t); | ||
throw t; | ||
} finally { | ||
operationStartSpan.finish(); | ||
} | ||
} | ||
|
||
@Override | ||
public CancelOperationOutput cancelOperation(CancelOperationInput input) { | ||
SpanContext rootSpanContext = | ||
contextAccessor.readSpanContextFromHeader(input.getOperationContext().getHeaders(), tracer); | ||
|
||
Span operationCancelSpan = | ||
spanFactory | ||
.createCancelNexusOperationSpan( | ||
tracer, | ||
input.getOperationContext().getService(), | ||
input.getOperationContext().getOperation(), | ||
rootSpanContext) | ||
.start(); | ||
try (Scope scope = tracer.scopeManager().activate(operationCancelSpan)) { | ||
return super.cancelOperation(input); | ||
} catch (Throwable t) { | ||
spanFactory.logFail(operationCancelSpan, t); | ||
throw t; | ||
} finally { | ||
operationCancelSpan.finish(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remind me again when this
finally
block is hit in Java? Is this after the operation completes or after the request to schedule it has been sent?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.
After the request to schedule it has been sent, we do the same thing for activities and child workflows in the Java SDK open tracing interceptor