Skip to content

Commit

Permalink
Cherry-Pick: SC v3.x Fixes to Branch dev (#3003)
Browse files Browse the repository at this point in the history
* Fixing storage traffic issue for SC

* fix SA1101 warnings

* Update WebJobs.Extensions.DurableTask.csproj

---------

Co-authored-by: alrod <[email protected]>
  • Loading branch information
nytian and alrod authored Jan 16, 2025
1 parent 4763742 commit 778a194
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ internal static IWebJobsBuilder AddDurableScaleForTrigger(this IWebJobsBuilder b
provider = new DurableTaskTriggersScaleProvider(serviceProvider.GetService<IOptions<DurableTaskOptions>>(), serviceProvider.GetService<INameResolver>(), serviceProvider.GetService<ILoggerFactory>(), serviceProvider.GetService<IEnumerable<IDurabilityProviderFactory>>(), triggerMetadata);
return provider;
});
builder.Services.AddSingleton<IScaleMonitorProvider>(serviceProvider => serviceProvider.GetServices<DurableTaskTriggersScaleProvider>().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<IScaleMonitorProvider>(serviceProvider => serviceProvider.GetServices<DurableTaskTriggersScaleProvider>().Single(x => x == provider));
builder.Services.AddSingleton<ITargetScalerProvider>(serviceProvider => serviceProvider.GetServices<DurableTaskTriggersScaleProvider>().Single(x => x == provider));
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,33 +31,40 @@ public DurableTaskMetricsProvider(
this.logger = logger;
this.performanceMonitor = performanceMonitor;
this.storageAccountClientProvider = storageAccountClientProvider;
this.heartbeat = null;
this.heartbeatTimeStamp = DateTime.MinValue;
}

public virtual async Task<DurableTaskTriggerMetrics> 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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.WebApiCompatShim" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.DurableTask.ApplicationInsights" Version="0.2.*" />
<PackageReference Include="Microsoft.Azure.DurableTask.ApplicationInsights" Version="0.2.0" />
<!-- The gRPC dependencies in this package are not compatible with older frameworks, like .NET Core 2.x -->
<PackageReference Include="Microsoft.DurableTask.Grpc" Version="1.3.0" />
<PackageReference Include="Grpc.Core" Version="2.46.6" /> <!-- Bring this in until we move to hosted RPC -->
Expand Down

0 comments on commit 778a194

Please sign in to comment.