Skip to content

Commit ed18484

Browse files
committed
[ServiceBus] Replacing scaling logs to WebJobs extension methods
1 parent 724366b commit ed18484

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

NuGet.Config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<clear />
55
<!-- Do not add any additional feeds if new packages are needed they need to come from our azure-sdk-for-net DevOps feed which has an upstream set to nuget.org -->
66
<add key="azure-sdk-for-net" value="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json" />
7+
<add key="local" value="Q:\nuget" />
78
</packageSources>
89
<disabledPackageSources>
910
<clear />

eng/Packages.Data.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@
249249
<PackageReference Update="Microsoft.Azure.SignalR.Management" Version="1.29.0" />
250250
<PackageReference Update="Microsoft.Azure.SignalR.Protocols" Version="1.29.0" />
251251
<PackageReference Update="Microsoft.Azure.SignalR.Serverless.Protocols" Version="1.10.0" />
252-
<PackageReference Update="Microsoft.Azure.WebJobs" Version="3.0.41" />
253-
<PackageReference Update="Microsoft.Azure.WebJobs.Sources" Version="3.0.41" PrivateAssets="All"/>
252+
<PackageReference Update="Microsoft.Azure.WebJobs" Version="3.0.42-dev" />
253+
<PackageReference Update="Microsoft.Azure.WebJobs.Sources" Version="3.0.42-dev" PrivateAssets="All"/>
254254
<PackageReference Update="Microsoft.Azure.WebJobs.Extensions.Rpc" Version="3.0.41" />
255255
<PackageReference Update="Microsoft.Azure.WebJobs.Host.Storage" Version="5.0.1" />
256256
<PackageReference Update="Microsoft.Spatial" Version="7.5.3" />

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Common/src/Shared/Queues/QueueMetricsProvider.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Azure;
77
using Azure.Storage.Queues;
88
using Azure.Storage.Queues.Models;
9+
using Microsoft.Azure.WebJobs.Host.Scale;
910
using Microsoft.Extensions.Logging;
1011

1112
namespace Microsoft.Azure.WebJobs.Extensions.Storage.Common.Listeners
@@ -15,16 +16,19 @@ namespace Microsoft.Azure.WebJobs.Extensions.Storage.Common.Listeners
1516
/// </summary>
1617
internal class QueueMetricsProvider
1718
{
19+
private readonly string _functionId;
1820
private readonly QueueClient _queue;
1921
private readonly ILogger _logger;
2022

2123
/// <summary>
2224
/// Instantiates a QueueMetricsProvider.
2325
/// </summary>
26+
/// <param name="functionId">The function id to make scale decisions for.</param>
2427
/// <param name="queue">The QueueClient to use for metrics polling.</param>
2528
/// <param name="loggerFactory">Used to create an ILogger instance.</param>
26-
public QueueMetricsProvider(QueueClient queue, ILoggerFactory loggerFactory)
29+
public QueueMetricsProvider(string functionId, QueueClient queue, ILoggerFactory loggerFactory)
2730
{
31+
_functionId = functionId;
2832
_queue = queue;
2933
_logger = loggerFactory.CreateLogger<QueueMetricsProvider>();
3034
}
@@ -49,12 +53,12 @@ public async Task<int> GetQueueLengthAsync()
4953
// ignore transient errors, and return default metrics
5054
// E.g. if the queue doesn't exist, we'll return a zero queue length
5155
// and scale in
52-
_logger.LogWarning($"Error querying for queue scale status: {ex.ToString()}");
56+
_logger.LogFunctionScaleWarning("Error querying for queue scale status", _functionId, ex);
5357
}
5458
}
5559
catch (Exception ex)
5660
{
57-
_logger.LogWarning($"Fatal error querying for queue scale status: {ex.ToString()}");
61+
_logger.LogFunctionScaleWarning("Fatal error querying for queue scale status", _functionId, ex);
5862
}
5963

