Skip to content

Commit

Permalink
Use consistent scaler IDs for target-based and scale monitor implemen…
Browse files Browse the repository at this point in the history
…tations (v3) (#2980)

Also fixed flakey integration test
  • Loading branch information
cgillum authored Dec 3, 2024
1 parent e8133bd commit 93eddb6
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ internal DurableTaskMetricsProvider GetMetricsProvider(
return new DurableTaskMetricsProvider(hubName, logger, performanceMonitor: null, storageAccountClientProvider);
}

// Common routine for getting the scaler ID. Note that we MUST use the same ID for both the
// scale monitor and the target scaler.
private static string GetScalerUniqueId(string hubName)
{
return $"DurableTask-AzureStorage:{hubName ?? "default"}";
}

/// <inheritdoc/>
public override bool TryGetScaleMonitor(
string functionId,
Expand All @@ -246,11 +253,17 @@ public override bool TryGetScaleMonitor(
{
if (this.singletonScaleMonitor == null)
{
StorageAccountClientProvider storageAccountClientProvider = this.clientProviderFactory.GetClientProvider(connectionName);
DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(hubName, storageAccountClientProvider, this.logger);
DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(
hubName,
this.clientProviderFactory.GetClientProvider(connectionName),
this.logger);

// Scalers in Durable Functions are shared for all functions in the same task hub.
// So instead of using a function ID, we use the task hub name as the basis for the descriptor ID.
string id = GetScalerUniqueId(hubName);
this.singletonScaleMonitor = new DurableTaskScaleMonitor(
id,
hubName,
storageAccountClientProvider,
this.logger,
metricsProvider);
}
Expand All @@ -272,12 +285,14 @@ public override bool TryGetTargetScaler(
if (this.singletonTargetScaler == null)
{
// This is only called by the ScaleController, it doesn't run in the Functions Host process.
StorageAccountClientProvider storageAccountClientProvider = this.clientProviderFactory.GetClientProvider(connectionName);
DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(hubName, storageAccountClientProvider, this.logger);
DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(
hubName,
this.clientProviderFactory.GetClientProvider(connectionName),
this.logger);

// Scalers in Durable Functions are shared for all functions in the same task hub.
// So instead of using a function ID, we use the task hub name as the basis for the descriptor ID.
string id = $"DurableTask-AzureStorage:{hubName ?? "default"}";
string id = GetScalerUniqueId(hubName);
this.singletonTargetScaler = new DurableTaskTargetScaler(id, metricsProvider, this, this.logger);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure;
using DurableTask.AzureStorage;
using DurableTask.AzureStorage.Monitoring;
using Microsoft.Azure.WebJobs.Host.Scale;
using Microsoft.Extensions.Logging;
Expand All @@ -17,28 +15,20 @@ namespace Microsoft.Azure.WebJobs.Extensions.DurableTask
internal sealed class DurableTaskScaleMonitor : IScaleMonitor<DurableTaskTriggerMetrics>
{
private readonly string hubName;
private readonly StorageAccountClientProvider storageAccountClientProvider;
private readonly ScaleMonitorDescriptor scaleMonitorDescriptor;
private readonly ILogger logger;
private readonly DurableTaskMetricsProvider durableTaskMetricsProvider;

private DisconnectedPerformanceMonitor performanceMonitor;

public DurableTaskScaleMonitor(
string id,
string hubName,
StorageAccountClientProvider storageAccountClientProvider,
ILogger logger,
DurableTaskMetricsProvider durableTaskMetricsProvider,
DisconnectedPerformanceMonitor performanceMonitor = null)
DurableTaskMetricsProvider durableTaskMetricsProvider)
{
this.hubName = hubName;
this.storageAccountClientProvider = storageAccountClientProvider;
this.logger = logger;
this.performanceMonitor = performanceMonitor;
this.durableTaskMetricsProvider = durableTaskMetricsProvider;

string id = $"DurableTaskTrigger-{this.hubName}".ToLower();

// Scalers in Durable Functions are shared for all functions in the same task hub.
// So instead of using a function ID, we use the task hub name as the basis for the descriptor ID.
this.scaleMonitorDescriptor = new ScaleMonitorDescriptor(id: id, functionId: id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>Microsoft.Azure.WebJobs.Extensions.DurableTask</RootNamespace>
<MajorVersion>3</MajorVersion>
<MinorVersion>0</MinorVersion>
<PatchVersion>1</PatchVersion>
<PatchVersion>2</PatchVersion>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<FileVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion)</FileVersion>
<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Worker.Extensions.DurableTask/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;

// TODO: Find a way to generate this dynamically at build-time
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.DurableTask", "3.0.1")]
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.DurableTask", "3.0.2")]
[assembly: InternalsVisibleTo("Worker.Extensions.DurableTask.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd1dabd5a893b40e75dc901fe7293db4a3caf9cd4d3e3ed6178d49cd476969abe74a9e0b7f4a0bb15edca48758155d35a4f05e6e852fff1b319d103b39ba04acbadd278c2753627c95e1f6f6582425374b92f51cca3deb0d2aab9de3ecda7753900a31f70a236f163006beefffe282888f85e3c76d1205ec7dfef7fa472a17b1")]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<AssemblyOriginatorKeyFile>..\..\sign.snk</AssemblyOriginatorKeyFile>

<!-- Version information -->
<VersionPrefix>1.2.1</VersionPrefix>
<VersionPrefix>1.2.2</VersionPrefix>
<VersionSuffix></VersionSuffix>
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
<!-- FileVersionRevision is expected to be set by the CI. -->
Expand Down
12 changes: 8 additions & 4 deletions test/Common/TestEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,14 @@ public static async Task HttpEntity(

private static async Task<int> CallHttpAsync(string requestUri)
{
using (HttpResponseMessage response = await SharedHttpClient.GetAsync(requestUri))
{
return (int)response.StatusCode;
}
////using (HttpResponseMessage response = await SharedHttpClient.GetAsync(requestUri))
////{
//// return (int)response.StatusCode;
////}

// Making real calls to HTTP endpoints is not reliable in tests.
await Task.Delay(100);
return 200;
}

//-------------- an entity that uses custom deserialization
Expand Down
2 changes: 1 addition & 1 deletion test/FunctionsV2/DurableTaskListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void GetMonitor_ReturnsExpectedValue()
IScaleMonitor scaleMonitor = this.listener.GetMonitor();

Assert.Equal(typeof(DurableTaskScaleMonitor), scaleMonitor.GetType());
Assert.Equal($"DurableTaskTrigger-DurableTaskHub".ToLower(), scaleMonitor.Descriptor.Id);
Assert.Equal($"DurableTask-AzureStorage:DurableTaskHub", scaleMonitor.Descriptor.Id);

IScaleMonitor scaleMonitor2 = this.listener.GetMonitor();

Expand Down
9 changes: 5 additions & 4 deletions test/FunctionsV2/DurableTaskScaleMonitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@ public DurableTaskScaleMonitorTests(ITestOutputHelper output)
this.performanceMonitor.Object,
this.clientProvider);

string scalerId = $"DurableTask-AzureStorage:{this.hubName}";

this.scaleMonitor = new DurableTaskScaleMonitor(
scalerId,
this.hubName,
this.clientProvider,
logger,
metricsProvider,
this.performanceMonitor.Object);
metricsProvider);
}

[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public void ScaleMonitorDescriptor_ReturnsExpectedValue()
{
Assert.Equal($"DurableTaskTrigger-{this.hubName}".ToLower(), this.scaleMonitor.Descriptor.Id);
Assert.Equal($"DurableTask-AzureStorage:{this.hubName}", this.scaleMonitor.Descriptor.Id);
}

[Fact]
Expand Down

0 comments on commit 93eddb6

Please sign in to comment.