Skip to content

Lightweight scale controller package for Mssql backend#3395

Open
nytian wants to merge 3 commits intodevfrom
nytian/sc-pkg-sql
Open

Lightweight scale controller package for Mssql backend#3395
nytian wants to merge 3 commits intodevfrom
nytian/sc-pkg-sql

Conversation

@nytian
Copy link
Collaborator

@nytian nytian commented Mar 18, 2026

As titled. This PR adds support for MSSQL backend at the lightweight scale controller package

Copilot AI review requested due to automatic review settings March 18, 2026 16:50

var storageProvider = triggerMetadata.Metadata["storageProvider"] as JObject;
Assert.NotNull(storageProvider);
Assert.Equal("mssql", storageProvider["type"]?.ToString());
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds MSSQL (DurableTask.SqlServer) support to the FunctionsScale (“lightweight scale controller”) extension by introducing SQL Server-specific scalability provider components, wiring them into DI, and adding scale tests + CI coverage.

Changes:

  • Implemented SQL Server scale components (provider factory/provider, metrics provider, scale monitor, target scaler).
  • Registered the SQL Server scalability provider factory in the FunctionsScale extension and added the required NuGet dependency.
  • Added MSSQL scale tests and updated the scale-test GitHub workflow to run SQL Server-backed tests in CI.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScalabilityProviderFactory.cs Creates SQL Server scalability providers from trigger metadata/config; sets up orchestration service settings.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScalabilityProvider.cs Implements ScalabilityProvider for SQL Server and exposes scale monitor/target scaler.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerMetricsProvider.cs Queries SQL backend for recommended replica count with a small cache.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScaleMonitor.cs Implements IScaleMonitor<T> for SQL-based scaling decisions.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerTargetScaler.cs Implements ITargetScaler for SQL Server backend recommendations.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScaleMetric.cs Defines the SQL scale metric payload used by monitor/scaler.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/DurableTaskScaleConfigurationExtensions.cs Registers the SQL Server provider factory with the extension DI.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale.csproj Adds Microsoft.DurableTask.SqlServer package reference.
test/ScaleTests/Sql/SqlServerTestFixture.cs Shared fixture to initialize SQL task hub for tests.
test/ScaleTests/Sql/SqlServerTestCollection.cs xUnit collection definition for SQL Server tests.
test/ScaleTests/Sql/SqlServerTargetScalerTests.cs Integration-style tests validating target-based scaling against SQL Server.
test/ScaleTests/Sql/SqlServerScalabilityProviderFactoryTests.cs Tests for factory/provider creation and basic integration behavior.
.github/workflows/validate-build-scale.yml Splits ScaleTests into Azure Storage and MSSQL jobs; adds SQL Server container setup.
Comments suppressed due to low confidence (1)

.github/workflows/validate-build-scale.yml:30

  • The steps: list items are not indented under steps: (the - uses: line is at the same indentation level). This makes the workflow YAML invalid and will prevent the job from running. Indent all step items two spaces under steps:.
    steps:
    - uses: actions/checkout@v3
      with:
        submodules: true


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +25
private readonly SqlServerMetricsProvider metricsProvider;
private int? previousWorkerCount = -1;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI review requested due to automatic review settings March 18, 2026 22:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds MSSQL backend support to the FunctionsScale (lightweight scale controller) package by introducing a SQL Server scalability provider (factory + provider + metrics/scaler/monitor) and validating it with new ScaleTests and CI workflow coverage.

Changes:

  • Added MSSQL scalability provider implementation (factory/provider/metrics + target scaler + scale monitor/metric).
  • Registered the MSSQL provider factory in DI and added the required SqlServer package reference.
  • Added SQL Server scale tests (with xUnit collection fixture) and updated the scale-test GitHub Actions workflow to run MSSQL tests via Docker.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScalabilityProviderFactory.cs Creates MSSQL scalability providers and resolves SQL connection settings.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScalabilityProvider.cs Implements scale monitor/target scaler creation for MSSQL.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerMetricsProvider.cs Fetches/caches recommended replica counts from DurableTask.SqlServer.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerTargetScaler.cs Implements target-based scaling using MSSQL metrics.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScaleMonitor.cs Implements metrics-based scaling vote logic for MSSQL.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Sql/SqlServerScaleMetric.cs Defines MSSQL scale metric type used by the monitor.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale.csproj Adds Microsoft.DurableTask.SqlServer dependency.
src/Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale/DurableTaskScaleConfigurationExtensions.cs Registers the MSSQL provider factory with the Scale extension DI setup.
test/ScaleTests/Sql/SqlServerTestFixture.cs Adds shared fixture to create SQL DB/schema once for MSSQL scale tests.
test/ScaleTests/Sql/SqlServerTestCollection.cs Defines xUnit collection to serialize MSSQL tests and share the fixture.
test/ScaleTests/Sql/SqlServerTargetScalerTests.cs Integration test validating target worker count for pending orchestrations.
test/ScaleTests/Sql/SqlServerScalabilityProviderFactoryTests.cs Factory validation tests + basic integration coverage of scaler/monitor creation.
.github/workflows/validate-build-scale.yml Splits scale tests into Azure Storage + MSSQL jobs; provisions SQL Server container for MSSQL runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +84
await Task.Delay(2000);

Comment on lines +60 to +68
this.GetScaleStatusCore(context.WorkerCount, context.Metrics.Cast<SqlServerScaleMetric>());

/// <inheritdoc />
public ScaleStatus GetScaleStatus(ScaleStatusContext<SqlServerScaleMetric> context) =>
this.GetScaleStatusCore(context.WorkerCount, context.Metrics);

private ScaleStatus GetScaleStatusCore(int currentWorkerCount, IEnumerable<SqlServerScaleMetric> metrics)
{
SqlServerScaleMetric mostRecentMetric = metrics.LastOrDefault();
Comment on lines +44 to +57
public virtual async Task<SqlServerScaleMetric> GetMetricsAsync(int? previousWorkerCount = null)
{
// We only want to query the metrics every 5 seconds to avoid excessive SQL queries.
if (this.metrics == null || DateTime.UtcNow >= this.metricsTimeStamp.AddSeconds(5))
{
// 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);

this.metricsTimeStamp = DateTime.UtcNow;
this.metrics = new SqlServerScaleMetric { RecommendedReplicaCount = recommendedReplicaCount };
}

- name: Start Azurite
run: azurite --silent --blobPort 10000 --queuePort 10001 --tablePort 10002 &

Comment on lines +114 to +122
echo "Waiting for SQL Server to be ready..."
for i in {1..30}; do
if docker exec mssql-server /opt/mssql-tools*/bin/sqlcmd -S localhost -U sa -P "$MSSQL_SA_PASSWORD" -Q "SELECT 1" > /dev/null 2>&1; then
echo "SQL Server is ready"
break
fi
echo "SQL Server is not ready, waiting ($i/30)"
sleep 2
done
Comment on lines +11 to +12
/// instance, which creates the database/schema once before the first test and
/// tears it down after the last test in the collection completes.
using Microsoft.Azure.WebJobs.Host.Scale;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Moq;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants