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
  • Loading branch information
cgillum committed Dec 3, 2024
1 parent 7801ed8 commit e8ca90e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"}";
}

/// <inheritdoc/>
public override bool TryGetScaleMonitor(
string functionId,
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,26 @@
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
{
internal sealed class DurableTaskScaleMonitor : IScaleMonitor<DurableTaskTriggerMetrics>
{
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.
Expand Down

0 comments on commit e8ca90e

Please sign in to comment.