in Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo/Trigger/CosmosDBMongoScaleMonitor.cs [71:120]
private ScaleStatus GetScaleStatusCore(int workerCount, CosmosDBMongoTriggerMetrics[] metrics)
{
ScaleStatus status = new ScaleStatus
{
Vote = ScaleVote.None
};
// Unable to determine the correct vote with no metrics.
if (metrics == null || metrics.Length == 0)
{
return status;
}
// At least _minSampleCount samples are required to make a scale decision for the rest of the checks.
if (metrics.Length < _minSampleCount)
{
return status;
}
// Samples are in chronological order. Check for a continuous increase in message count.
// If detected, this results in an automatic scale out for the site container.
if (metrics[metrics.Length-1].PendingEventsCount > 0)
{
bool PendingWorkCountHitMaxForN =
IsTrueForLastN(
metrics,
_minSampleCount,
(prev, next) => prev.PendingEventsCount <= next.PendingEventsCount && next.PendingEventsCount >= _maxWorkPerInstance);
if (PendingWorkCountHitMaxForN)
{
status.Vote = ScaleVote.ScaleOut;
return status;
}
}
bool PendingWorkCountDecreasing =
IsTrueForLastN(
metrics,
_minSampleCount,
(prev, next) => prev.PendingEventsCount >= next.PendingEventsCount);
if (PendingWorkCountDecreasing)
{
status.Vote = ScaleVote.ScaleIn;
return status;
}
_logger.LogDebug($"CosmosDB Mongo trigger function '{_functionId}-{_databaseName}-{_collectionName}' is steady.");
return status;
}