Skip to content

Commit 5099e83

Browse files
authored
chore(serverless): add fields for advanced scaling options (scaleway#708)
1 parent 627314b commit 5099e83

File tree

8 files changed

+222
-48
lines changed

8 files changed

+222
-48
lines changed

scaleway-async/scaleway_async/container/v1beta1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .types import TriggerInputType
2424
from .types import TriggerStatus
2525
from .content import TRIGGER_TRANSIENT_STATUSES
26+
from .types import ContainerScalingOption
2627
from .types import SecretHashedValue
2728
from .types import TriggerMnqNatsClientConfig
2829
from .types import TriggerMnqSqsClientConfig
@@ -99,6 +100,7 @@
99100
"TriggerInputType",
100101
"TriggerStatus",
101102
"TRIGGER_TRANSIENT_STATUSES",
103+
"ContainerScalingOption",
102104
"SecretHashedValue",
103105
"TriggerMnqNatsClientConfig",
104106
"TriggerMnqSqsClientConfig",

scaleway-async/scaleway_async/container/v1beta1/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ListTokensRequestOrderBy,
3030
ListTriggersRequestOrderBy,
3131
Container,
32+
ContainerScalingOption,
3233
CreateContainerRequest,
3334
CreateCronRequest,
3435
CreateDomainRequest,
@@ -595,6 +596,7 @@ async def create_container(
595596
http_option: Optional[ContainerHttpOption] = None,
596597
sandbox: Optional[ContainerSandbox] = None,
597598
local_storage_limit: Optional[int] = None,
599+
scaling_option: Optional[ContainerScalingOption] = None,
598600
) -> Container:
599601
"""
600602
Create a new container.
@@ -620,6 +622,8 @@ async def create_container(
620622
- enabled: Serve both HTTP and HTTPS traffic.
621623
:param sandbox: Execution environment of the container.
622624
:param local_storage_limit: Local storage limit of the container (in MB).
625+
:param scaling_option: Possible values:
626+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
623627
:return: :class:`Container <Container>`
624628
625629
Usage:
@@ -659,6 +663,7 @@ async def create_container(
659663
http_option=http_option,
660664
sandbox=sandbox,
661665
local_storage_limit=local_storage_limit,
666+
scaling_option=scaling_option,
662667
),
663668
self.client,
664669
),
@@ -689,6 +694,7 @@ async def update_container(
689694
http_option: Optional[ContainerHttpOption] = None,
690695
sandbox: Optional[ContainerSandbox] = None,
691696
local_storage_limit: Optional[int] = None,
697+
scaling_option: Optional[ContainerScalingOption] = None,
692698
) -> Container:
693699
"""
694700
Update an existing container.
@@ -714,6 +720,8 @@ async def update_container(
714720
- enabled: Serve both HTTP and HTTPS traffic.
715721
:param sandbox: Execution environment of the container.
716722
:param local_storage_limit: Local storage limit of the container (in MB).
723+
:param scaling_option: Possible values:
724+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
717725
:return: :class:`Container <Container>`
718726
719727
Usage:
@@ -753,6 +761,7 @@ async def update_container(
753761
http_option=http_option,
754762
sandbox=sandbox,
755763
local_storage_limit=local_storage_limit,
764+
scaling_option=scaling_option,
756765
),
757766
self.client,
758767
),

scaleway-async/scaleway_async/container/v1beta1/marshalling.py

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
resolve_one_of,
1111
)
1212
from .types import (
13+
ContainerScalingOption,
1314
SecretHashedValue,
1415
Container,
1516
Cron,
@@ -44,6 +45,23 @@
4445
)
4546

4647

