diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea20198..d9e04afd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 5149bc5c..1a88ae52 100644 --- a/README.md +++ b/README.md @@ -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/ @@ -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 diff --git a/deploy/lib/createContainers.js b/deploy/lib/createContainers.js index 9888d879..af31df9a 100644 --- a/deploy/lib/createContainers.js +++ b/deploy/lib/createContainers.js @@ -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; @@ -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) @@ -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. @@ -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) => @@ -165,8 +199,14 @@ module.exports = { port: container.port, http_option: container.httpOption, 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 diff --git a/examples/container/serverless.yml b/examples/container/serverless.yml index 2f7a89e7..3e611484 100644 --- a/examples/container/serverless.yml +++ b/examples/container/serverless.yml @@ -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