From e8ca90e799fc6f76a7ac8d6af45310c26f1a016b Mon Sep 17 00:00:00 2001 From: Chris Gillum Date: Mon, 2 Dec 2024 18:19:21 -0800 Subject: [PATCH] Use consistent scaler IDs for target-based and scale monitor implementations --- .../AzureStorageDurabilityProvider.cs | 27 ++++++++++++++----- .../Listener/DurableTaskScaleMonitor.cs | 13 ++------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs b/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs index ea5350463..1640dbd63 100644 --- a/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs +++ b/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs @@ -243,6 +243,13 @@ internal DurableTaskMetricsProvider GetMetricsProvider( return new DurableTaskMetricsProvider(hubName, logger, performanceMonitor: null, storageAccount); } + // 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, @@ -255,11 +262,17 @@ public override bool TryGetScaleMonitor( { if (this.singletonScaleMonitor == null) { - CloudStorageAccount storageAccount = this.storageAccountProvider.GetStorageAccountDetails(connectionName).ToCloudStorageAccount(); - DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(hubName, storageAccount, this.logger); + DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider( + hubName, + this.storageAccountProvider.GetStorageAccountDetails(connectionName).ToCloudStorageAccount(), + 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, - storageAccount, this.logger, metricsProvider); } @@ -283,12 +296,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. - CloudStorageAccount storageAccount = this.storageAccountProvider.GetStorageAccountDetails(connectionName).ToCloudStorageAccount(); - DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(hubName, storageAccount, this.logger); + DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider( + hubName, + this.storageAccountProvider.GetStorageAccountDetails(connectionName).ToCloudStorageAccount(), + 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 c24762e06..fc9225b72 100644 --- a/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskScaleMonitor.cs +++ b/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskScaleMonitor.cs @@ -9,7 +9,6 @@ using DurableTask.AzureStorage.Monitoring; using Microsoft.Azure.WebJobs.Host.Scale; using Microsoft.Extensions.Logging; -using Microsoft.WindowsAzure.Storage; using Newtonsoft.Json; namespace Microsoft.Azure.WebJobs.Extensions.DurableTask @@ -17,27 +16,19 @@ namespace Microsoft.Azure.WebJobs.Extensions.DurableTask internal sealed class DurableTaskScaleMonitor : IScaleMonitor { private readonly string hubName; - private readonly CloudStorageAccount storageAccount; private readonly ScaleMonitorDescriptor scaleMonitorDescriptor; private readonly ILogger logger; private readonly DurableTaskMetricsProvider durableTaskMetricsProvider; - private DisconnectedPerformanceMonitor performanceMonitor; - public DurableTaskScaleMonitor( + string id, string hubName, - CloudStorageAccount storageAccount, ILogger logger, - DurableTaskMetricsProvider durableTaskMetricsProvider, - DisconnectedPerformanceMonitor performanceMonitor = null) + DurableTaskMetricsProvider durableTaskMetricsProvider) { this.hubName = hubName; - this.storageAccount = storageAccount; this.logger = logger; - this.performanceMonitor = performanceMonitor; this.durableTaskMetricsProvider = durableTaskMetricsProvider; - - string id = $"DurableTaskTrigger-{this.hubName}".ToLower(); #if FUNCTIONS_V3_OR_GREATER // 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.