-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathAzureManagedScalabilityProvider.cs
More file actions
99 lines (88 loc) · 4.15 KB
/
AzureManagedScalabilityProvider.cs
File metadata and controls
99 lines (88 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using Microsoft.Azure.WebJobs.Host.Scale;
using Microsoft.DurableTask.AzureManagedBackend;
using Microsoft.Extensions.Logging;
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale.AzureManaged
{
/// <summary>
/// The AzureManaged backend implementation of the scalability provider for Durable Functions.
/// </summary>
public class AzureManagedScalabilityProvider : ScalabilityProvider
{
private readonly AzureManagedOrchestrationService orchestrationService;
private readonly string connectionName;
private readonly ILogger logger;
/// <summary>
/// Initializes a new instance of the <see cref="AzureManagedScalabilityProvider"/> class.
/// </summary>
/// <param name="orchestrationService">
/// The <see cref="AzureManagedOrchestrationService"/> instance that provides access to backend service for scaling operations.
/// </param>
/// <param name="connectionName">
/// The logical name of the storage or service connection associated with this provider.
/// </param>
/// <param name="logger">
/// The <see cref="ILogger"/> instance used for logging provider activities and diagnostics.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="orchestrationService"/> is <see langword="null"/>.
/// </exception>
public AzureManagedScalabilityProvider(
AzureManagedOrchestrationService orchestrationService,
string connectionName,
ILogger logger)
: base("AzureManaged", connectionName)
{
this.orchestrationService = orchestrationService ?? throw new ArgumentNullException(nameof(orchestrationService));
this.connectionName = connectionName;
this.logger = logger;
}
/// <summary>
/// Gets the app setting containing the Azure Managed connection string.
/// </summary>
public override string ConnectionName => this.connectionName;
/// <inheritdoc/>
/// This is not used.
public override bool TryGetScaleMonitor(
string functionId,
string functionName,
string hubName,
string targetConnectionName,
out IScaleMonitor scaleMonitor)
{
// Azure Managed backend does not support the legacy scale monitor infrastructure.
// Return a dummy scale monitor to avoid exceptions.
scaleMonitor = new DummyScaleMonitor(functionId, hubName);
return true;
}
/// <inheritdoc/>
public override bool TryGetTargetScaler(
string functionId,
string functionName,
string hubName,
string targetConnectionName,
out ITargetScaler targetScaler)
{
// Create a target scaler that uses the orchestration service's metrics endpoint.
// All target scalers share the same AzureManagedOrchestrationService in the same task hub.
targetScaler = new AzureManagedTargetScaler(this.orchestrationService, functionId, this.logger);
return true;
}
private class DummyScaleMonitor : IScaleMonitor
{
private static readonly ScaleMetrics DummyScaleMetrics = new ScaleMetrics();
private static readonly ScaleStatus DummyScaleStatus = new ScaleStatus();
public DummyScaleMonitor(string functionId, string taskHub)
{
this.Descriptor = new ScaleMonitorDescriptor(
id: $"DurableTask.AzureManaged:{taskHub ?? "default"}",
functionId);
}
public ScaleMonitorDescriptor Descriptor { get; }
public System.Threading.Tasks.Task<ScaleMetrics> GetMetricsAsync() => System.Threading.Tasks.Task.FromResult(DummyScaleMetrics);
public ScaleStatus GetScaleStatus(ScaleStatusContext context) => DummyScaleStatus;
}
}
}