-
Notifications
You must be signed in to change notification settings - Fork 284
Introduce worker versioning into durable functions #3095
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1fc0271
Introduce worker versioning into durable functions
halspang eb3029f
Update sub-orchestration to use defaultVersion
halspang 7b9c6a7
Update dependencies to new releases
halspang ff16aaf
Update tests and copy constructor
halspang 64ccbb9
Add TODO for copy constructor
halspang 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| # The following files were downloaded from branch main at 2025-06-05 21:25:17 UTC | ||
| https://raw.githubusercontent.com/microsoft/durabletask-protobuf/fd9369c6a03d6af4e95285e432b7c4e943c06970/protos/orchestrator_service.proto | ||
| https://raw.githubusercontent.com/microsoft/durabletask-protobuf/fd9369c6a03d6af4e95285e432b7c4e943c06970/protos/orchestrator_service.proto |
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
120 changes: 120 additions & 0 deletions
120
test/e2e/Apps/BasicDotNetIsolated/VersionedOrchestration.cs
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,120 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Azure.Functions.Worker.Http; | ||
| using Microsoft.DurableTask; | ||
| using Microsoft.DurableTask.Client; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.Azure.Durable.Tests.E2E; | ||
|
|
||
| public static class VersionedOrchestration | ||
| { | ||
| [Function(nameof(VersionedOrchestration))] | ||
| public static async Task<string> RunOrchestrator( | ||
| [OrchestrationTrigger] TaskOrchestrationContext context) | ||
| { | ||
| ILogger logger = context.CreateReplaySafeLogger(nameof(VersionedOrchestration)); | ||
| logger.LogInformation($"Versioned orchestration! Version: '{context.Version}'"); | ||
|
|
||
| return await context.CallActivityAsync<string>(nameof(SayVersion), context.Version); | ||
| } | ||
|
|
||
| [Function(nameof(RunWithSubOrchestrator))] | ||
| public static async Task<string> RunWithSubOrchestrator( | ||
| [OrchestrationTrigger] TaskOrchestrationContext context, | ||
| string? subVersion) | ||
| { | ||
| ILogger logger = context.CreateReplaySafeLogger(nameof(VersionedOrchestration)); | ||
| logger.LogInformation($"Versioned orchestration! Version: '{context.Version}' Sub Version: '{subVersion}'"); | ||
|
|
||
| string subOrchestrationResponse; | ||
| if (subVersion == null) | ||
| { | ||
| subOrchestrationResponse = await context.CallSubOrchestratorAsync<string>(nameof(VersionedSubOrchestration)); | ||
| } | ||
| else | ||
| { | ||
| subOrchestrationResponse = await context.CallSubOrchestratorAsync<string>(nameof(VersionedSubOrchestration), new SubOrchestrationOptions | ||
| { | ||
| Version = subVersion, | ||
| }); | ||
| } | ||
| return $"Parent Version: '{context.Version}' | Sub {subOrchestrationResponse}"; | ||
| } | ||
|
|
||
| [Function(nameof(VersionedSubOrchestration))] | ||
| public static async Task<string> VersionedSubOrchestration([OrchestrationTrigger] TaskOrchestrationContext context) | ||
| { | ||
| ILogger logger = context.CreateReplaySafeLogger(nameof(VersionedOrchestration)); | ||
| logger.LogInformation($"Versioned sub-orchestration! Version: '{context.Version}'"); | ||
|
|
||
| return await context.CallActivityAsync<string>(nameof(SayVersion), context.Version); | ||
| } | ||
|
|
||
| [Function(nameof(SayVersion))] | ||
| public static string SayVersion([ActivityTrigger] string version, FunctionContext executionContext) | ||
| { | ||
| ILogger logger = executionContext.GetLogger("SayVersion"); | ||
| logger.LogInformation("Activity running with version: {name}.", version); | ||
| return $"Version: '{version}'"; | ||
| } | ||
|
|
||
| [Function("OrchestrationVersion_HttpStart")] | ||
| public static async Task<HttpResponseData> HttpStart( | ||
| [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req, | ||
| [DurableClient] DurableTaskClient client, | ||
| FunctionContext executionContext, | ||
| string? version) | ||
| { | ||
| ILogger logger = executionContext.GetLogger("VersionedOrchestration_HttpStart"); | ||
|
|
||
| // Function input comes from the request content. | ||
| string instanceId; | ||
| if (version != null) | ||
| { | ||
| instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(VersionedOrchestration), new StartOrchestrationOptions | ||
| { | ||
| Version = version, | ||
| }); | ||
| } | ||
| else | ||
| { | ||
| instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(VersionedOrchestration)); | ||
| } | ||
|
|
||
| logger.LogInformation("Started orchestration with ID = '{instanceId}' and Version = '{version}'.", instanceId, version); | ||
|
|
||
| // Returns an HTTP 202 response with an instance management payload. | ||
| // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration | ||
| return await client.CreateCheckStatusResponseAsync(req, instanceId); | ||
| } | ||
|
|
||
| [Function("OrchestrationSubVersion_HttpStart")] | ||
| public static async Task<HttpResponseData> HttpSubStart( | ||
| [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req, | ||
| [DurableClient] DurableTaskClient client, | ||
| FunctionContext executionContext, | ||
| string? subOrchestrationVersion) | ||
| { | ||
| ILogger logger = executionContext.GetLogger("OrchestrationSubVersion_HttpStart"); | ||
|
|
||
| // Function input comes from the request content. | ||
| string instanceId; | ||
| if (subOrchestrationVersion != null) | ||
| { | ||
| instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(RunWithSubOrchestrator), input: subOrchestrationVersion); | ||
| } | ||
| else | ||
| { | ||
| instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(RunWithSubOrchestrator)); | ||
| } | ||
|
|
||
| logger.LogInformation("Started orchestration with ID = '{instanceId}' and Version = '{subOrchestrationVersion}'.", instanceId, subOrchestrationVersion); | ||
|
|
||
| // Returns an HTTP 202 response with an instance management payload. | ||
| // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration | ||
| return await client.CreateCheckStatusResponseAsync(req, instanceId); | ||
| } | ||
| } |
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,87 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.Net; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Azure.Durable.Tests.DotnetIsolatedE2E; | ||
|
|
||
| [Collection(Constants.FunctionAppCollectionName)] | ||
| public class VersioningTests | ||
| { | ||
| private readonly FunctionAppFixture _fixture; | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public VersioningTests(FunctionAppFixture fixture, ITestOutputHelper testOutputHelper) | ||
| { | ||
| _fixture = fixture; | ||
| _fixture.TestLogs.UseTestLogger(testOutputHelper); | ||
| _output = testOutputHelper; | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(null)] // Represents a non-versioned case. | ||
| [InlineData("")] // Non-versioned/empty-versioned case. | ||
| [InlineData("1.0")] | ||
| [InlineData("2.0")] | ||
| public async Task TestVersionedOrchestration_OKWithMatchingVersion(string? version) | ||
| { | ||
| string queryString = version == null ? string.Empty : $"?version={version}"; | ||
| using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("OrchestrationVersion_HttpStart", queryString); | ||
|
|
||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUriAsync(response); | ||
|
|
||
| await DurableHelpers.WaitForOrchestrationStateAsync(statusQueryGetUri, "Completed", 30); | ||
|
|
||
| var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(statusQueryGetUri); | ||
| if (version != null) | ||
| { | ||
| Assert.Equal($"Version: '{version}'", orchestrationDetails.Output); | ||
| } | ||
| else | ||
| { | ||
| // The default version (2.0) from the host.json file should've been used here. | ||
| Assert.Equal("Version: '2.0'", orchestrationDetails.Output); | ||
| } | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(null)] // Represents a non-versioned case. | ||
| [InlineData("")] // Non-versioned/empty-versioned case. | ||
| [InlineData("1.0")] | ||
| [InlineData("2.0")] | ||
| public async Task TestVersionedSubOrchestration_OKWithMatchingVersion(string? subOrchestrationVersion) | ||
| { | ||
| string queryString = subOrchestrationVersion == null ? string.Empty : $"?subOrchestrationVersion={subOrchestrationVersion}"; | ||
| using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("OrchestrationSubVersion_HttpStart", queryString); | ||
|
|
||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUriAsync(response); | ||
|
|
||
| await DurableHelpers.WaitForOrchestrationStateAsync(statusQueryGetUri, "Completed", 30); | ||
|
|
||
| var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(statusQueryGetUri); | ||
| if (subOrchestrationVersion != null) | ||
| { | ||
| Assert.Equal($"Parent Version: '2.0' | Sub Version: '{subOrchestrationVersion}'", orchestrationDetails.Output); | ||
| } | ||
| else | ||
| { | ||
| // The default version (2.0) from the host.json file should've been used here. | ||
| Assert.Equal("Parent Version: '2.0' | Sub Version: '2.0'", orchestrationDetails.Output); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestVersionedOrchestration_FailsWithNonMatchingVersion() | ||
| { | ||
| using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("OrchestrationVersion_HttpStart", $"?version=3.0"); | ||
|
|
||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUriAsync(response); | ||
|
|
||
| await DurableHelpers.WaitForOrchestrationStateAsync(statusQueryGetUri, "Failed", 30); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.