Skip to content

Commit

Permalink
task: further mocks and tests for autoscaling logic
Browse files Browse the repository at this point in the history
* reset context mocks after each run

* test for no metrics

* further tests and cleanup

* scaleUp and scaleDown utility tests

* more logging from autoscaler during scaling choices

* scale down test

* basic scaling tests completed
  • Loading branch information
aaronkvanmeerten authored Mar 1, 2024
1 parent eea5b5c commit f40e6b3
Show file tree
Hide file tree
Showing 3 changed files with 713 additions and 29 deletions.
23 changes: 16 additions & 7 deletions src/autoscaler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ export default class AutoscaleProcessor {
group.scalingOptions.scaleUpPeriodsCount,
group.scalingOptions.scaleDownPeriodsCount,
);
const metricInventoryPerPeriod: Array<Array<InstanceMetric>> =
await this.instanceTracker.getMetricInventoryPerPeriod(
ctx,
group.name,
maxPeriodCount,
group.scalingOptions.scalePeriod,
);
const metricInventoryPerPeriod = await this.instanceTracker.getMetricInventoryPerPeriod(
ctx,
group.name,
maxPeriodCount,
group.scalingOptions.scalePeriod,
);

const scaleMetrics = await this.updateDesiredCountIfNeeded(ctx, group, count, metricInventoryPerPeriod);
await this.audit.updateLastAutoScalerRun(ctx, group.name, scaleMetrics);
Expand Down Expand Up @@ -133,6 +132,11 @@ export default class AutoscaleProcessor {
desiredCount = group.scalingOptions.maxDesired;
}

ctx.logger.info(
`[AutoScaler] Increasing desired count to ${desiredCount} for group ${group.name} with ${count} instances`,
{ desiredCount },
);

await this.audit.saveAutoScalerActionItem(group.name, {
timestamp: Date.now(),
actionType: 'increaseDesiredCount',
Expand All @@ -151,6 +155,11 @@ export default class AutoscaleProcessor {
desiredCount = group.scalingOptions.minDesired;
}

ctx.logger.info(
`[AutoScaler] Reducing desired count to ${desiredCount} for group ${group.name} with ${count} instances`,
{ desiredCount },
);

await this.audit.saveAutoScalerActionItem(group.name, {
timestamp: Date.now(),
actionType: 'decreaseDesiredCount',
Expand Down
Loading

0 comments on commit f40e6b3

Please sign in to comment.