Skip to content

Commit 8430784

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

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
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/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/src/Listeners/ServiceBusMetricsProvider.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using Microsoft.Azure.WebJobs.ServiceBus.Listeners;
5-
using Microsoft.Azure.WebJobs.ServiceBus;
64
using System;
75
using System.Threading.Tasks;
8-
using Microsoft.Extensions.Logging;
96
using Azure.Messaging.ServiceBus;
107
using Azure.Messaging.ServiceBus.Administration;
11-
using Microsoft.Azure.WebJobs.Extensions.ServiceBus.Config;
8+
using Microsoft.Azure.WebJobs.Host.Scale;
9+
using Microsoft.Azure.WebJobs.ServiceBus;
10+
using Microsoft.Azure.WebJobs.ServiceBus.Listeners;
11+
using Microsoft.Extensions.Logging;
1212

1313
namespace Microsoft.Azure.WebJobs.Extensions.ServiceBus.Listeners
1414
{
@@ -17,6 +17,7 @@ internal class ServiceBusMetricsProvider
1717
internal const string DeadLetterQueuePath = @"/$DeadLetterQueue";
1818

1919
private readonly ILogger _logger;
20+
private readonly string _functionId;
2021
private readonly string _entityPath;
2122
private readonly ServiceBusEntityType _serviceBusEntityType;
2223
private readonly Lazy<ServiceBusReceiver> _receiver;
@@ -30,12 +31,14 @@ internal class ServiceBusMetricsProvider
3031
private DateTime _nextWarningTime;
3132

3233
public ServiceBusMetricsProvider(
34+
string functionId,
3335
string entityPath,
3436
ServiceBusEntityType serviceBusEntityType,
3537
Lazy<ServiceBusReceiver> receiver,
3638
Lazy<ServiceBusAdministrationClient> administrationClient,
3739
ILoggerFactory loggerFactory)
3840
{
41+
_functionId = functionId;
3942
_serviceBusEntityType = serviceBusEntityType;
4043
_receiver = receiver;
4144
_entityPath = entityPath;
@@ -90,19 +93,20 @@ public async Task<long> GetMessageCountAsync()
9093
catch (ServiceBusException ex)
9194
when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
9295
{
93-
_logger.LogWarning($"ServiceBus {entityName} '{_entityPath}' was not found.");
96+
_logger.LogFunctionScaleError($"ServiceBus {entityName} '{_entityPath}' was not found.", _functionId, ex);
9497
}
9598
catch (UnauthorizedAccessException ex)
9699
{
97100
if (TimeToLogWarning())
98101
{
99-
_logger.LogWarning(ex, $"Connection string does not have 'Manage Claim' for {entityName} '{_entityPath}'. Unable to determine active message count.");
102+
_logger.LogFunctionScaleWarning($"Connection string does not have 'Manage Claim' for {entityName} '{_entityPath}'. Unable to determine active message count.",
103+
_functionId, ex);
100104
}
101105
throw;
102106
}
103-
catch (Exception e)
107+
catch (Exception ex)
104108
{
105-
_logger.LogWarning(e, $"Error querying for Service Bus {entityName} scale");
109+
_logger.LogFunctionScaleError($"Error querying for Service Bus {entityName} scale", _functionId, ex);
106110
}
107111

108112
long totalNewMessageCount = 0;
@@ -163,19 +167,20 @@ public async Task<ServiceBusTriggerMetrics> GetMetricsAsync()
163167
catch (ServiceBusException ex)
164168
when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
165169
{
166-
_logger.LogWarning($"ServiceBus {entityName} '{_entityPath}' was not found.");
170+
_logger.LogFunctionScaleError($"ServiceBus {entityName} '{_entityPath}' was not found.", _functionId, ex);
167171
}
168-
catch (UnauthorizedAccessException) // When manage claim is not used on Service Bus connection string
172+
catch (UnauthorizedAccessException ex) // When manage claim is not used on Service Bus connection string
169173
{
170174
if (TimeToLogWarning())
171175
{
172-
_logger.LogWarning($"Connection string does not have Manage claim for {entityName} '{_entityPath}'. Failed to get {entityName} description to " +
173-
$"derive {entityName} length metrics. Falling back to using first message enqueued time.");
176+
_logger.LogFunctionScaleWarning($"Connection string does not have Manage claim for {entityName} '{_entityPath}'. Failed to get {entityName} description to " +
177+
$"derive {entityName} length metrics. Falling back to using first message enqueued time.",
178+
_functionId, ex);
174179
}
175180
}
176-
catch (Exception e)
181+
catch (Exception ex)
177182
{
178-
_logger.LogWarning($"Error querying for Service Bus {entityName} scale status: {e.Message}");
183+
_logger.LogFunctionScaleError($"Error querying for Service Bus {entityName} scale status", _functionId, ex);
179184
}
180185

181186
// Path for connection strings with no manage claim

sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/src/Listeners/ServiceBusScaleMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ILoggerFactory loggerFactory
3737
{
3838
_functionId = functionId;
3939
_entityPath = entityPath;
40-
_serviceBusMetricsProvider = new ServiceBusMetricsProvider(entityPath, entityType, receiver, administrationClient, loggerFactory);
40+
_serviceBusMetricsProvider = new ServiceBusMetricsProvider(_functionId, entityPath, entityType, receiver, administrationClient, loggerFactory);
4141
_scaleMonitorDescriptor = new ScaleMonitorDescriptor($"{_functionId}-ServiceBusTrigger-{_entityPath}".ToLower(CultureInfo.InvariantCulture), functionId);
4242
_logger = loggerFactory.CreateLogger<ServiceBusScaleMonitor>();
4343
}

sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/src/Listeners/ServiceBusTargetScaler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.ServiceBus.Listeners
1616
{
1717
internal class ServiceBusTargetScaler : ITargetScaler
1818
{
19-
private readonly string _functionId;
19+
private readonly string _functionName;
2020
private readonly ServiceBusMetricsProvider _serviceBusMetricsProvider;
2121
private readonly ServiceBusOptions _options;
2222
private readonly bool _isSessionsEnabled;
@@ -26,7 +26,7 @@ internal class ServiceBusTargetScaler : ITargetScaler
2626
private readonly ILogger _logger;
2727

2828
public ServiceBusTargetScaler(
29-
string functionId,
29+
string functionName,
3030
string entityPath,
3131
ServiceBusEntityType entityType,
3232
Lazy<ServiceBusReceiver> receiver,
@@ -37,10 +37,10 @@ public ServiceBusTargetScaler(
3737
ILoggerFactory loggerFactory
3838
)
3939
{
40-
_functionId = functionId;
41-
_serviceBusMetricsProvider = new ServiceBusMetricsProvider(entityPath, entityType, receiver, administrationClient, loggerFactory);
40+
_functionName = functionName;
41+
_serviceBusMetricsProvider = new ServiceBusMetricsProvider(_functionName, entityPath, entityType, receiver, administrationClient, loggerFactory);
4242
_entityPath = entityPath;
43-
_targetScalerDescriptor = new TargetScalerDescriptor(functionId);
43+
_targetScalerDescriptor = new TargetScalerDescriptor(functionName);
4444
_logger = loggerFactory.CreateLogger<ServiceBusTargetScaler>();
4545
_options = options;
4646
_singleDispatch = singleDispatch;
@@ -108,7 +108,8 @@ internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context,
108108
targetWorkerCount = int.MaxValue;
109109
}
110110

111-
_logger.LogInformation($"Target worker count for function '{_functionId}' is '{targetWorkerCount}' (EntityPath='{_entityPath}', MessageCount ='{messageCount}', Concurrency='{concurrency}').");
111+
_logger.LogFunctionScaleVote(_functionName, targetWorkerCount, (int)messageCount, concurrency,
112+
$"Target worker count for function '{_functionName}' is '{targetWorkerCount}' (EntityPath='{_entityPath}', MessageCount ='{messageCount}', Concurrency='{concurrency}').");
112113

113114
return new TargetScalerResult
114115
{

0 commit comments

Comments
 (0)