Skip to content

Commit fe01816

Browse files
authored
Fix responses with bounds (#268)
Fixes a bug where bounds of zero were ignored. Also ensures that we always return a pair of upper and lower bounds, where +/-inf is returned in case the bound is not set.
2 parents a1d123b + 14e53af commit fe01816

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
## Bug Fixes
1616

17-
* Remove invalid HasField check on scalar which can cause failure retrieving formula-aggregated metrics.
17+
* Fixes a bug where bounds of 0 were ignored and ensure the client always returns a pair of upper and lower bounds, were unset bounds are represented by +/- infinity.

src/frequenz/client/reporting/_types.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ def __iter__(self) -> Iterator[MetricSample]:
119119

120120
if self.has_bounds:
121121
for i, bound in enumerate(sample.bounds):
122-
if bound.lower:
123-
yield MetricSample(
124-
ts, mid, cid, f"{met}_bound_{i}_lower", bound.lower
125-
)
126-
if bound.upper:
127-
yield MetricSample(
128-
ts, mid, cid, f"{met}_bound_{i}_upper", bound.upper
129-
)
122+
lower = bound.lower if bound.HasField("lower") else -math.inf
123+
yield MetricSample(
124+
ts, mid, cid, f"{met}_bound_{i}_lower", lower
125+
)
126+
upper = bound.upper if bound.HasField("upper") else math.inf
127+
yield MetricSample(
128+
ts, mid, cid, f"{met}_bound_{i}_upper", upper
129+
)
130130

131131
for state in getattr(item, "state_snapshots", []):
132132
ts = datetime_from_proto(state.origin_time)

0 commit comments

Comments
 (0)