-
Notifications
You must be signed in to change notification settings - Fork 32
✨Autoscaling: scale down while in use 🚨 #6898
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
sanderegg
merged 43 commits into
ITISFoundation:master
from
sanderegg:autoscaling/bugfix/scale-down-while-in-use
Dec 11, 2024
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
b65a42b
creating the test for the issue
sanderegg 24d600e
need to patch when using moto
sanderegg 8ce92da
initial test
sanderegg 42c89a0
parametrize
sanderegg 9df58c2
test ready for dynamic
sanderegg f397141
ongoing test
sanderegg 9e02dc4
sort nodes
sanderegg e65be93
check sorting
sanderegg 509a9b1
ruff
sanderegg abfd35c
refactor
sanderegg 077d9a7
fixed terminating and terminated
sanderegg 608e536
refactor
sanderegg 2572c9f
test now finally works
sanderegg e3cf731
fixed test that started failing, but is correct
sanderegg a9fea5c
fixed test that started failing, but is correct in computational mode
sanderegg a1c65be
refactoring
sanderegg 9ce628c
re-organize
sanderegg c3855d4
re-organize more
sanderegg 41ee615
ruff
sanderegg cc1713b
prepare test for computations
sanderegg 5c6df69
incompatible with osparc.io
sanderegg 2007b8b
refactoring
sanderegg d1e0615
cleanup
sanderegg fe12f8c
refactor
sanderegg 40bd952
refactor
sanderegg 9f20912
ready to add the new test
sanderegg 66a99ae
move fixture down
sanderegg 31308cb
preparing test
sanderegg cc6bb77
fixed usage of resources
sanderegg 45eb79a
move fixtures down
sanderegg eb13e88
ruff
sanderegg a9353d3
ongoing
sanderegg 016531e
improve
sanderegg 9361517
better log
sanderegg 0c4a1e4
linter
sanderegg d8a77bd
linter
sanderegg f1abbfb
better logging
sanderegg 1cac434
cleanup
sanderegg b72085d
test completed
sanderegg 2f8bfef
cleanup
sanderegg f84796b
cleanup
sanderegg 0de1bed
cleanup
sanderegg 3a40819
improve logging
sanderegg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
73 changes: 73 additions & 0 deletions
73
packages/pytest-simcore/src/pytest_simcore/helpers/autoscaling.py
This file contains hidden or 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,73 @@ | ||
| from collections.abc import Callable | ||
|
|
||
| import arrow | ||
| from aws_library.ec2 import EC2InstanceData | ||
| from models_library.generated_models.docker_rest_api import ( | ||
| Availability, | ||
| Node, | ||
| NodeState, | ||
| ) | ||
| from pytest_mock import MockType | ||
| from simcore_service_autoscaling.models import AssociatedInstance, Cluster | ||
| from simcore_service_autoscaling.utils.utils_docker import ( | ||
| _OSPARC_NODE_TERMINATION_PROCESS_LABEL_KEY, | ||
| _OSPARC_SERVICE_READY_LABEL_KEY, | ||
| _OSPARC_SERVICES_READY_DATETIME_LABEL_KEY, | ||
| ) | ||
|
|
||
|
|
||
| def assert_cluster_state( | ||
| spied_cluster_analysis: MockType, *, expected_calls: int, expected_num_machines: int | ||
| ) -> Cluster: | ||
| assert spied_cluster_analysis.call_count == expected_calls | ||
|
|
||
| assert isinstance(spied_cluster_analysis.spy_return, Cluster) | ||
| assert ( | ||
| spied_cluster_analysis.spy_return.total_number_of_machines() | ||
| == expected_num_machines | ||
| ) | ||
| print("current cluster state:", spied_cluster_analysis.spy_return) | ||
| cluster = spied_cluster_analysis.spy_return | ||
| spied_cluster_analysis.reset_mock() | ||
| return cluster | ||
|
|
||
|
|
||
| def create_fake_association( | ||
| create_fake_node: Callable[..., Node], | ||
| drained_machine_id: str | None, | ||
| terminating_machine_id: str | None, | ||
| ): | ||
| fake_node_to_instance_map = {} | ||
|
|
||
| async def _fake_node_creator( | ||
| _nodes: list[Node], ec2_instances: list[EC2InstanceData] | ||
| ) -> tuple[list[AssociatedInstance], list[EC2InstanceData]]: | ||
| def _create_fake_node_with_labels(instance: EC2InstanceData) -> Node: | ||
| if instance not in fake_node_to_instance_map: | ||
| fake_node = create_fake_node() | ||
| assert fake_node.spec | ||
| fake_node.spec.availability = Availability.active | ||
| assert fake_node.status | ||
| fake_node.status.state = NodeState.ready | ||
| assert fake_node.spec.labels | ||
| fake_node.spec.labels |= { | ||
| _OSPARC_SERVICES_READY_DATETIME_LABEL_KEY: arrow.utcnow().isoformat(), | ||
| _OSPARC_SERVICE_READY_LABEL_KEY: ( | ||
| "true" if instance.id != drained_machine_id else "false" | ||
| ), | ||
| } | ||
| if instance.id == terminating_machine_id: | ||
| fake_node.spec.labels |= { | ||
| _OSPARC_NODE_TERMINATION_PROCESS_LABEL_KEY: arrow.utcnow().isoformat() | ||
| } | ||
| fake_node_to_instance_map[instance] = fake_node | ||
| return fake_node_to_instance_map[instance] | ||
|
|
||
| associated_instances = [ | ||
| AssociatedInstance(node=_create_fake_node_with_labels(i), ec2_instance=i) | ||
| for i in ec2_instances | ||
| ] | ||
|
|
||
| return associated_instances, [] | ||
|
|
||
| return _fake_node_creator | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.