Skip to content

Commit b7098eb

Browse files
authored
🐛Autoscaling: Buffer pools metrics always showing 0 (#6314)
1 parent 37ce5ae commit b7098eb

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

services/autoscaling/src/simcore_service_autoscaling/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import defaultdict
22
from collections.abc import Generator
3-
from dataclasses import dataclass, field
3+
from dataclasses import dataclass, field, fields
44
from typing import Any, TypeAlias
55

66
from 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

services/autoscaling/src/simcore_service_autoscaling/modules/instrumentation/_models.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)