48+
def unmarshal_ContainerScalingOption(data: Any) -> ContainerScalingOption:
49+
if not isinstance(data, dict):
50+
raise TypeError(
51+
"Unmarshalling the type 'ContainerScalingOption' failed as data isn't a dictionary."
52+
)
53+
54+
args: Dict[str, Any] = {}
55+
56+
field = data.get("concurrent_requests_threshold", None)
57+
if field is not None:
58+
args["concurrent_requests_threshold"] = field
59+
else:
60+
args["concurrent_requests_threshold"] = None
61+
62+
return ContainerScalingOption(**args)
63+
64+
4765
def unmarshal_SecretHashedValue(data: Any) -> SecretHashedValue:
4866
if not isinstance(data, dict):
4967
raise TypeError(
@@ -119,6 +137,18 @@ def unmarshal_Container(data: Any) -> Container:
119137
if field is not None:
120138
args["max_concurrency"] = field
121139

140+
field = data.get("domain_name", None)
141+
if field is not None:
142+
args["domain_name"] = field
143+
144+
field = data.get("protocol", None)
145+
if field is not None:
146+
args["protocol"] = field
147+
148+
field = data.get("port", None)
149+
if field is not None:
150+
args["port"] = field
151+
122152
field = data.get("timeout", None)
123153
if field is not None:
124154
args["timeout"] = field
@@ -137,18 +167,6 @@ def unmarshal_Container(data: Any) -> Container:
137167
else:
138168
args["description"] = None
139169

140-
field = data.get("domain_name", None)
141-
if field is not None:
142-
args["domain_name"] = field
143-
144-
field = data.get("protocol", None)
145-
if field is not None:
146-
args["protocol"] = field
147-
148-
field = data.get("port", None)
149-
if field is not None:
150-
args["port"] = field
151-
152170
field = data.get("secret_environment_variables", None)
153171
if field is not None:
154172
args["secret_environment_variables"] = (
@@ -173,6 +191,12 @@ def unmarshal_Container(data: Any) -> Container:
173191
if field is not None:
174192
args["region"] = field
175193

194+
field = data.get("scaling_option", None)
195+
if field is not None:
196+
args["scaling_option"] = unmarshal_ContainerScalingOption(field)
197+
else:
198+
args["scaling_option"] = None
199+
176200
return Container(**args)
177201

178202

@@ -644,6 +668,25 @@ def unmarshal_ListTriggersResponse(data: Any) -> ListTriggersResponse:
644668
return ListTriggersResponse(**args)
645669

646670

671+
def marshal_ContainerScalingOption(
672+
request: ContainerScalingOption,
673+
defaults: ProfileDefaults,
674+
) -> Dict[str, Any]:
675+
output: Dict[str, Any] = {}
676+
output.update(
677+
resolve_one_of(
678+
[
679+
OneOfPossibility(
680+
"concurrent_requests_threshold",
681+
request.concurrent_requests_threshold,
682+
),
683+
]
684+
),
685+
)
686+
687+
return output
688+
689+
647690
def marshal_Secret(
648691
request: Secret,
649692
defaults: ProfileDefaults,
@@ -722,6 +765,11 @@ def marshal_CreateContainerRequest(
722765
if request.local_storage_limit is not None:
723766
output["local_storage_limit"] = request.local_storage_limit
724767

768+
if request.scaling_option is not None:
769+
output["scaling_option"] = marshal_ContainerScalingOption(
770+
request.scaling_option, defaults
771+
)
772+
725773
return output
726774

727775

@@ -958,6 +1006,11 @@ def marshal_UpdateContainerRequest(
9581006
if request.local_storage_limit is not None:
9591007
output["local_storage_limit"] = request.local_storage_limit
9601008

1009+
if request.scaling_option is not None:
1010+
output["scaling_option"] = marshal_ContainerScalingOption(
1011+
request.scaling_option, defaults
1012+
)
1013+
9611014
return output
9621015

9631016

scaleway-async/scaleway_async/container/v1beta1/types.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ def __str__(self) -> str:
191191
return str(self.value)
192192

193193

194+
@dataclass
195+
class ContainerScalingOption:
196+
concurrent_requests_threshold: Optional[int]
197+
198+
194199
@dataclass
195200
class SecretHashedValue:
196201
key: str
@@ -381,34 +386,34 @@ class Container:
381386
Number of maximum concurrent executions of the container.
382387
"""
383388

384-
timeout: Optional[str]
389+
domain_name: str
385390
"""
386-
Processing time limit for the container.
391+
Domain name attributed to the contaioner.
387392
"""
388393

389-
error_message: Optional[str]
394+
protocol: ContainerProtocol
390395
"""
391-
Last error message of the container.
396+
Protocol the container uses.
392397
"""
393398

394-
description: Optional[str]
399+
port: int
395400
"""
396-
Description of the container.
401+
Port the container listens on.
397402
"""
398403

399-
domain_name: str
404+
timeout: Optional[str]
400405
"""
401-
Domain name attributed to the contaioner.
406+
Processing time limit for the container.
402407
"""
403408

404-
protocol: ContainerProtocol
409+
error_message: Optional[str]
405410
"""
406-
Protocol the container uses.
411+
Last error message of the container.
407412
"""
408413

409-
port: int
414+
description: Optional[str]
410415
"""
411-
Port the container listens on.
416+
Description of the container.
412417
"""
413418

414419
secret_environment_variables: List[SecretHashedValue]
@@ -438,6 +443,12 @@ class Container:
438443
Region in which the container will be deployed.
439444
"""
440445

446+
scaling_option: Optional[ContainerScalingOption]
447+
"""
448+
Possible values:
449+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
450+
"""
451+
441452

442453
@dataclass
443454
class Cron:
@@ -755,6 +766,12 @@ class CreateContainerRequest:
755766
Local storage limit of the container (in MB).
756767
"""
757768

769+
scaling_option: Optional[ContainerScalingOption]
770+
"""
771+
Possible values:
772+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
773+
"""
774+
758775

759776
@dataclass
760777
class CreateCronRequest:
@@ -1416,6 +1433,12 @@ class UpdateContainerRequest:
14161433
Local storage limit of the container (in MB).
14171434
"""
14181435

1436+
scaling_option: Optional[ContainerScalingOption]
1437+
"""
1438+
Possible values:
1439+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
1440+
"""
1441+
14191442

14201443
@dataclass
14211444
class UpdateCronRequest:

scaleway/scaleway/container/v1beta1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .types import TriggerInputType
2424
from .types import TriggerStatus
2525
from .content import TRIGGER_TRANSIENT_STATUSES
26+
from .types import ContainerScalingOption
2627
from .types import SecretHashedValue
2728
from .types import TriggerMnqNatsClientConfig
2829
from .types import TriggerMnqSqsClientConfig
@@ -99,6 +100,7 @@
99100
"TriggerInputType",
100101
"TriggerStatus",
101102
"TRIGGER_TRANSIENT_STATUSES",
103+
"ContainerScalingOption",
102104
"SecretHashedValue",
103105
"TriggerMnqNatsClientConfig",
104106
"TriggerMnqSqsClientConfig",

scaleway/scaleway/container/v1beta1/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ListTokensRequestOrderBy,
3030
ListTriggersRequestOrderBy,
3131
Container,
32+
ContainerScalingOption,
3233
CreateContainerRequest,
3334
CreateCronRequest,
3435
CreateDomainRequest,
@@ -591,6 +592,7 @@ def create_container(
591592
http_option: Optional[ContainerHttpOption] = None,
592593
sandbox: Optional[ContainerSandbox] = None,
593594
local_storage_limit: Optional[int] = None,
595+
scaling_option: Optional[ContainerScalingOption] = None,
594596
) -> Container:
595597
"""
596598
Create a new container.
@@ -616,6 +618,8 @@ def create_container(
616618
- enabled: Serve both HTTP and HTTPS traffic.
617619
:param sandbox: Execution environment of the container.
618620
:param local_storage_limit: Local storage limit of the container (in MB).
621+
:param scaling_option: Possible values:
622+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
619623
:return: :class:`Container <Container>`
620624
621625
Usage:
@@ -655,6 +659,7 @@ def create_container(
655659
http_option=http_option,
656660
sandbox=sandbox,
657661
local_storage_limit=local_storage_limit,
662+
scaling_option=scaling_option,
658663
),
659664
self.client,
660665
),
@@ -685,6 +690,7 @@ def update_container(
685690
http_option: Optional[ContainerHttpOption] = None,
686691
sandbox: Optional[ContainerSandbox] = None,
687692
local_storage_limit: Optional[int] = None,
693+
scaling_option: Optional[ContainerScalingOption] = None,
688694
) -> Container:
689695
"""
690696
Update an existing container.
@@ -710,6 +716,8 @@ def update_container(
710716
- enabled: Serve both HTTP and HTTPS traffic.
711717
:param sandbox: Execution environment of the container.
712718
:param local_storage_limit: Local storage limit of the container (in MB).
719+
:param scaling_option: Possible values:
720+
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
713721
:return: :class:`Container <Container>`
714722
715723
Usage:
@@ -749,6 +757,7 @@ def update_container(
749757
http_option=http_option,
750758
sandbox=sandbox,
751759
local_storage_limit=local_storage_limit,
760+
scaling_option=scaling_option,
752761
),
753762
self.client,
754763
),

0 commit comments

Comments
 (0)