function getSuggestedSize()

in src/scaler/scaler-core/scaling-methods/linear.js [146:193]


function getSuggestedSize(cluster, direction, engineAnalysis) {
  if (!engineAnalysis) return cluster.currentSize;
  if (direction === AutoscalerDirection.NONE) return cluster.currentSize;

  const scalingMetricList = getMetricsForScaling(
    cluster,
    direction,
    engineAnalysis,
  );
  if (!scalingMetricList) return cluster.currentSize;

  let suggestedSize = null;
  for (const scalingMetric of scalingMetricList) {
    // This should not happen as this check is done on getMetricsForScaling
    // and an error message is logged. However, this helps type inference.
    if (!scalingMetric.threshold) continue;

    // Linear scaling main calculation.
    const metricSuggestedSize = Math.ceil(
      cluster.currentSize * (scalingMetric.value / scalingMetric.threshold),
    );

    suggestedSize = Math.max(suggestedSize || 0, metricSuggestedSize);
  }
  if (suggestedSize === null) suggestedSize = cluster.currentSize;

  if (direction === AutoscalerDirection.IN) {
    if (cluster.scaleInLimit) {
      suggestedSize = Math.max(
        suggestedSize,
        cluster.currentSize - cluster.scaleInLimit,
      );
    }

    if (suggestedSize < cluster.currentSize) return suggestedSize;
  } else if (direction === AutoscalerDirection.OUT) {
    if (cluster.scaleOutLimit) {
      suggestedSize = Math.min(
        suggestedSize,
        cluster.currentSize + cluster.scaleOutLimit,
      );
    }

    if (suggestedSize > cluster.currentSize) return suggestedSize;
  }

  return cluster.currentSize;
}