Aggregate all metric config bounds into a BoundsSet - #268
Merged
Conversation
`_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
requested review from
florian-wagner-frequenz
and removed request for
a team
August 14, 2026 12:30
llucax
enabled auto-merge
August 14, 2026 12:31
tiyash-basu-frequenz
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ElectricalComponent.metric_config_boundscomes from therepeated MetricConfigBounds metric_config_boundswire field, which is not a protobuf map. The converter nonetheless keyed a dict by metric and didbounds[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 orelectrical_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 aBoundsSet(their union); a metric with any malformed entry maps to anInvalidBoundsSetpreserving 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], andget_metric_config_bounds()resolves an entry to a validBoundsSet(defaulting to the unboundedBoundsSet()) or raisesInvalidBoundsSetError.