Skip to content

Commit

Permalink
the fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Sep 5, 2024
1 parent 37ce5ae commit 826707d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 11 additions & 1 deletion services/autoscaling/src/simcore_service_autoscaling/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import defaultdict
from collections.abc import Generator
from dataclasses import dataclass, field
from dataclasses import dataclass, field, fields
from typing import Any, TypeAlias

from aws_library.ec2 import EC2InstanceData, EC2InstanceType, Resources
Expand Down Expand Up @@ -212,3 +212,13 @@ class BufferPoolManager:

def __repr__(self) -> str:
return f"BufferPoolManager({dict(self.buffer_pools)})"

def flatten_buffer_pool(self) -> BufferPool:
"""returns a flattened buffer pool with all the EC2InstanceData"""
flat_pool = BufferPool()

for buffer_pool in self.buffer_pools.values():
for f in fields(BufferPool):
getattr(flat_pool, f.name).update(getattr(buffer_pool, f.name))

return flat_pool
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ def __post_init__(self) -> None:
def update_from_buffer_pool_manager(
self, buffer_pool_manager: BufferPoolManager
) -> None:
for buffer_pool in buffer_pool_manager.buffer_pools.values():
for field_name in BUFFER_POOLS_METRICS_DEFINITIONS:
tracked_gauge = getattr(self, field_name)
assert isinstance(tracked_gauge, TrackedGauge) # nosec
instances = getattr(buffer_pool, field_name)
assert isinstance(instances, set) # nosec
tracked_gauge.update_from_instances(instances)
flat_pool = buffer_pool_manager.flatten_buffer_pool()

for field_name in BUFFER_POOLS_METRICS_DEFINITIONS:
tracked_gauge = getattr(self, field_name)
assert isinstance(tracked_gauge, TrackedGauge) # nosec
instances = getattr(flat_pool, field_name)
assert isinstance(instances, set) # nosec
tracked_gauge.update_from_instances(instances)


@dataclass(slots=True, kw_only=True)
Expand Down

0 comments on commit 826707d

Please sign in to comment.