Skip to content

Commit eb4afd3

Browse files
committed
Fix responses with bounds
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. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
1 parent da122e0 commit eb4afd3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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)