mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Simplify get_dead_runners_in_ec2 a little bit, update runners
This commit is contained in:
parent
b775b5cfd6
commit
3c13eaa159
@ -99,44 +99,44 @@ def get_dead_runners_in_ec2(runners: RunnerDescriptions) -> RunnerDescriptions:
|
|||||||
def get_lost_ec2_instances(runners: RunnerDescriptions) -> List[dict]:
|
def get_lost_ec2_instances(runners: RunnerDescriptions) -> List[dict]:
|
||||||
client = boto3.client("ec2")
|
client = boto3.client("ec2")
|
||||||
reservations = client.describe_instances(
|
reservations = client.describe_instances(
|
||||||
Filters=[{"Name": "tag-key", "Values": ["github:runner-type"]}]
|
Filters=[{"Name": "tag-key", "Values": ["github:runner-type"]}],
|
||||||
)["Reservations"]
|
)["Reservations"]
|
||||||
lost_instances = []
|
# flatten the reservation into instances
|
||||||
offline_runners = [
|
instances = [
|
||||||
runner.name for runner in runners if runner.offline and not runner.busy
|
instance
|
||||||
|
for reservation in reservations
|
||||||
|
for instance in reservation["Instances"]
|
||||||
]
|
]
|
||||||
# Here we refresh the runners to get the most recent state
|
lost_instances = []
|
||||||
|
offline_runner_names = {
|
||||||
|
runner.name for runner in runners if runner.offline and not runner.busy
|
||||||
|
}
|
||||||
|
runner_names = {runner.name for runner in runners}
|
||||||
now = datetime.now().timestamp()
|
now = datetime.now().timestamp()
|
||||||
|
|
||||||
for reservation in reservations:
|
for instance in instances:
|
||||||
for instance in reservation["Instances"]:
|
# Do not consider instances started 20 minutes ago as problematic
|
||||||
# Do not consider instances started 20 minutes ago as problematic
|
if now - instance["LaunchTime"].timestamp() < 1200:
|
||||||
if now - instance["LaunchTime"].timestamp() < 1200:
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
runner_type = [
|
runner_type = [
|
||||||
tag["Value"]
|
tag["Value"]
|
||||||
for tag in instance["Tags"]
|
for tag in instance["Tags"]
|
||||||
if tag["Key"] == "github:runner-type"
|
if tag["Key"] == "github:runner-type"
|
||||||
][0]
|
][0]
|
||||||
# If there's no necessary labels in runner type it's fine
|
# If there's no necessary labels in runner type it's fine
|
||||||
if not (
|
if not (UNIVERSAL_LABEL in runner_type or runner_type in RUNNER_TYPE_LABELS):
|
||||||
UNIVERSAL_LABEL in runner_type or runner_type in RUNNER_TYPE_LABELS
|
continue
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if instance["InstanceId"] in offline_runners:
|
if instance["InstanceId"] in offline_runner_names:
|
||||||
lost_instances.append(instance)
|
lost_instances.append(instance)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if instance["State"]["Name"] == "running" and (
|
if (
|
||||||
not [
|
instance["State"]["Name"] == "running"
|
||||||
runner
|
and not instance["InstanceId"] in runner_names
|
||||||
for runner in runners
|
):
|
||||||
if runner.name == instance["InstanceId"]
|
lost_instances.append(instance)
|
||||||
]
|
|
||||||
):
|
|
||||||
lost_instances.append(instance)
|
|
||||||
|
|
||||||
return lost_instances
|
return lost_instances
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user