private int getBoundedRecommendationForScaleDown()

in src/main/java/com/google/cloud/run/kafkascaler/ScalingStabilizer.java [295:320]


  private int getBoundedRecommendationForScaleDown(
      Behavior behavior,
      Instant time,
      int currentInstanceCount,
      int recommendedInstances,
      BoundsDebugInfo debug) {
    if (behavior.scaleDown() == null) {
      return recommendedInstances;
    }

    Scaling scaleDown = behavior.scaleDown();
    Optional<Integer> stabilizationBound =
        stabilizeRecommendation(behavior, time, currentInstanceCount, recommendedInstances, debug);
    Optional<Integer> rateLimitBound =
        rateLimitScaleDownRecommendation(time, currentInstanceCount, scaleDown, debug);

    int scaleDownBound = recommendedInstances;
    if (stabilizationBound.isPresent()) {
      scaleDownBound = max(stabilizationBound.get(), scaleDownBound);
    }
    if (rateLimitBound.isPresent()) {
      scaleDownBound = max(rateLimitBound.get(), scaleDownBound);
    }

    return scaleDownBound;
  }