Skip to content
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

✨Autoscaling: scale down while in use 🚨 #6898

Merged
Show file tree
Hide file tree
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 Dec 3, 2024
24d600e
need to patch when using moto
sanderegg Dec 3, 2024
8ce92da
initial test
sanderegg Dec 3, 2024
42c89a0
parametrize
sanderegg Dec 3, 2024
9df58c2
test ready for dynamic
sanderegg Dec 3, 2024
f397141
ongoing test
sanderegg Dec 3, 2024
9e02dc4
sort nodes
sanderegg Dec 9, 2024
e65be93
check sorting
sanderegg Dec 9, 2024
509a9b1
ruff
sanderegg Dec 9, 2024
abfd35c
refactor
sanderegg Dec 9, 2024
077d9a7
fixed terminating and terminated
sanderegg Dec 9, 2024
608e536
refactor
sanderegg Dec 9, 2024
2572c9f
test now finally works
sanderegg Dec 9, 2024
e3cf731
fixed test that started failing, but is correct
sanderegg Dec 9, 2024
a9fea5c
fixed test that started failing, but is correct in computational mode
sanderegg Dec 9, 2024
a1c65be
refactoring
sanderegg Dec 9, 2024
9ce628c
re-organize
sanderegg Dec 9, 2024
c3855d4
re-organize more
sanderegg Dec 9, 2024
41ee615
ruff
sanderegg Dec 9, 2024
cc1713b
prepare test for computations
sanderegg Dec 9, 2024
5c6df69
incompatible with osparc.io
sanderegg Dec 10, 2024
2007b8b
refactoring
sanderegg Dec 10, 2024
d1e0615
cleanup
sanderegg Dec 10, 2024
fe12f8c
refactor
sanderegg Dec 10, 2024
40bd952
refactor
sanderegg Dec 10, 2024
9f20912
ready to add the new test
sanderegg Dec 10, 2024
66a99ae
move fixture down
sanderegg Dec 10, 2024
31308cb
preparing test
sanderegg Dec 10, 2024
cc6bb77
fixed usage of resources
sanderegg Dec 10, 2024
45eb79a
move fixtures down
sanderegg Dec 10, 2024
eb13e88
ruff
sanderegg Dec 10, 2024
a9353d3
ongoing
sanderegg Dec 10, 2024
016531e
improve
sanderegg Dec 10, 2024
9361517
better log
sanderegg Dec 10, 2024
0c4a1e4
linter
sanderegg Dec 10, 2024
d8a77bd
linter
sanderegg Dec 10, 2024
f1abbfb
better logging
sanderegg Dec 10, 2024
1cac434
cleanup
sanderegg Dec 10, 2024
b72085d
test completed
sanderegg Dec 10, 2024
2f8bfef
cleanup
sanderegg Dec 10, 2024
f84796b
cleanup
sanderegg Dec 10, 2024
0de1bed
cleanup
sanderegg Dec 10, 2024
3a40819
improve logging
sanderegg Dec 11, 2024
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
3 changes: 2 additions & 1 deletion packages/aws-library/src/aws_library/ec2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ async def launch_instances(
)
instance_ids = [i["InstanceId"] for i in instances["Instances"]]
_logger.info(
"New instances launched: %s, waiting for them to start now...",
"%s New instances launched: %s, waiting for them to start now...",
len(instance_ids),
instance_ids,
)

Expand Down
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]
sanderegg marked this conversation as resolved.
Show resolved Hide resolved
) -> 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
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def _print_dynamic_instances(
f"{utils.color_encode_with_state(instance.name, instance.ec2_instance)}",
f"ID: {instance.ec2_instance.instance_id}",
f"AMI: {instance.ec2_instance.image_id}",
f"AMI name: {instance.ec2_instance.image.name}",
f"Type: {instance.ec2_instance.instance_type}",
f"Up: {utils.timedelta_formatting(time_now - instance.ec2_instance.launch_time, color_code=True)}",
f"ExtIP: {instance.ec2_instance.public_ip_address}",
Expand Down Expand Up @@ -183,7 +182,6 @@ def _print_computational_clusters(
f"Name: {cluster.primary.name}",
f"ID: {cluster.primary.ec2_instance.id}",
f"AMI: {cluster.primary.ec2_instance.image_id}",
f"AMI name: {cluster.primary.ec2_instance.image.name}",
f"Type: {cluster.primary.ec2_instance.instance_type}",
f"Up: {utils.timedelta_formatting(time_now - cluster.primary.ec2_instance.launch_time, color_code=True)}",
f"ExtIP: {cluster.primary.ec2_instance.public_ip_address}",
Expand Down Expand Up @@ -229,7 +227,6 @@ def _print_computational_clusters(
f"Name: {worker.name}",
f"ID: {worker.ec2_instance.id}",
f"AMI: {worker.ec2_instance.image_id}",
f"AMI name: {worker.ec2_instance.image.name}",
f"Type: {worker.ec2_instance.instance_type}",
f"Up: {utils.timedelta_formatting(time_now - worker.ec2_instance.launch_time, color_code=True)}",
f"ExtIP: {worker.ec2_instance.public_ip_address}",
Expand Down
Loading
Loading