Skip to content

Commit

Permalink
trycatch in getmetrics (#45974)
Browse files Browse the repository at this point in the history
Co-authored-by: Vincent Chiang <[email protected]>
  • Loading branch information
chiangvincent and Vincent Chiang authored Sep 16, 2024
1 parent 78ed4d1 commit a70122e
Showing 1 changed file with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,44 @@ public ZeroToOneScaleMonitor(string functionId, BlobServiceClient blobServiceCli

public async Task<ScaleMetrics> GetMetricsAsync()
{
// if new blob were detected we want to GetScaleStatus return scale out vote at least once
if (Interlocked.Equals(_threadSafeWritesDetectedValue, 1))
try
{
_logger.LogInformation($"New writes were detectd but GetScaleStatus was not called. Waiting GetScaleStatus to call.");
return new ScaleMetrics();
}
// if new blob were detected we want to GetScaleStatus return scale out vote at least once
if (Interlocked.Equals(_threadSafeWritesDetectedValue, 1))
{
_logger.LogInformation($"New writes were detectd but GetScaleStatus was not called. Waiting GetScaleStatus to call.");
return new ScaleMetrics();
}

var blobLogListener = await _blobLogListener.Value.ConfigureAwait(false);
BlobWithContainer<BlobBaseClient>[] recentWrites = _recentWrite == null ? (await blobLogListener.GetRecentBlobWritesAsync(CancellationToken.None).ConfigureAwait(false)).ToArray()
: new BlobWithContainer<BlobBaseClient>[] { _recentWrite };
if (recentWrites.Length > 0)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (var write in recentWrites)
var blobLogListener = await _blobLogListener.Value.ConfigureAwait(false);
BlobWithContainer<BlobBaseClient>[] recentWrites = _recentWrite == null ? (await blobLogListener.GetRecentBlobWritesAsync(CancellationToken.None).ConfigureAwait(false)).ToArray()
: new BlobWithContainer<BlobBaseClient>[] { _recentWrite };
if (recentWrites.Length > 0)
{
stringBuilder.Append($"'{write.BlobClient.Name}', ");
if (stringBuilder.Length > 1000)
StringBuilder stringBuilder = new StringBuilder();
foreach (var write in recentWrites)
{
stringBuilder.Append("[truncated]");
break;
stringBuilder.Append($"'{write.BlobClient.Name}', ");
if (stringBuilder.Length > 1000)
{
stringBuilder.Append("[truncated]");
break;
}
}
_logger.LogInformation($"'{recentWrites.Length}' recent writes were detected for '{_scaleMonitorDescriptor.FunctionId}': {stringBuilder}");
Interlocked.CompareExchange(ref _threadSafeWritesDetectedValue, 1, 0);
}
else
{
_logger.LogInformation($"No recent writes were detected for '{_scaleMonitorDescriptor.FunctionId}'");
Interlocked.CompareExchange(ref _threadSafeWritesDetectedValue, 0, 1);
}
_logger.LogInformation($"'{recentWrites.Length}' recent writes were detected for '{_scaleMonitorDescriptor.FunctionId}': {stringBuilder}");
Interlocked.CompareExchange(ref _threadSafeWritesDetectedValue, 1, 0);
}
else
catch (Exception e)
{
_logger.LogInformation($"No recent writes were detected for '{_scaleMonitorDescriptor.FunctionId}'");
Interlocked.CompareExchange(ref _threadSafeWritesDetectedValue, 0, 1);
_logger.LogWarning($"Encountered exception while detecting recent writes for '{_scaleMonitorDescriptor.FunctionId}'. Exception: {e.ToString()}");
}

return new ScaleMetrics();
}

Expand Down

0 comments on commit a70122e

Please sign in to comment.