Skip to content

feat(serverless): add health check spec to containers #725

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 8 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scaleway-async/scaleway_async/container/v1beta1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from .types import TriggerInputType
from .types import TriggerStatus
from .content import TRIGGER_TRANSIENT_STATUSES
from .types import ContainerHealthCheckSpecHTTPProbe
from .types import ContainerHealthCheckSpecTCPProbe
from .types import ContainerHealthCheckSpec
from .types import ContainerScalingOption
from .types import SecretHashedValue
from .types import TriggerMnqNatsClientConfig
Expand Down Expand Up @@ -100,6 +103,9 @@
"TriggerInputType",
"TriggerStatus",
"TRIGGER_TRANSIENT_STATUSES",
"ContainerHealthCheckSpecHTTPProbe",
"ContainerHealthCheckSpecTCPProbe",
"ContainerHealthCheckSpec",
"ContainerScalingOption",
"SecretHashedValue",
"TriggerMnqNatsClientConfig",
Expand Down
8 changes: 8 additions & 0 deletions scaleway-async/scaleway_async/container/v1beta1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ListTokensRequestOrderBy,
ListTriggersRequestOrderBy,
Container,
ContainerHealthCheckSpec,
ContainerScalingOption,
CreateContainerRequest,
CreateCronRequest,
Expand Down Expand Up @@ -603,6 +604,7 @@ async def create_container(
sandbox: Optional[ContainerSandbox] = None,
local_storage_limit: Optional[int] = None,
scaling_option: Optional[ContainerScalingOption] = None,
health_check: Optional[ContainerHealthCheckSpec] = None,
) -> Container:
"""
Create a new container.
Expand Down Expand Up @@ -631,6 +633,7 @@ async def create_container(
:param scaling_option: Possible values:
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
- cpu_usage_threshold: Scale depending on the CPU usage of a container instance.
:param health_check: Health check configuration of the container.
:return: :class:`Container <Container>`

Usage:
Expand Down Expand Up @@ -671,6 +674,7 @@ async def create_container(
sandbox=sandbox,
local_storage_limit=local_storage_limit,
scaling_option=scaling_option,
health_check=health_check,
),
self.client,
),
Expand Down Expand Up @@ -702,6 +706,7 @@ async def update_container(
sandbox: Optional[ContainerSandbox] = None,
local_storage_limit: Optional[int] = None,
scaling_option: Optional[ContainerScalingOption] = None,
health_check: Optional[ContainerHealthCheckSpec] = None,
) -> Container:
"""
Update an existing container.
Expand Down Expand Up @@ -730,6 +735,8 @@ async def update_container(
:param scaling_option: Possible values:
- concurrent_requests_threshold: Scale depending on the number of concurrent requests being processed per container instance.
- cpu_usage_threshold: Scale depending on the CPU usage of a container instance.
:param health_check: Health check configuration of the container.

:return: :class:`Container <Container>`

Usage:
Expand Down Expand Up @@ -770,6 +777,7 @@ async def update_container(
sandbox=sandbox,
local_storage_limit=local_storage_limit,
scaling_option=scaling_option,
health_check=health_check,
),
self.client,
),
Expand Down
158 changes: 142 additions & 16 deletions scaleway-async/scaleway_async/container/v1beta1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
resolve_one_of,
)
from .types import (
ContainerHealthCheckSpecHTTPProbe,
ContainerHealthCheckSpecTCPProbe,
ContainerHealthCheckSpec,
ContainerScalingOption,
SecretHashedValue,
Container,
Expand Down Expand Up @@ -45,6 +48,69 @@
)


def unmarshal_ContainerHealthCheckSpecHTTPProbe(
data: Any,
) -> ContainerHealthCheckSpecHTTPProbe:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ContainerHealthCheckSpecHTTPProbe' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("path", None)
if field is not None:
args["path"] = field

return ContainerHealthCheckSpecHTTPProbe(**args)


def unmarshal_ContainerHealthCheckSpecTCPProbe(
data: Any,
) -> ContainerHealthCheckSpecTCPProbe:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ContainerHealthCheckSpecTCPProbe' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

return ContainerHealthCheckSpecTCPProbe(**args)


def unmarshal_ContainerHealthCheckSpec(data: Any) -> ContainerHealthCheckSpec:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ContainerHealthCheckSpec' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("failure_threshold", None)
if field is not None:
args["failure_threshold"] = field

field = data.get("http", None)
if field is not None:
args["http"] = unmarshal_ContainerHealthCheckSpecHTTPProbe(field)
else:
args["http"] = None

field = data.get("tcp", None)
if field is not None:
args["tcp"] = unmarshal_ContainerHealthCheckSpecTCPProbe(field)
else:
args["tcp"] = None

field = data.get("interval", None)
if field is not None:
args["interval"] = field
else:
args["interval"] = None

return ContainerHealthCheckSpec(**args)


def unmarshal_ContainerScalingOption(data: Any) -> ContainerScalingOption:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -139,22 +205,6 @@ def unmarshal_Container(data: Any) -> Container:
if field is not None:
args["registry_image"] = field

field = data.get("max_concurrency", None)
if field is not None:
args["max_concurrency"] = field

field = data.get("domain_name", None)
if field is not None:
args["domain_name"] = field

field = data.get("protocol", None)
if field is not None:
args["protocol"] = field

field = data.get("port", None)
if field is not None:
args["port"] = field

field = data.get("timeout", None)
if field is not None:
args["timeout"] = field
Expand All @@ -173,6 +223,22 @@ def unmarshal_Container(data: Any) -> Container:
else:
args["description"] = None

field = data.get("max_concurrency", None)
if field is not None:
args["max_concurrency"] = field

field = data.get("domain_name", None)
if field is not None:
args["domain_name"] = field

field = data.get("protocol", None)
if field is not None:
args["protocol"] = field

field = data.get("port", None)
if field is not None:
args["port"] = field

field = data.get("secret_environment_variables", None)
if field is not None:
args["secret_environment_variables"] = (
Expand Down Expand Up @@ -203,6 +269,12 @@ def unmarshal_Container(data: Any) -> Container:
else:
args["scaling_option"] = None

field = data.get("health_check", None)
if field is not None:
args["health_check"] = unmarshal_ContainerHealthCheckSpec(field)
else:
args["health_check"] = None

field = data.get("created_at", None)
if field is not None:
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
Expand Down Expand Up @@ -696,6 +768,50 @@ def unmarshal_ListTriggersResponse(data: Any) -> ListTriggersResponse:
return ListTriggersResponse(**args)


def marshal_ContainerHealthCheckSpecHTTPProbe(
request: ContainerHealthCheckSpecHTTPProbe,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.path is not None:
output["path"] = request.path

return output


def marshal_ContainerHealthCheckSpecTCPProbe(
request: ContainerHealthCheckSpecTCPProbe,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

return output


def marshal_ContainerHealthCheckSpec(
request: ContainerHealthCheckSpec,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}
output.update(
resolve_one_of(
[
OneOfPossibility("http", request.http),
OneOfPossibility("tcp", request.tcp),
]
),
)

if request.failure_threshold is not None:
output["failure_threshold"] = request.failure_threshold

if request.interval is not None:
output["interval"] = request.interval

return output


def marshal_ContainerScalingOption(
request: ContainerScalingOption,
defaults: ProfileDefaults,
Expand Down Expand Up @@ -799,6 +915,11 @@ def marshal_CreateContainerRequest(
request.scaling_option, defaults
)

if request.health_check is not None:
output["health_check"] = marshal_ContainerHealthCheckSpec(
request.health_check, defaults
)

return output


Expand Down Expand Up @@ -1043,6 +1164,11 @@ def marshal_UpdateContainerRequest(
request.scaling_option, defaults
)

if request.health_check is not None:
output["health_check"] = marshal_ContainerHealthCheckSpec(
request.health_check, defaults
)

return output


Expand Down
Loading