Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented Nov 24, 2025

This PR introduces a new metrics package compatible with the v1alpha8 API version, along with a new proto package for common protobuf conversion utilities. The changes deprecate the old enum_proto module in favor of the new proto.enum_from_proto function and improve deprecation messages across the codebase to include full module paths.

Key changes:

  • Adds new frequenz.client.common.proto package with enum_from_proto, datetime_from_proto, and datetime_to_proto utilities
  • Introduces frequenz.client.common.metrics package with comprehensive metric types (Metric, MetricSample, AggregatedMetricValue, Bounds, etc.) compatible with v1alpha8
  • Deprecates frequenz.client.common.enum_proto module with improved deprecation messages that include full module paths
  • Updates all existing deprecation messages to include full module paths for better clarity

@llucax llucax requested a review from a team as a code owner November 24, 2025 17:23
@llucax llucax requested review from Copilot and shsms November 24, 2025 17:23
@github-actions github-actions bot added 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 part:pagination Affects the pagination protobuf definitions labels Nov 24, 2025
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
We will start to expose conversion functions, for which we will always
use a sub-module called `proto` for these conversion functions, so we
we do the same with `enum_proto`.

The old version is kept as deprecated.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
These functions are copied from `frequenz-client-base` and renamed to
match the naming convention in this project. The functions in
`frequenz-client-base` will be eventually deprecated.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
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 PR introduces a new metrics package compatible with the v1alpha8 API version, along with a new proto package for common protobuf conversion utilities. The changes deprecate the old enum_proto module in favor of the new proto.enum_from_proto function and improve deprecation messages across the codebase to include full module paths.

Key changes:

  • Adds new frequenz.client.common.proto package with enum_from_proto, datetime_from_proto, and datetime_to_proto utilities
  • Introduces frequenz.client.common.metrics package with comprehensive metric types (Metric, MetricSample, AggregatedMetricValue, Bounds, etc.) compatible with v1alpha8
  • Deprecates frequenz.client.common.enum_proto module with improved deprecation messages that include full module paths
  • Updates all existing deprecation messages to include full module paths for better clarity

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pyproject.toml Adds protobuf and hypothesis dependencies with types-protobuf for mypy
src/frequenz/client/common/proto/__init__.py New package exporting protobuf conversion utilities
src/frequenz/client/common/proto/_enum.py New module with enum_from_proto function moved from enum_proto
src/frequenz/client/common/proto/_timestamp.py New module with datetime conversion utilities
src/frequenz/client/common/metrics/__init__.py New package exporting metric-related types
src/frequenz/client/common/metrics/_metric.py Defines Metric enum with all supported metric types
src/frequenz/client/common/metrics/_bounds.py Defines Bounds dataclass for metric constraints
src/frequenz/client/common/metrics/_sample.py Defines MetricSample, AggregatedMetricValue, and related types
src/frequenz/client/common/metrics/proto/__init__.py Exports protobuf conversion functions for metrics
src/frequenz/client/common/metrics/proto/_bounds.py Implements bounds_from_proto conversion
src/frequenz/client/common/metrics/proto/_sample.py Implements metric sample protobuf conversions with issue tracking
src/frequenz/client/common/enum_proto.py Deprecates enum_from_proto with message pointing to new location
src/frequenz/client/common/pagination/__init__.py Updates deprecation messages to include full module paths
src/frequenz/client/common/microgrid/components/__init__.py Updates deprecation messages for from_proto methods
src/frequenz/client/common/microgrid/electrical_components/__init__.py Updates deprecation messages for from_proto methods
src/frequenz/client/common/metric/__init__.py Updates deprecation message for from_proto method
tests/test_streaming.py Updates import to use new proto.enum_from_proto
tests/test_enum_proto.py Simplifies tests to only check deprecation warnings
tests/test_client_common.py Adds deprecation warning checks to existing tests
tests/proto/test_enum.py New comprehensive tests for enum_from_proto
tests/proto/test_datetime.py New tests for datetime conversion using hypothesis
tests/metrics/test_bounds.py New tests for Bounds class
tests/metrics/test_sample.py New tests for MetricSample and AggregatedMetricValue
tests/metrics/proto/test_bounds.py New tests for bounds protobuf conversion
tests/metrics/proto/test_sample.py New tests for metric sample protobuf conversion

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

@github-actions github-actions bot added the part:docs Affects the documentation label Nov 24, 2025
@llucax llucax requested a review from cwasicki November 24, 2025 17:32
@llucax llucax added this to the v0.3.7 milestone Nov 24, 2025
@llucax llucax self-assigned this Nov 24, 2025
@llucax llucax enabled auto-merge November 25, 2025 14:40
@llucax
Copy link
Contributor Author

llucax commented Nov 25, 2025

Will update with some better test coverage.

@llucax
Copy link
Contributor Author

llucax commented Nov 25, 2025

Updated release notes to make them ready for a release.

@llucax llucax enabled auto-merge November 25, 2025 15:36


def bounds_from_proto(message: bounds_pb2.Bounds) -> Bounds: # noqa: DOC502
"""Create a `Bounds` from a protobuf message.
Copy link
Contributor

Choose a reason for hiding this comment

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

... Bounds object from ... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

major_issues: list[str],
minor_issues: list[str], # pylint: disable=unused-argument
) -> Bounds | None: # noqa: DOC502
"""Create a `Bounds` from a protobuf message.
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

"""The alternating current electric potential difference between phase 3 and phase 1."""

AC_CURRENT = metrics_pb2.METRIC_AC_CURRENT
"""The alternating current current."""
Copy link
Contributor

Choose a reason for hiding this comment

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

This reads weird. I suggest to replace all "alternating current" strings with AC. If you think this needs to be defined (tbh I don't) you could do so in the beginning of the class doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change, I thought these came from the API definition but it looks like it doesn't, not sure if it was in the previous versions or if it was generated by AI but I definitely didn't write that :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also replaced all "direct current" with "DC".

"""The metric is unspecified (this should not be used)."""

DC_VOLTAGE = metrics_pb2.METRIC_DC_VOLTAGE
"""The direct current voltage."""
Copy link
Contributor

Choose a reason for hiding this comment

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

We should state the units for all of the metrics.

Copy link
Contributor Author

@llucax llucax Nov 25, 2025

Choose a reason for hiding this comment

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

I would first fix it here:

And then replicate in this repo. We probably need to create an issue in this repo too so we don't forget.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I added the units in the issue, and also a few more I thought it was safe to assume, but there are still some I'm not sure about.

@llucax
Copy link
Contributor Author

llucax commented Nov 25, 2025

@llucax
Copy link
Contributor Author

llucax commented Nov 25, 2025

Updated.

The old `metric` package (not the singular) is based on the old API
v0.5. Since the package name didn't match the API naming scheme, we add
a new package with the right name to keep backwards compatibility.

These classes are based on the microgrid API client v0.18:
https://github.com/frequenz-floss/frequenz-client-microgrid-python/tree/v0.18.0/src/frequenz/client/microgrid/metrics

Only some minor changes were applied to make it closer to the API names,
for example, `MetricSample.sampled_at` was renamed to `.sample_time` to
match the new name.

Also the `MetricConnection` and `MetricConnectionCategory` classes were
added.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax disabled auto-merge November 26, 2025 08:27
@llucax llucax added this pull request to the merge queue Nov 26, 2025
Merged via the queue into frequenz-floss:v0.x.x with commit 7bdac82 Nov 26, 2025
6 checks passed
@llucax llucax deleted the metrics-alpha8 branch November 26, 2025 08:29
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:pagination Affects the pagination 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