Skip to content

Comments

Fix responses with bounds#268

Merged
cwasicki merged 1 commit intofrequenz-floss:v0.x.xfrom
cwasicki:bounds
Feb 17, 2026
Merged

Fix responses with bounds#268
cwasicki merged 1 commit intofrequenz-floss:v0.x.xfrom
cwasicki:bounds

Conversation

@cwasicki
Copy link
Contributor

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.

Copilot AI review requested due to automatic review settings February 16, 2026 19:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug in the bounds handling logic for metric samples. The issue occurred when bound values were exactly zero - they were incorrectly skipped due to Python's truthiness evaluation. The fix uses protobuf's HasField() method to properly distinguish between unset optional fields and fields with zero values, and ensures that both upper and lower bounds are always returned (using infinity values when not set).

Changes:

  • Fixed bug where zero-valued bounds were incorrectly ignored due to falsy evaluation
  • Ensured both upper and lower bounds are always yielded as pairs, using infinity defaults for unset values
  • Changed from conditional yielding based on truthiness to proper protobuf field presence checking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +122 to +129
lower = bound.lower if bound.HasField("lower") else -math.inf
yield MetricSample(
ts, mid, cid, f"{met}_bound_{i}_lower", lower
)
upper = bound.upper if bound.HasField("upper") else math.inf
yield MetricSample(
ts, mid, cid, f"{met}_bound_{i}_upper", upper
)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bounds handling logic has been updated to fix the bug where zero values were ignored, but there are no tests covering this functionality. Consider adding tests that verify:

  1. Bounds with zero values are properly returned
  2. Missing bounds return infinity values as expected
  3. Both upper and lower bounds are always yielded as pairs

This is important to prevent regression of the bug that was just fixed.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added the part:docs Affects the documentation label Feb 17, 2026
Copy link

@micaebe micaebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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>
Copy link

@stefan-brus-frequenz stefan-brus-frequenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cwasicki cwasicki added this pull request to the merge queue Feb 17, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit fe01816 Feb 17, 2026
6 checks passed
@cwasicki cwasicki deleted the bounds branch February 17, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants