Skip to content

Commit 2c91a75

Browse files
cyclimseBemilie
andauthored
feat(containers): backport scaling option + bump to 0.4.14 (#252)
* feat(ci): add simple publish workflow + add userAgent * fix: do the same for registry client * fix: updated changelog entry + lock * feat(container): add healthCheck support * fix: format * feat: add scaling option + bump version * docs: pleonasm * fix: comment maxConcurrency in README Co-authored-by: Emilie BOUIN <[email protected]> --------- Co-authored-by: Emilie BOUIN <[email protected]>
1 parent 78a8689 commit 2c91a75

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 0.4.14
4+
5+
### Added
6+
7+
- Added `healthCheck` to define a health check for containers
8+
- Added `scalingOption` to allow scaling on concurrent requests, cpu usage or memory usage
9+
10+
### Fixed
11+
12+
- Updating an existing function or container `sandbox` option was not working
13+
14+
### Changed
15+
16+
- 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.
17+
318
## 0.4.13
419

520
### Changed

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,17 @@ custom:
200200
minScale: 0
201201
maxScale: 10
202202
203-
# Number of simultaneous requests to handle simultaneously
204-
maxConcurrency: 20
203+
# Configuration used to decide when to scale the container up or down
204+
scalingOption:
205+
# Can be one of: concurrentRequests, cpuUsage, memoryUsage
206+
type: concurrentRequests
207+
# Value to trigger scaling up
208+
# It's expressed in:
209+
# - concurrentRequests: number of requests
210+
# - cpuUsage: percentage of CPU usage
211+
# - memoryUsage: percentage of memory usage
212+
# Note that cpu and memory scaling are only available for minScale >= 1 containers
213+
threshold: 50
205214
206215
# Memory limit (in MiB)
207216
# Limits: https://www.scaleway.com/en/docs/serverless/containers/reference-content/containers-limitations/
@@ -252,6 +261,10 @@ custom:
252261
input:
253262
key-a: "value-a"
254263
key-b: "value-b"
264+
265+
# Deprecated: number of simultaneous requests to handle
266+
# Please use scalingOption of type concurrentRequests instead
267+
# maxConcurrency: 20
255268
```
256269

257270
## Supported commands

deploy/lib/createContainers.js

+40
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const singleSource = require("../../shared/singleSource");
55
const secrets = require("../../shared/secrets");
66
const domainUtils = require("../../shared/domains");
77

8+
const maxConcurrencyDeprecationWarning = `WARNING: maxConcurrency is deprecated and has been replaced by scalingOption of type: concurrentRequests.
9+
Please update your serverless.yml file.`;
10+
811
function adaptHealthCheckToAPI(healthCheck) {
912
if (!healthCheck) {
1013
return null;
@@ -25,6 +28,31 @@ function adaptHealthCheckToAPI(healthCheck) {
2528
};
2629
}
2730

31+
const scalingOptionToAPIProperty = {
32+
concurrentRequests: "concurrent_requests_threshold",
33+
cpuUsage: "cpu_usage_threshold",
34+
memoryUsage: "memory_usage_threshold",
35+
};
36+
37+
function adaptScalingOptionToAPI(scalingOption) {
38+
if (!scalingOption || !scalingOption.type) {
39+
return null;
40+
}
41+
42+
const property = scalingOptionToAPIProperty[scalingOption.type];
43+
if (!property) {
44+
throw new Error(
45+
`scalingOption.type must be one of: ${Object.keys(
46+
scalingOptionToAPIProperty
47+
).join(", ")}`
48+
);
49+
}
50+
51+
return {
52+
[property]: scalingOption.threshold,
53+
};
54+
}
55+
2856
module.exports = {
2957
createContainers() {
3058
return BbPromise.bind(this)
@@ -125,6 +153,7 @@ module.exports = {
125153
http_option: container.httpOption,
126154
sandbox: container.sandbox,
127155
health_check: adaptHealthCheckToAPI(container.healthCheck),
156+
scaling_option: adaptScalingOptionToAPI(container.scalingOption),
128157
};
129158

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

167+
// note about maxConcurrency deprecation
168+
if (container.maxConcurrency) {
169+
this.serverless.cli.log(maxConcurrencyDeprecationWarning);
170+
}
171+
138172
this.serverless.cli.log(`Creating container ${container.name}...`);
139173

140174
return this.createContainer(params).then((response) =>
@@ -166,8 +200,14 @@ module.exports = {
166200
http_option: container.httpOption,
167201
sandbox: container.sandbox,
168202
health_check: adaptHealthCheckToAPI(container.healthCheck),
203+
scaling_option: adaptScalingOptionToAPI(container.scalingOption),
169204
};
170205

206+
// note about maxConcurrency deprecation
207+
if (container.maxConcurrency) {
208+
this.serverless.cli.log(maxConcurrencyDeprecationWarning);
209+
}
210+
171211
this.serverless.cli.log(`Updating container ${container.name}...`);
172212

173213
// assign domains

examples/container/serverless.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ custom:
2626
# memoryLimit: 256
2727
# cpuLimit: 140
2828
# maxScale: 2
29-
# maxConcurrency: 50
29+
# scalingOption:
30+
# type: concurrentRequests
31+
# threshold: 50
3032
# timeout: "20s"
3133
# httpOption: redirected
3234
# Local environment variables - used only in given function

0 commit comments

Comments
 (0)