From 778a194d51b6d0897d4a0a5de9f1e3385bb40ee9 Mon Sep 17 00:00:00 2001 From: Naiyuan Tian <110135109+nytian@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:29:03 -0800 Subject: [PATCH] Cherry-Pick: SC v3.x Fixes to Branch `dev` (#3003) * Fixing storage traffic issue for SC * fix SA1101 warnings * Update WebJobs.Extensions.DurableTask.csproj --------- Co-authored-by: alrod --- ...rableTaskJobHostConfigurationExtensions.cs | 4 ++- .../Listener/DurableTaskMetricsProvider.cs | 27 ++++++++++++------- .../WebJobs.Extensions.DurableTask.csproj | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs b/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs index 84d0f78ad..4ee45fea4 100644 --- a/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs +++ b/src/WebJobs.Extensions.DurableTask/DurableTaskJobHostConfigurationExtensions.cs @@ -112,7 +112,9 @@ internal static IWebJobsBuilder AddDurableScaleForTrigger(this IWebJobsBuilder b provider = new DurableTaskTriggersScaleProvider(serviceProvider.GetService>(), serviceProvider.GetService(), serviceProvider.GetService(), serviceProvider.GetService>(), triggerMetadata); return provider; }); - builder.Services.AddSingleton(serviceProvider => serviceProvider.GetServices().Single(x => x == provider)); + + // Commenting out incremental scale model for hotfix release 3.0.0-rc.4, SC uses TBS by default + // builder.Services.AddSingleton(serviceProvider => serviceProvider.GetServices().Single(x => x == provider)); builder.Services.AddSingleton(serviceProvider => serviceProvider.GetServices().Single(x => x == provider)); return builder; } diff --git a/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskMetricsProvider.cs b/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskMetricsProvider.cs index 7ec9df2e3..97377023c 100644 --- a/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskMetricsProvider.cs +++ b/src/WebJobs.Extensions.DurableTask/Listener/DurableTaskMetricsProvider.cs @@ -16,6 +16,8 @@ internal class DurableTaskMetricsProvider private readonly string hubName; private readonly ILogger logger; private readonly StorageAccountClientProvider storageAccountClientProvider; + private PerformanceHeartbeat heartbeat; + private DateTime heartbeatTimeStamp; private DisconnectedPerformanceMonitor performanceMonitor; @@ -29,6 +31,8 @@ public DurableTaskMetricsProvider( this.logger = logger; this.performanceMonitor = performanceMonitor; this.storageAccountClientProvider = storageAccountClientProvider; + this.heartbeat = null; + this.heartbeatTimeStamp = DateTime.MinValue; } public virtual async Task GetMetricsAsync() @@ -36,26 +40,31 @@ public virtual async Task GetMetricsAsync() DurableTaskTriggerMetrics metrics = new DurableTaskTriggerMetrics(); // Durable stores its own metrics, so we just collect them here - PerformanceHeartbeat heartbeat = null; try { DisconnectedPerformanceMonitor performanceMonitor = this.GetPerformanceMonitor(); - heartbeat = await performanceMonitor.PulseAsync(); + + // We only want to call PulseAsync every 5 seconds + if (this.heartbeat == null || DateTime.UtcNow > this.heartbeatTimeStamp.AddSeconds(5)) + { + this.heartbeat = await performanceMonitor.PulseAsync(); + this.heartbeatTimeStamp = DateTime.UtcNow; + } } catch (Exception e) when (e.InnerException is RequestFailedException) { this.logger.LogWarning("{details}. HubName: {hubName}.", e.ToString(), this.hubName); } - if (heartbeat != null) + if (this.heartbeat != null) { - metrics.PartitionCount = heartbeat.PartitionCount; - metrics.ControlQueueLengths = JsonConvert.SerializeObject(heartbeat.ControlQueueLengths); - metrics.ControlQueueLatencies = JsonConvert.SerializeObject(heartbeat.ControlQueueLatencies); - metrics.WorkItemQueueLength = heartbeat.WorkItemQueueLength; - if (heartbeat.WorkItemQueueLatency > TimeSpan.Zero) + metrics.PartitionCount = this.heartbeat.PartitionCount; + metrics.ControlQueueLengths = JsonConvert.SerializeObject(this.heartbeat.ControlQueueLengths); + metrics.ControlQueueLatencies = JsonConvert.SerializeObject(this.heartbeat.ControlQueueLatencies); + metrics.WorkItemQueueLength = this.heartbeat.WorkItemQueueLength; + if (this.heartbeat.WorkItemQueueLatency > TimeSpan.Zero) { - metrics.WorkItemQueueLatency = heartbeat.WorkItemQueueLatency.ToString(); + metrics.WorkItemQueueLatency = this.heartbeat.WorkItemQueueLatency.ToString(); } } diff --git a/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj b/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj index a36e2c23d..15e306be7 100644 --- a/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj +++ b/src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj @@ -59,7 +59,7 @@ - +