Skip to content

feat(containers): backport scaling option + bump to 0.4.14 #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 29, 2024
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.4.14

### Added

- Added `healthCheck` to define a health check for containers
- Added `scalingOption` to allow scaling on concurrent requests, cpu usage or memory usage

### Fixed

- Updating an existing function or container `sandbox` option was not working

### Changed

- Following the introduction of `scalingOption`, the `maxConcurrency` parameter is now deprecated. It will continue to work but we invite you to use `scalingOption` of type `concurrentRequests` instead.

## 0.4.13

### Changed
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,17 @@ custom:
minScale: 0
maxScale: 10

# Number of simultaneous requests to handle simultaneously
maxConcurrency: 20
# Configuration used to decide when to scale the container up or down
scalingOption:
# Can be one of: concurrentRequests, cpuUsage, memoryUsage
type: concurrentRequests
# Value to trigger scaling up
# It's expressed in:
# - concurrentRequests: number of requests
# - cpuUsage: percentage of CPU usage
# - memoryUsage: percentage of memory usage
# Note that cpu and memory scaling are only available for minScale >= 1 containers
threshold: 50

# Memory limit (in MiB)
# Limits: https://www.scaleway.com/en/docs/serverless/containers/reference-content/containers-limitations/
Expand Down Expand Up @@ -252,6 +261,10 @@ custom:
input:
key-a: "value-a"
key-b: "value-b"

# Deprecated: number of simultaneous requests to handle
# Please use scalingOption of type concurrentRequests instead
# maxConcurrency: 20
```

## Supported commands
Expand Down
40 changes: 40 additions & 0 deletions deploy/lib/createContainers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const singleSource = require("../../shared/singleSource");
const secrets = require("../../shared/secrets");
const domainUtils = require("../../shared/domains");

const maxConcurrencyDeprecationWarning = `WARNING: maxConcurrency is deprecated and has been replaced by scalingOption of type: concurrentRequests.
Please update your serverless.yml file.`;

function adaptHealthCheckToAPI(healthCheck) {
if (!healthCheck) {
return null;
Expand All @@ -25,6 +28,31 @@ function adaptHealthCheckToAPI(healthCheck) {
};
}

const scalingOptionToAPIProperty = {
concurrentRequests: "concurrent_requests_threshold",
cpuUsage: "cpu_usage_threshold",
memoryUsage: "memory_usage_threshold",
};

function adaptScalingOptionToAPI(scalingOption) {
if (!scalingOption || !scalingOption.type) {
return null;
}

const property = scalingOptionToAPIProperty[scalingOption.type];
if (!property) {
throw new Error(
`scalingOption.type must be one of: ${Object.keys(
scalingOptionToAPIProperty
).join(", ")}`
);
}

return {
[property]: scalingOption.threshold,
};
}

module.exports = {
createContainers() {
return BbPromise.bind(this)
Expand Down Expand Up @@ -125,6 +153,7 @@ module.exports = {
http_option: container.httpOption,
sandbox: container.sandbox,
health_check: adaptHealthCheckToAPI(container.healthCheck),
scaling_option: adaptScalingOptionToAPI(container.scalingOption),
};

// checking if there is custom_domains set on container creation.
Expand All @@ -135,6 +164,11 @@ module.exports = {
);
}

// note about maxConcurrency deprecation
if (container.maxConcurrency) {
this.serverless.cli.log(maxConcurrencyDeprecationWarning);
}

this.serverless.cli.log(`Creating container ${container.name}...`);

return this.createContainer(params).then((response) =>
Expand Down Expand Up @@ -166,8 +200,14 @@ module.exports = {
http_option: container.httpOption,
sandbox: container.sandbox,
health_check: adaptHealthCheckToAPI(container.healthCheck),
scaling_option: adaptScalingOptionToAPI(container.scalingOption),
};

// note about maxConcurrency deprecation
if (container.maxConcurrency) {
this.serverless.cli.log(maxConcurrencyDeprecationWarning);
}

this.serverless.cli.log(`Updating container ${container.name}...`);

// assign domains
Expand Down
4 changes: 3 additions & 1 deletion examples/container/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ custom:
# memoryLimit: 256
# cpuLimit: 140
# maxScale: 2
# maxConcurrency: 50
# scalingOption:
# type: concurrentRequests
# threshold: 50
# timeout: "20s"
# httpOption: redirected
# Local environment variables - used only in given function
Expand Down
Loading