6064
return 0;
@@ -101,12 +105,13 @@ public async Task<QueueTriggerMetrics> GetMetricsAsync()
101105
// ignore transient errors, and return default metrics
102106
// E.g. if the queue doesn't exist, we'll return a zero queue length
103107
// and scale in
104-
_logger.LogWarning($"Error querying for queue scale status: {ex.ToString()}");
108+
109+
_logger.LogFunctionScaleWarning("Error querying for queue scale status", _functionId, ex);
105110
}
106111
}
107112
catch (Exception ex)
108113
{
109-
_logger.LogWarning($"Fatal error querying for queue scale status: {ex.ToString()}");
114+
_logger.LogFunctionScaleWarning("Fatal error querying for queue scale status", _functionId, ex);
110115
}
111116

112117
return new QueueTriggerMetrics

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Common/src/Shared/Queues/QueueScaleMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public QueueScaleMonitor(string functionId, QueueClient queue, ILoggerFactory lo
4141
_queue = queue;
4242
_logger = loggerFactory.CreateLogger<QueueListener>();
4343
_scaleMonitorDescriptor = new ScaleMonitorDescriptor($"{functionId}-QueueTrigger-{_queue.Name}".ToLower(CultureInfo.InvariantCulture), functionId);
44-
_queueMetricsProvider = new QueueMetricsProvider(queue, loggerFactory);
44+
_queueMetricsProvider = new QueueMetricsProvider(functionId, queue, loggerFactory);
4545
}
4646

4747
/// <summary>

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Common/src/Shared/Queues/QueueTargetScaler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal QueueTargetScaler(string functionId, QueueClient queueClient, QueuesOpt
3636
{
3737
_functionId = functionId;
3838
_queueName = queueClient.Name;
39-
_queueMetricsProvider = new QueueMetricsProvider(queueClient, loggerFactory);
39+
_queueMetricsProvider = new QueueMetricsProvider(_functionId, queueClient, loggerFactory);
4040
_targetScalerDescriptor = new TargetScalerDescriptor(functionId);
4141
_options = options;
4242
_logger = loggerFactory.CreateLogger<QueueTargetScaler>();
@@ -64,7 +64,8 @@ internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context,
6464

6565
int targetWorkerCount = (int)Math.Ceiling(queueLength / (decimal)concurrency);
6666

67-
_logger.LogInformation($"Target worker count for function '{_functionId}' is '{targetWorkerCount}' (QueueName='{_queueName}', QueueLength ='{queueLength}', Concurrency='{concurrency}').");
67+
string details = $"Target worker count for function '{_functionId}' is '{targetWorkerCount}' (QueueName='{_queueName}', QueueLength ='{queueLength}', Concurrency='{concurrency}').";
68+
_logger.LogFunctionScaleVote(_functionId, targetWorkerCount, queueLength, concurrency, details);
6869
return new TargetScalerResult
6970
{
7071
TargetWorkerCount = targetWorkerCount

sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/tests/QueueMetricsProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void SetUp()
3434
_loggerFactory.AddProvider(_loggerProvider);
3535
_mockQueue = new Mock<QueueClient>(new Uri("https://test.queue.core.windows.net/testqueue"), new QueueClientOptions());
3636
_mockQueue.Setup(x => x.Name).Returns("testqueue");
37-
_metricsProvider = new QueueMetricsProvider(_mockQueue.Object, _loggerFactory);
37+
_metricsProvider = new QueueMetricsProvider("testfunction", _mockQueue.Object, _loggerFactory);
3838
}
3939

4040
[OneTimeSetUp]
@@ -54,7 +54,7 @@ public void OneTimeTearDown()
5454
[Test]
5555
public async Task GetMetrics_ReturnsExpectedResult()
5656
{
57-
QueueMetricsProvider _provider = new QueueMetricsProvider(Fixture.Queue, _loggerFactory);
57+
QueueMetricsProvider _provider = new QueueMetricsProvider("testfunction", Fixture.Queue, _loggerFactory);
5858
var metrics = await _provider.GetMetricsAsync();
5959

6060
Assert.AreEqual(0, metrics.QueueLength);

0 commit comments

Comments
 (0)