Skip to content

Aggregate all metric config bounds into a BoundsSet - #268

Merged
llucax merged 3 commits into
frequenz-floss:v0.x.xfrom
llucax:metric-config-bounds-set
Aug 14, 2026
Merged

Aggregate all metric config bounds into a BoundsSet#268
llucax merged 3 commits into
frequenz-floss:v0.x.xfrom
llucax:metric-config-bounds-set

Conversation

@llucax

@llucax llucax commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

ElectricalComponent.metric_config_bounds comes from the repeated MetricConfigBounds metric_config_bounds wire field, which is not a protobuf map. The converter nonetheless keyed a dict by metric and did bounds[metric] = ... on each entry, so when a metric appeared more than once the later entry silently overwrote the earlier one. Conflicting operational limits were lost with no diagnostic on the returned mapping or electrical_component_from_proto_with_issues().

Aggregate every entry for a metric instead, reusing bounds_set_from_proto. A metric whose entries are all well-formed maps to a BoundsSet (their union); a metric with any malformed entry maps to an InvalidBoundsSet preserving all the raw bounds in wire order, so the conflict stays inspectable.

As a consequence the field is now typed Mapping[Metric | int, BoundsSet | InvalidBoundsSet], and get_metric_config_bounds() resolves an entry to a valid BoundsSet (defaulting to the unbounded BoundsSet()) or raises InvalidBoundsSetError.

llucax added 3 commits August 14, 2026 14:26
`_bounds_set_from_proto` converts a sequence of protobuf `Bounds` into
a `BoundsSet | InvalidBoundsSet`. That is a bounds converter, so its
natural home is `_bounds.py` next to `bounds_from_proto2` (which it
calls), not `_sample.py`, where it only happened to be first needed.

Relocating it lets other converters reuse it without reaching into the
sample module — in particular the electrical-component metric config
bounds converter, which is about to aggregate duplicate metrics through
the same helper.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
`bounds_set_from_proto` is the multi-bound counterpart of the public
`bounds_from_proto2`: it converts a `repeated Bounds` field into a
single `BoundsSet | InvalidBoundsSet`, surfacing malformed data at the
type level.

It was module-private, but any client reading a repeated bounds field
needs the exact same conversion, so we better expose it in the public
package.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
`ElectricalComponent.metric_config_bounds` comes from the `repeated
MetricConfigBounds metric_config_bounds` wire field, which is *not* a
protobuf map. The converter nonetheless keyed a dict by metric and did
`bounds[metric] = ...` on each entry, so when a metric appeared more
than once the later entry silently overwrote the earlier one.
Conflicting operational limits were lost with no diagnostic on the
returned mapping or `electrical_component_from_proto_with_issues()`.

Aggregate every entry for a metric instead, reusing
`bounds_set_from_proto`. A metric whose entries are all well-formed maps
to a `BoundsSet` (their union); a metric with any malformed entry maps
to an `InvalidBoundsSet` preserving all the raw bounds in wire order,
so the conflict stays inspectable.

As a consequence the field is now typed `Mapping[Metric | int,
BoundsSet | InvalidBoundsSet]`, and `get_metric_config_bounds()`
resolves an entry to a valid `BoundsSet` (defaulting to the unbounded
`BoundsSet()`) or raises `InvalidBoundsSetError`.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax
llucax requested a review from a team as a code owner August 14, 2026 12:30
@llucax
llucax requested review from florian-wagner-frequenz and removed request for a team August 14, 2026 12:30
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:metrics Affects the metrics protobuf definitions part:microgrid Affects the microgrid protobuf definitions labels Aug 14, 2026
@llucax llucax self-assigned this Aug 14, 2026
@llucax llucax added this to the v0.4.1 milestone Aug 14, 2026
@llucax
llucax enabled auto-merge August 14, 2026 12:31
@llucax
llucax added this pull request to the merge queue Aug 14, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit 9d02f48 Aug 14, 2026
9 checks passed
@llucax
llucax deleted the metric-config-bounds-set branch August 14, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:metrics Affects the metrics protobuf definitions part:microgrid Affects the microgrid protobuf definitions part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants