-
Notifications
You must be signed in to change notification settings - Fork 55
Wangbill/serverless private preview op1 #734
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
Draft
YunchuWang
wants to merge
43
commits into
main
Choose a base branch
from
wangbill/serverless-private-preview-op1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
6723dde
Add remote activity SDK APIs
YunchuWang 05223b6
Add remote activity worker profiles
YunchuWang ce8c38c
serverless pkg
YunchuWang 8d96663
remove launchcommand
YunchuWang 6dc7d23
separate declare from conneect
YunchuWang a94c91c
logcleanup
YunchuWang a1a03d8
use grpc retry
YunchuWang f58cd4d
inflight activity tracker
YunchuWang 48f7284
serverless connection resilient
YunchuWang 7c94c39
completeasync
YunchuWang cfa428e
add jitter
YunchuWang 11a7914
dup headers
YunchuWang 821069a
make taskhub metadata opt-out
YunchuWang 1077961
Add serverless sandbox list and log APIs
YunchuWang e1433f2
remove declarat
YunchuWang 4891155
Add serverless activities sample
YunchuWang 42b6153
Remove serverless sample no-auth credential
YunchuWang 71c9359
Simplify serverless sample auth and HTTP helper
YunchuWang 55c9e36
Remove insecure credential sample wiring
YunchuWang 560557c
simple serverless sample
YunchuWang 2ca9681
Simplify serverless sample dashboard flow
YunchuWang dfede69
cleanup
YunchuWang 81a603c
sync proto
YunchuWang 18c8e02
remove env var
YunchuWang d5dcc19
Revert "remove env var"
YunchuWang 408ee71
Enhance serverless worker registration and configuration
YunchuWang 008a416
Remove serverless wakeup listener
YunchuWang a60e43a
Split serverless worker runtime options
YunchuWang ee477ac
Refactor serverless options and improve activity registration methods
YunchuWang 098983a
remove public pull
YunchuWang 44ee2e5
Enable annotation-based serverless declarations
YunchuWang 7188bb8
Simplify serverless sample; move worker profile
YunchuWang 5f431e3
Validate and resolve serverless activity annotations
YunchuWang 46ce48b
Disallow EnableServerlessActivities in worker
YunchuWang dcbb904
Refactor serverless annotation resolution
YunchuWang 862f5f2
Resolve and validate declared serverless activities
YunchuWang d907e31
Serverless: use appsettings and remove marker
YunchuWang f05c6b3
Inline task name resolver; remove helper class
YunchuWang cf26c58
Rename annotation resolver to declaration
YunchuWang d4373e6
Use attributes for serverless activity declarations
YunchuWang ae1f0d1
Use AddActivity for serverless declarations
YunchuWang b6faacd
Fail serverless worker without activities
YunchuWang d71f765
Harden serverless worker runtime defaults
YunchuWang 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,71 @@ | ||
| # Serverless Activities Sample | ||
|
|
||
| This sample shows how to run selected Durable Task activities in DTS-managed serverless sandboxes. | ||
|
|
||
| The sample is intentionally split into two projects: | ||
|
|
||
| | Path | Purpose | | ||
| | --- | --- | | ||
| | `shared/` | Defines activity name constants shared by the main app and remote worker. | | ||
| | `main-app/` | Runs locally or in a normal app host. It declares the serverless activity and starts one hello orchestration. | | ||
| | `remote-worker/` | Builds the container image that DTS starts inside a serverless sandbox. It contains the remote hello activity. | | ||
|
|
||
| ## Build | ||
|
|
||
| ```powershell | ||
| dotnet build .\samples\serverless\main-app\main-app.csproj | ||
| dotnet build .\samples\serverless\remote-worker\remote-worker.csproj | ||
| ``` | ||
|
|
||
| ## Build the remote worker image | ||
|
|
||
| Run from the repository root: | ||
|
|
||
| ```powershell | ||
| $image = "<acr-name>.azurecr.io/dts-serverless-sample:<tag>" | ||
| docker build -f .\samples\serverless\remote-worker\Containerfile -t $image . | ||
| docker push $image | ||
| ``` | ||
|
|
||
| ## Run a hello orchestration | ||
|
|
||
| The main app uses `DefaultAzureCredential`; sign in with Azure CLI or configure another supported Azure identity before running it. | ||
| After pushing the remote worker image, set `ContainerImage` in | ||
| `main-app/WorkerProfiles.cs` to the pushed image reference. The worker profile | ||
| class declares the image, CPU, memory, max concurrency, and serverless activity | ||
| names with `options.AddActivity(...)`. The main app and remote worker both use | ||
| the `shared/ActivityNames.cs` constants so the declaration and worker registration | ||
| stay in sync. | ||
|
|
||
| Update `main-app/appsettings.json` with your scheduler endpoint and task hub: | ||
|
|
||
| ```json | ||
| { | ||
| "ServerlessSample": { | ||
| "EndpointAddress": "https://<scheduler-endpoint>", | ||
| "TaskHubName": "ServerlessPocHub" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Then run the main app: | ||
|
|
||
| ```powershell | ||
| Push-Location .\samples\serverless\main-app | ||
| dotnet run | ||
| Pop-Location | ||
| ``` | ||
|
|
||
| Expected output includes the serverless activity result: | ||
|
|
||
| ```text | ||
| Runtime status: Completed | ||
| Output: "hello locally: serverless-sample; hello remotely from <sandbox> pid=<pid>: serverless-sample" | ||
| ``` | ||
|
|
||
| Use the Durable Task Scheduler dashboard's Serverless Activities preview tab to inspect serverless activity runtimes and stream runtime logs. | ||
|
|
||
| The remote worker image does not need customer-provided DTS runtime settings. | ||
| DTS injects the scheduler endpoint, task hub, worker profile, capacity, substrate, | ||
| and sandbox identifier when it starts the sandbox. The worker reports the | ||
| activities registered in the image when it connects. |
This file contains hidden or 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,18 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.DurableTask.Samples.Serverless.MainApp; | ||
|
|
||
| internal static class ServerlessTaskNames | ||
| { | ||
| public const string LocalHello = "LocalHello"; | ||
| public const string HelloOrchestrator = nameof(HelloOrchestrator); | ||
| } | ||
|
|
||
| [DurableTask(ServerlessTaskNames.LocalHello)] | ||
| internal sealed class LocalHelloActivity : TaskActivity<string, string> | ||
| { | ||
| public override Task<string> RunAsync(TaskActivityContext context, string input) | ||
| => Task.FromResult($"hello locally: {input}"); | ||
| } | ||
|
|
This file contains hidden or 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,18 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.DurableTask; | ||
| using Microsoft.DurableTask.Samples.Serverless.Shared; | ||
|
|
||
| namespace Microsoft.DurableTask.Samples.Serverless.MainApp; | ||
|
|
||
| [DurableTask(nameof(HelloOrchestrator))] | ||
| internal sealed class HelloOrchestrator : TaskOrchestrator<string, string> | ||
| { | ||
| public override async Task<string> RunAsync(TaskOrchestrationContext context, string input) | ||
| { | ||
| string localResult = await context.CallActivityAsync<string>(ServerlessTaskNames.LocalHello, input); | ||
| string remoteResult = await context.CallActivityAsync<string>(ActivityNames.RemoteHello, input); | ||
| return $"{localResult}; {remoteResult}"; | ||
| } | ||
| } |
This file contains hidden or 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,69 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Core; | ||
| using Azure.Identity; | ||
| using Microsoft.DurableTask; | ||
| using Microsoft.DurableTask.Client; | ||
| using Microsoft.DurableTask.Client.AzureManaged; | ||
| using Microsoft.DurableTask.Samples.Serverless.MainApp; | ||
| using Microsoft.DurableTask.Worker; | ||
| using Microsoft.DurableTask.Worker.AzureManaged; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| const string Input = "serverless-sample"; | ||
|
|
||
| HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); | ||
| string endpoint = builder.Configuration["ServerlessSample:EndpointAddress"]!; | ||
| string taskHub = builder.Configuration["ServerlessSample:TaskHubName"]!; | ||
| TokenCredential credential = new DefaultAzureCredential(); | ||
| builder.Logging.AddSimpleConsole(options => | ||
| { | ||
| options.SingleLine = true; | ||
| options.UseUtcTimestamp = true; | ||
| options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ "; | ||
| }); | ||
|
|
||
| builder.Services.AddDurableTaskWorker(workerBuilder => | ||
| { | ||
| workerBuilder.AddTasks(tasks => tasks.AddAllGeneratedTasks()); | ||
| workerBuilder.UseDurableTaskScheduler(options => | ||
| { | ||
| options.EndpointAddress = endpoint; | ||
| options.TaskHubName = taskHub; | ||
| options.Credential = credential; | ||
| }); | ||
|
|
||
| workerBuilder.EnableServerlessActivities(); | ||
| }); | ||
|
|
||
| builder.Services.AddDurableTaskClient(clientBuilder => | ||
| { | ||
| clientBuilder.UseDurableTaskScheduler(options => | ||
| { | ||
| options.EndpointAddress = endpoint; | ||
| options.TaskHubName = taskHub; | ||
| options.Credential = credential; | ||
| }); | ||
| }); | ||
|
|
||
| using IHost host = builder.Build(); | ||
|
|
||
| await host.StartAsync(); | ||
|
|
||
| DurableTaskClient client = host.Services.GetRequiredService<DurableTaskClient>(); | ||
| string instanceId = await client.ScheduleNewOrchestrationInstanceAsync( | ||
| ServerlessTaskNames.HelloOrchestrator, | ||
| input: Input); | ||
| OrchestrationMetadata? result = await client.WaitForInstanceCompletionAsync( | ||
| instanceId, | ||
| getInputsAndOutputs: true); | ||
|
|
||
| Console.WriteLine($"Started orchestration: {instanceId}"); | ||
| Console.WriteLine($"Runtime status: {result?.RuntimeStatus}"); | ||
| Console.WriteLine($"Output: {result?.SerializedOutput ?? "<null>"}"); | ||
|
|
||
| await host.StopAsync(); | ||
This file contains hidden or 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,20 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.DurableTask.Worker.AzureManaged.Serverless; | ||
| using Microsoft.DurableTask.Samples.Serverless.Shared; | ||
|
|
||
| namespace Microsoft.DurableTask.Samples.Serverless.MainApp; | ||
|
|
||
| [ServerlessWorkerProfile("default")] | ||
| internal sealed class DefaultServerlessWorkerProfile : IServerlessWorkerProfile | ||
| { | ||
| public void Configure(ServerlessOptions options) | ||
| { | ||
| options.ContainerImage = Environment.GetEnvironmentVariable("DTS_SERVERLESS_CONTAINER_IMAGE") ?? "serverless-remote-worker:local"; | ||
| options.Cpu = "1000m"; | ||
| options.Memory = "2048Mi"; | ||
| options.MaxConcurrentActivities = 1; | ||
| options.AddActivity(ActivityNames.RemoteHello); | ||
| } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| { | ||
| "ServerlessSample": { | ||
| "EndpointAddress": "https://<scheduler-endpoint>", | ||
| "TaskHubName": "ServerlessPocHub" | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <AssemblyName>ServerlessMainApp</AssemblyName> | ||
| <RootNamespace>Microsoft.DurableTask.Samples.Serverless.MainApp</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(SrcRoot)Client/AzureManaged/Client.AzureManaged.csproj" /> | ||
| <ProjectReference Include="$(SrcRoot)Worker/AzureManaged/Worker.AzureManaged.csproj" /> | ||
| <ProjectReference Include="$(SrcRoot)Extensions/AzureManagedServerless/AzureManagedServerless.csproj" /> | ||
| <ProjectReference Include="..\shared\shared.csproj" /> | ||
| <ProjectReference Include="$(SrcRoot)Analyzers/Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="$(SrcRoot)Generators/Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,16 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.DurableTask; | ||
| using Microsoft.DurableTask.Samples.Serverless.Shared; | ||
|
|
||
| namespace Microsoft.DurableTask.Samples.Serverless.RemoteWorker; | ||
|
|
||
| [DurableTask(ActivityNames.RemoteHello)] | ||
| internal sealed class RemoteHelloActivity : TaskActivity<string, string> | ||
| { | ||
| public override Task<string> RunAsync(TaskActivityContext context, string input) | ||
| { | ||
| return Task.FromResult($"hello remotely from {Environment.MachineName} pid={Environment.ProcessId}: {input}"); | ||
| } | ||
| } |
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.
why add this console? we really need this?