Skip to content

Commit

Permalink
fix: default consumer rate to the final calculated target rate (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Mason authored Aug 14, 2023
2 parents cc11260 + 357c303 commit c18c0a2
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public TriggerResult process(KubernetesClient client, ScaledResource resource, K

var lag = lagModel.getLag();
var targetRate = lagModel.getTopicRate().orElse(0);
var consumerRate = lagModel.estimateConsumerRate(replicaCount).orElse(targetRate);
var consumerRate = lagModel.estimateConsumerRate(replicaCount);
if (lag > threshold) {
// We need to catch up, so calculate a target rate that will clear the lag within the SLA
var rateRequiredToClearLag = lag / (double) sla.toSeconds();
targetRate = targetRate + rateRequiredToClearLag;
}
// We need to invert the calculation because we need to scale _up_ to the target rate, not down
return TriggerResult.inverted(trigger, consumerRate, targetRate);
return TriggerResult.inverted(trigger, consumerRate.orElse(targetRate), targetRate);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
Expand Down

0 comments on commit c18c0a2

Please sign in to comment.