Skip to content

Commit

Permalink
add comments to explain when code runs in the ScaleController process
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid committed Sep 21, 2023
1 parent e251a81 commit 7912e7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public override bool TryGetTargetScaler(
string connectionName,
out ITargetScaler targetScaler)
{
// This is only called by the ScaleController, it doesn't run in the Functions Host process.
CloudStorageAccount storageAccount = this.storageAccountProvider.GetStorageAccountDetails(connectionName).ToCloudStorageAccount();
DurableTaskMetricsProvider metricsProvider = this.GetMetricsProvider(functionName, hubName, storageAccount, this.logger);
targetScaler = new DurableTaskTargetScaler(functionId, metricsProvider, this, this.logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public DurableTaskTargetScaler(string functionId, DurableTaskMetricsProvider met

public async Task<TargetScalerResult> GetScaleResultAsync(TargetScalerContext context)
{
// This method is only invoked by the ScaleController, so it doesn't run in the Functions Host process.
var metrics = await this.metricsProvider.GetMetricsAsync();

// compute activityWorkers: the number of workers we need to process all activity messages
Expand All @@ -59,6 +60,8 @@ public async Task<TargetScalerResult> GetScaleResultAsync(TargetScalerContext co
this.scaleResult.TargetWorkerCount = numWorkersToRequest;

// When running on ScaleController V3, ILogger logs are forwarded to the ScaleController's Kusto table.
// This works because this code does not execute in the Functions Host process, but in the ScaleController process,
// and the ScaleController is injecting it's own custom ILogger implementation that forwards logs to Kusto.
var scaleControllerLog = $"Target worker count for {this.functionId}: {numWorkersToRequest}. " +
$"Metrics used: workItemQueueLength={workItemQueueLength}. controlQueueLengths={serializedControlQueueLengths}. " +
$"maxConcurrentOrchestrators={this.MaxConcurrentOrchestrators}. maxConcurrentActivities={this.MaxConcurrentActivities}";
Expand All @@ -68,6 +71,7 @@ public async Task<TargetScalerResult> GetScaleResultAsync(TargetScalerContext co
{
scaleControllerLog = "Tried to request a negative worker count." + scaleControllerLog;
this.logger.LogError(scaleControllerLog);
// Throw exception so ScaleController can handle the error.
throw new Exception(scaleControllerLog);
}

Expand Down

0 comments on commit 7912e7a

Please sign in to comment.