-
Notifications
You must be signed in to change notification settings - Fork 34
Add target based scaling support for MSSQL #169
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 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fae10ca
initial commit
bachuv f4527f6
update csproj
bachuv a469297
added previousWorkerCount as argument for GetMetricsAsync()
bachuv 4b952a5
adding tests
bachuv 26dedfc
Merge branch 'main' into vabachu/tbs
cgillum c4498c4
PR feedback updates, fix build warnings, update CHANGELOG.md, etc.
cgillum b9d6891
Fix failing tests caused by version update
cgillum 830934f
PR feedback and minor cleanup
cgillum 994d78c
Merge branch 'main' into vabachu/tbs
cgillum 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
29 changes: 29 additions & 0 deletions
29
src/DurableTask.SqlServer.AzureFunctions/SqlMetricsProvider.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,29 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace DurableTask.SqlServer.AzureFunctions | ||
| { | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| public class SqlMetricsProvider | ||
| { | ||
| readonly SqlOrchestrationService service; | ||
|
|
||
| public SqlMetricsProvider(SqlOrchestrationService service, int? previousWorkerCount = null) | ||
|
bachuv marked this conversation as resolved.
Outdated
cgillum marked this conversation as resolved.
Outdated
|
||
| { | ||
| this.service = service; | ||
| } | ||
|
|
||
| public virtual async Task<SqlScaleMetric> GetMetricsAsync(int? previousWorkerCount = null) | ||
| { | ||
| // GetRecommendedReplicaCountAsync will write a trace if the recommendation results | ||
| // in a worker count that is different from the worker count we pass in as an argument. | ||
| int recommendedReplicaCount = await this.service.GetRecommendedReplicaCountAsync( | ||
| previousWorkerCount, | ||
| CancellationToken.None); | ||
|
|
||
| return new SqlScaleMetric { RecommendedReplicaCount = recommendedReplicaCount }; | ||
|
bachuv marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
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
32 changes: 32 additions & 0 deletions
32
src/DurableTask.SqlServer.AzureFunctions/SqlTargetScaler.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,32 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace DurableTask.SqlServer.AzureFunctions | ||
| { | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Azure.WebJobs.Host.Scale; | ||
|
|
||
| #if !NETSTANDARD | ||
| public class SqlTargetScaler : ITargetScaler | ||
| { | ||
| readonly SqlMetricsProvider sqlMetricsProvider; | ||
| readonly TargetScalerResult scaleResult; | ||
|
cgillum marked this conversation as resolved.
Outdated
|
||
|
|
||
| public SqlTargetScaler(string functionId, SqlMetricsProvider sqlMetricsProvider) | ||
| { | ||
| this.sqlMetricsProvider = sqlMetricsProvider; | ||
| this.scaleResult = new TargetScalerResult(); | ||
| this.TargetScalerDescriptor = new TargetScalerDescriptor(functionId); | ||
| } | ||
|
|
||
| public TargetScalerDescriptor TargetScalerDescriptor { get; private set; } | ||
|
cgillum marked this conversation as resolved.
Outdated
|
||
|
|
||
| public async Task<TargetScalerResult> GetScaleResultAsync(TargetScalerContext context) | ||
| { | ||
| SqlScaleMetric sqlScaleMetric = await this.sqlMetricsProvider.GetMetricsAsync(); | ||
| this.scaleResult.TargetWorkerCount = sqlScaleMetric.RecommendedReplicaCount; | ||
| return this.scaleResult; | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
test/DurableTask.SqlServer.AzureFunctions.Tests/TargetBasedScalingTests.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,59 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace DurableTask.SqlServer.AzureFunctions.Tests | ||
| { | ||
| using System; | ||
| using DurableTask.Core; | ||
| using Microsoft.Azure.WebJobs.Extensions.DurableTask; | ||
| using Microsoft.Azure.WebJobs.Host.Scale; | ||
| using Microsoft.Extensions.Logging; | ||
| using Moq; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| public class TargetBasedScalingTests | ||
| { | ||
| readonly Mock<SqlMetricsProvider> metricsProviderMock; | ||
| readonly Mock<IOrchestrationService> orchestrationServiceMock; | ||
|
|
||
| public TargetBasedScalingTests() | ||
| { | ||
| this.orchestrationServiceMock = new Mock<IOrchestrationService>(MockBehavior.Strict); | ||
|
|
||
| this.metricsProviderMock = new Mock<SqlMetricsProvider>( | ||
| MockBehavior.Strict, | ||
| null, | ||
| null); | ||
|
cgillum marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(0)] | ||
| [InlineData(10)] | ||
| [InlineData(20)] | ||
| public async void TargetBasedScalingTest(int expectedTargetWorkerCount) | ||
|
cgillum marked this conversation as resolved.
|
||
| { | ||
| var durabilityProviderMock = new Mock<DurabilityProvider>( | ||
| MockBehavior.Strict, | ||
| "storageProviderName", | ||
| this.orchestrationServiceMock.Object, | ||
| new Mock<IOrchestrationServiceClient>().Object, | ||
| "connectionName"); | ||
|
|
||
| SqlScaleMetric sqlScaleMetric = new SqlScaleMetric() | ||
| { | ||
| RecommendedReplicaCount = expectedTargetWorkerCount, | ||
| }; | ||
|
|
||
| this.metricsProviderMock.Setup(m => m.GetMetricsAsync(null)).ReturnsAsync(sqlScaleMetric); | ||
|
|
||
| SqlTargetScaler targetScaler = new SqlTargetScaler( | ||
| "functionId", | ||
| this.metricsProviderMock.Object); | ||
|
|
||
| TargetScalerResult result = await targetScaler.GetScaleResultAsync(new TargetScalerContext()); | ||
|
|
||
| Assert.Equal(expectedTargetWorkerCount, result.TargetWorkerCount); | ||
| } | ||
| } | ||
| } | ||
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.