diff --git a/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs b/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs index 11e115111..87b925b26 100644 --- a/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs +++ b/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs @@ -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"}"; + } + /// public override bool TryGetScaleMonitor( string functionId, @@ -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); } @@ -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); } diff --git a/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskScaleMonitor.cs b/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskScaleMonitor.cs index 1c9d63212..7f0b20ec4 100644 --- a/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskScaleMonitor.cs +++ b/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskScaleMonitor.cs @@ -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; @@ -17,28 +15,20 @@ namespace Microsoft.Azure.WebJobs.Extensions.DurableTask internal sealed class DurableTaskScaleMonitor : IScaleMonitor { 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); diff --git a/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj b/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj index 0fd97f9c9..a36e2c23d 100644 --- a/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj +++ b/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj @@ -6,7 +6,7 @@ Microsoft.Azure.WebJobs.Extensions.DurableTask 3 0 - 1 + 2 $(MajorVersion).$(MinorVersion).$(PatchVersion) $(MajorVersion).$(MinorVersion).$(PatchVersion) $(MajorVersion).0.0.0 diff --git a/src/Worker.Extensions.DurableTask/AssemblyInfo.cs b/src/Worker.Extensions.DurableTask/AssemblyInfo.cs index 2bf204302..9771a09ed 100644 --- a/src/Worker.Extensions.DurableTask/AssemblyInfo.cs +++ b/src/Worker.Extensions.DurableTask/AssemblyInfo.cs @@ -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")] diff --git a/src/Worker.Extensions.DurableTask/Worker.Extensions.DurableTask.csproj b/src/Worker.Extensions.DurableTask/Worker.Extensions.DurableTask.csproj index 81f805875..135f4b352 100644 --- a/src/Worker.Extensions.DurableTask/Worker.Extensions.DurableTask.csproj +++ b/src/Worker.Extensions.DurableTask/Worker.Extensions.DurableTask.csproj @@ -29,7 +29,7 @@ ..\..\sign.snk - 1.2.1 + 1.2.2 $(VersionPrefix).0 diff --git a/test/Common/TestEntities.cs b/test/Common/TestEntities.cs index a1ba7e15b..5bf6ecd0a 100644 --- a/test/Common/TestEntities.cs +++ b/test/Common/TestEntities.cs @@ -340,10 +340,14 @@ public static async Task HttpEntity( private static async Task 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 diff --git a/test/FunctionsV2/DurableTaskListenerTests.cs b/test/FunctionsV2/DurableTaskListenerTests.cs index 886e5a1b3..e79b51586 100644 --- a/test/FunctionsV2/DurableTaskListenerTests.cs +++ b/test/FunctionsV2/DurableTaskListenerTests.cs @@ -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(); diff --git a/test/FunctionsV2/DurableTaskScaleMonitorTests.cs b/test/FunctionsV2/DurableTaskScaleMonitorTests.cs index 87c988c5b..3ea4f9297 100644 --- a/test/FunctionsV2/DurableTaskScaleMonitorTests.cs +++ b/test/FunctionsV2/DurableTaskScaleMonitorTests.cs @@ -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]