Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented May 22, 2025

When no metric filter was passed to stream_sensor_data() the transform callback failed because the metrics argument wasn't passed when calling sensor_data_samples_from_proto() internally, making the gRPC streaming task stop with an unhandled exception.

This PR makes the metrics argument optional for sensor_data_samples_from_proto() to fix that.

A test case with no metric filters is added too, and the test case testing metric filters is improved to actually test the filtering.

llucax added 2 commits May 22, 2025 17:16
The test was requesting only one metric, but also sensing only one
metric, so the filtering wasn't being tested.

We also rename the test to make it more specific.

Signed-off-by: Leandro Lucarella <[email protected]>
When no metric filter was passed to `stream_sensor_data()` the transform
callback failed because the `metrics` argument wasn't passed when
calling `sensor_data_samples_from_proto()` internally, making the
gRPC streaming task stop with an unhandled exception.

This commit makes the `metrics` argument optional for
`sensor_data_samples_from_proto()` to fix that.

A test case with no metric filters is added too.

Signed-off-by: Leandro Lucarella <[email protected]>
@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 15:20
@llucax llucax requested review from a team as code owners May 22, 2025 15:20
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:client Affects the client code labels May 22, 2025
@llucax llucax added this to the v0.8.0 milestone May 22, 2025
@llucax llucax self-assigned this May 22, 2025
@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label May 22, 2025
@llucax
Copy link
Contributor Author

llucax commented May 22, 2025

Skipping release notes as this fixes unreleased code.

@llucax llucax added the type:bug Something isn't working label May 22, 2025
@llucax llucax enabled auto-merge May 22, 2025 15:21
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 ensures that when no metric filters are provided, stream_sensor_data() still returns all sensor metrics by making the metrics argument optional and updating the filtering logic. It also adds and refines tests to cover streaming with and without metric filters.

  • Allow sensor_data_samples_from_proto() to default to retrieving all metrics if none are specified.
  • Adjust the filter logic to handle None for metrics and add a test for streaming without filters, while improving the existing filter test.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/test_client.py Renamed and extended tests to cover streaming with one metric filter and without filters
src/frequenz/client/microgrid/_sensor_proto.py Made metrics parameter optional and updated filtering logic
Comments suppressed due to low confidence (2)

tests/test_client.py:915

  • [nitpick] The test name test_stream_sensor_data_one_metric suggests a single-metric scenario, but the test data yields two metrics when no filter is passed. Consider renaming the test to clarify that it's streaming without filters or adjust the data and assertions to match the intended filter behavior.
async def test_stream_sensor_data_one_metric(

tests/test_client.py:915

  • This test never passes a metrics filter to client.stream_sensor_data, so it's not validating filtered behavior. Add the appropriate metrics argument to the call and assert that only the specified metric samples are returned.
async def test_stream_sensor_data_one_metric(

Copy link
Contributor

@tiyash-basu-frequenz tiyash-basu-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

@llucax llucax added this pull request to the merge queue May 22, 2025
Merged via the queue into frequenz-floss:v0.x.x with commit a24d1c3 May 22, 2025
6 of 7 checks passed
@llucax llucax deleted the fix-sensor-streaming branch May 22, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:client Affects the client code part:tests Affects the unit, integration and performance (benchmarks) tests type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants