forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛Bugfix/autoscaling does not scale above limit (ITISFoundation#5129)
- Loading branch information
Showing
8 changed files
with
376 additions
and
32 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/dask-task-models-library/src/dask_task_models_library/resource_constraints.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Any, TypeAlias | ||
|
||
from .constants import DASK_TASK_EC2_RESOURCE_RESTRICTION_KEY | ||
|
||
DaskTaskResources: TypeAlias = dict[str, Any] | ||
|
||
|
||
def create_ec2_resource_constraint_key(ec2_instance_type: str) -> str: | ||
return f"{DASK_TASK_EC2_RESOURCE_RESTRICTION_KEY}:{ec2_instance_type}" | ||
|
||
|
||
def get_ec2_instance_type_from_resources( | ||
task_resources: DaskTaskResources, | ||
) -> str | None: | ||
for resource_name in task_resources: | ||
if resource_name.startswith(DASK_TASK_EC2_RESOURCE_RESTRICTION_KEY): | ||
return resource_name.split(":")[-1] | ||
return None |
34 changes: 34 additions & 0 deletions
34
packages/dask-task-models-library/tests/test_resource_constraints.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from dask_task_models_library.constants import DASK_TASK_EC2_RESOURCE_RESTRICTION_KEY | ||
from dask_task_models_library.resource_constraints import ( | ||
create_ec2_resource_constraint_key, | ||
get_ec2_instance_type_from_resources, | ||
) | ||
from faker import Faker | ||
|
||
|
||
def test_create_ec2_resource_constraint_key(faker: Faker): | ||
faker_instance_type = faker.pystr() | ||
assert ( | ||
create_ec2_resource_constraint_key(faker_instance_type) | ||
== f"{DASK_TASK_EC2_RESOURCE_RESTRICTION_KEY}:{faker_instance_type}" | ||
) | ||
|
||
empty_instance_type = "" | ||
assert ( | ||
create_ec2_resource_constraint_key(empty_instance_type) | ||
== f"{DASK_TASK_EC2_RESOURCE_RESTRICTION_KEY}:" | ||
) | ||
|
||
|
||
def test_get_ec2_instance_type_from_resources(faker: Faker): | ||
empty_task_resources = {} | ||
assert get_ec2_instance_type_from_resources(empty_task_resources) is None | ||
no_ec2_types_in_resources = {"blahblah": 1} | ||
assert get_ec2_instance_type_from_resources(no_ec2_types_in_resources) is None | ||
|
||
faker_instance_type = faker.pystr() | ||
ec2_type_in_resources = {create_ec2_resource_constraint_key(faker_instance_type): 1} | ||
assert ( | ||
get_ec2_instance_type_from_resources(ec2_type_in_resources) | ||
== faker_instance_type | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.