Skip to content

Conversation

@cyiallou
Copy link
Contributor

  • Introduced StateRecord, a typed NamedTuple, to replace dict-based state records.
  • Replaced raw integer state values with proper enum names using ComponentStateCode and ComponentErrorCode.
  • Improved internal structure by splitting _extract_state_records() and _filter_alerts() into cleaner, testable units.
  • Added _resolve_enum_name() to map proto values to readable enum names.
  • Updated unit tests accordingly for enum-based comparisons and removed deprecated test cases.

This improves downstream use of state records, such as in alert visualisation and reporting.

- Introduced `StateRecord`, a typed NamedTuple, to replace dict-based
  state records.
- Replaced raw integer state values with proper enum names using
  `ComponentStateCode` and `ComponentErrorCode`.
- Improved internal structure by splitting `_extract_state_records()`
  and `_filter_alerts()` into cleaner, testable units.
- Added `_resolve_enum_name()` to map proto values to readable enum names.
- Updated unit tests accordingly for enum-based comparisons and removed
  deprecated test cases.

This improves downstream use of state records, such as in alert
visualisation and reporting.

Signed-off-by: cyiallou - Costas <[email protected]>
@cyiallou cyiallou requested a review from a team as a code owner July 10, 2025 15:41
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests labels Jul 10, 2025
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 refactors state extraction to use a strongly typed StateRecord named tuple and replaces raw integer state and error codes with enum-based names, improving clarity and testability.

  • Introduced StateRecord, _extract_state_records, _process_sample_group, and _resolve_enum_name to replace dict-based logic and centralize enum resolution.
  • Updated fetch_and_extract_state_durations to use the new extraction and filtering functions.
  • Revised tests to use enum values and removed deprecated delete_me tests.
  • Updated release notes to document the switch to StateRecord with enum names.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_frequenz_reporting.py Switched tests from raw ints to enum values; updated test logic
src/frequenz/reporting/_reporting.py Added StateRecord, split extraction/filtering, and enum mapping
RELEASE_NOTES.md Documented migration to StateRecord with descriptive enums
Comments suppressed due to low confidence (1)

tests/test_frequenz_reporting.py:167

  • The debug print statement should be removed from the test to avoid cluttering test output.
    print(test_case["alert_states"])

end_time=end_time,
resampling_period=resampling_period,
include_states=True,
include_bounds=False,
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

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

Pass include_states=True to _fetch_component_data so that state metrics are actually fetched for processing.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

check again

Copy link
Collaborator

@flora-hofmann-frequenz flora-hofmann-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 at first glace. The naming likely to change with updates in client-common though (also a topic for assets api that I would like to discuss next week). If you need this now it is probably good to move along, but we will have to rename once changes from the 'api-common' side are pulled through.

@cyiallou
Copy link
Contributor Author

If you need this now it is probably good to move along

This PR makes it easier to work with downstream because as it is now it accepts a list of integers as alert_states which means that you already need to know the Enum values from the ComponentStateCode so that you can pass them in and then you need to convert these values back to the Enum name to improve readability - which is not really convenient.

This code is used in the Alerts notebook on lib-notebooks.

@cyiallou cyiallou added this pull request to the merge queue Jul 14, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 14, 2025
The codebase requires `frequenz.client.common.enum_proto`, which was
added in v0.3.3. Earlier versions lack this module, causing test failures
in `pytest_min`.

Bumping the minimum version ensures compatibility with
`frequenz-repo-config`’s  min-dependency testing and avoids runtime
import errors.

Signed-off-by: cyiallou - Costas <[email protected]>
@github-actions github-actions bot added the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Jul 14, 2025
@cyiallou cyiallou added this pull request to the merge queue Jul 14, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 14, 2025
@cyiallou
Copy link
Contributor Author

Closing as this code has been moved to frequenz-lib-notebooks with this PR: frequenz-floss/frequenz-lib-notebooks#131

I will open another PR that will remove the parts of the code that have been moved.

@cyiallou cyiallou closed this Jul 22, 2025
@cyiallou cyiallou deleted the enhancement/fetch-states branch July 22, 2025 21:49
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: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