File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
services/autoscaling/src/simcore_service_autoscaling Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 11from collections import defaultdict
22from collections .abc import Generator
3- from dataclasses import dataclass , field
3+ from dataclasses import dataclass , field , fields
44from typing import Any , TypeAlias
55
66from aws_library .ec2 import EC2InstanceData , EC2InstanceType , Resources
@@ -212,3 +212,13 @@ class BufferPoolManager:
212212
213213 def __repr__ (self ) -> str :
214214 return f"BufferPoolManager({ dict (self .buffer_pools )} )"
215+
216+ def flatten_buffer_pool (self ) -> BufferPool :
217+ """returns a flattened buffer pool with all the EC2InstanceData"""
218+ flat_pool = BufferPool ()
219+
220+ for buffer_pool in self .buffer_pools .values ():
221+ for f in fields (BufferPool ):
222+ getattr (flat_pool , f .name ).update (getattr (buffer_pool , f .name ))
223+
224+ return flat_pool
Original file line number Diff line number Diff line change @@ -154,13 +154,14 @@ def __post_init__(self) -> None:
154154 def update_from_buffer_pool_manager (
155155 self , buffer_pool_manager : BufferPoolManager
156156 ) -> None :
157- for buffer_pool in buffer_pool_manager .buffer_pools .values ():
158- for field_name in BUFFER_POOLS_METRICS_DEFINITIONS :
159- tracked_gauge = getattr (self , field_name )
160- assert isinstance (tracked_gauge , TrackedGauge ) # nosec
161- instances = getattr (buffer_pool , field_name )
162- assert isinstance (instances , set ) # nosec
163- tracked_gauge .update_from_instances (instances )
157+ flat_pool = buffer_pool_manager .flatten_buffer_pool ()
158+
159+ for field_name in BUFFER_POOLS_METRICS_DEFINITIONS :
160+ tracked_gauge = getattr (self , field_name )
161+ assert isinstance (tracked_gauge , TrackedGauge ) # nosec
162+ instances = getattr (flat_pool , field_name )
163+ assert isinstance (instances , set ) # nosec
164+ tracked_gauge .update_from_instances (instances )
164165
165166
166167@dataclass (slots = True , kw_only = True )
You can’t perform that action at this time.
0 commit comments