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

✨ added CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX env to facilitate testing (⚠️ devops) #5251

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
1 change: 1 addition & 0 deletions .env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CLUSTERS_KEEPER_MAX_MISSED_HEARTBEATS_BEFORE_CLUSTER_TERMINATION=5
CLUSTERS_KEEPER_PRIMARY_EC2_INSTANCES=null
CLUSTERS_KEEPER_TASK_INTERVAL=30
CLUSTERS_KEEPER_WORKERS_EC2_INSTANCES=null
CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX=""


DASK_SCHEDULER_HOST=dask-scheduler
Expand Down
1 change: 1 addition & 0 deletions services/clusters-keeper/.env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PRIMARY_EC2_INSTANCES_KEY_NAME=XXXXXXXXXX
PRIMARY_EC2_INSTANCES_SECURITY_GROUP_IDS=XXXXXXXXXX
PRIMARY_EC2_INSTANCES_SUBNET_ID=XXXXXXXXXX
EC2_CLUSTERS_KEEPER_SECRET_ACCESS_KEY=XXXXXXXXXX
CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX="testing"
LOG_FORMAT_LOCAL_DEV_ENABLED=True
RABBIT_HOST=rabbit
RABBIT_PASSWORD=test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
auto_default_from_env=True
)

CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX: str = Field(
...,
description="set a prefix to all machines created (useful for testing)",
)

CLUSTERS_KEEPER_RABBITMQ: RabbitSettings | None = Field(auto_default_from_env=True)

CLUSTERS_KEEPER_PROMETHEUS_INSTRUMENTATION_ENABLED: bool = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def get_cluster_name(
wallet_id: WalletID | None,
is_manager: bool,
) -> str:
return f"{CLUSTER_NAME_PREFIX}{'manager' if is_manager else 'worker'}-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}"
return f"{app_settings.CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}{CLUSTER_NAME_PREFIX}{'manager' if is_manager else 'worker'}-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}"


def _minimal_identification_tag(app_settings: ApplicationSettings) -> EC2Tags:
return {
AWSTagKey(".".join([_APPLICATION_TAG_KEY, "deploy"])): AWSTagValue(
app_settings.SWARM_STACK_NAME
AWSTagKey(".".join([_APPLICATION_TAG_KEY, "deploy",])): AWSTagValue(
f"{app_settings.CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}{app_settings.SWARM_STACK_NAME}"
)
}

Expand Down
1 change: 1 addition & 0 deletions services/clusters-keeper/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def app_environment(
"CLUSTERS_KEEPER_EC2_ACCESS_KEY_ID": faker.pystr(),
"CLUSTERS_KEEPER_EC2_SECRET_ACCESS_KEY": faker.pystr(),
"CLUSTERS_KEEPER_PRIMARY_EC2_INSTANCES": "{}",
"CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX": faker.pystr(),
"PRIMARY_EC2_INSTANCES_KEY_NAME": faker.pystr(),
"PRIMARY_EC2_INSTANCES_SECURITY_GROUP_IDS": json.dumps(
faker.pylist(allowed_types=(str,))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ async def _assert_cluster_instance_created(
assert all("Value" in x for x in instance_ec2_tags)

_EXPECTED_TAGS: dict[str, str] = {
f"{_APPLICATION_TAG_KEY}.deploy": app_settings.SWARM_STACK_NAME,
f"{_APPLICATION_TAG_KEY}.deploy": f"{app_settings.CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}{app_settings.SWARM_STACK_NAME}",
f"{_APPLICATION_TAG_KEY}.version": f"{APP_VERSION}",
"Name": f"{CLUSTER_NAME_PREFIX}manager-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}",
"Name": f"{app_settings.CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}{CLUSTER_NAME_PREFIX}manager-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}",
"user_id": f"{user_id}",
"wallet_id": f"{wallet_id}",
"osparc-tag": "the pytest tag is here",
Expand Down
4 changes: 2 additions & 2 deletions services/clusters-keeper/tests/unit/test_utils_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def test_get_cluster_name(
get_cluster_name(
app_settings, user_id=user_id, wallet_id=wallet_id, is_manager=True
)
== f"osparc-computational-cluster-manager-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}"
== f"{app_settings.CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}osparc-computational-cluster-manager-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}"
)
# worker
assert (
get_cluster_name(
app_settings, user_id=user_id, wallet_id=wallet_id, is_manager=False
)
== f"osparc-computational-cluster-worker-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}"
== f"{app_settings.CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}osparc-computational-cluster-worker-{app_settings.SWARM_STACK_NAME}-user_id:{user_id}-wallet_id:{wallet_id}"
)


Expand Down
1 change: 1 addition & 0 deletions services/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ services:
- CLUSTERS_KEEPER_EC2_ENDPOINT=${CLUSTERS_KEEPER_EC2_ENDPOINT}
- CLUSTERS_KEEPER_EC2_REGION_NAME=${CLUSTERS_KEEPER_EC2_REGION_NAME}
- CLUSTERS_KEEPER_EC2_SECRET_ACCESS_KEY=${CLUSTERS_KEEPER_EC2_SECRET_ACCESS_KEY}
- CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX=${CLUSTERS_KEEPER_EC2_INSTANCES_PREFIX}
- LOG_FORMAT_LOCAL_DEV_ENABLED=${LOG_FORMAT_LOCAL_DEV_ENABLED}
- CLUSTERS_KEEPER_PRIMARY_EC2_INSTANCES=${CLUSTERS_KEEPER_PRIMARY_EC2_INSTANCES}
- PRIMARY_EC2_INSTANCES_ALLOWED_TYPES=${PRIMARY_EC2_INSTANCES_ALLOWED_TYPES}
Expand Down
Loading