Skip to content

Improve streamer events #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 28, 2025
Merged

Conversation

llucax
Copy link
Contributor

@llucax llucax commented May 28, 2025

This PR contains several improvements to streamer events:

  • Remove Event suffix from stream events (for shorter names)
  • Make stream event dataclasses not keyword-only (for more compact pattern matching)
  • Add a StreamFatalError event (for errors when the stream stops for good and can't be retried)
  • Replace StreamStopped with StreamRetrying (only sent when the stream is retrying, not when it stops for good)

It also includes some minor improvements and fixes:

  • Send some valid messages in test_messages_on_retry
  • Lower the retry interval to 0.0 in tests
  • Do a proper full comparison for events in tests
  • Fix example indentation and blank line
  • Fix typo
  • Improve release notes formatting

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 11:25
@llucax llucax requested a review from a team as a code owner May 28, 2025 11:25
@llucax llucax self-assigned this May 28, 2025
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:code Affects the code in general labels May 28, 2025
@llucax llucax requested a review from Marenz May 28, 2025 11:25
@llucax llucax added this to the v0.9.0 milestone May 28, 2025
Copy link

@Copilot 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 refines the event system used by the streaming client by renaming and adjusting the stream events for clearer semantics and improved pattern matching. Key changes include:

  • Removing the "Event" suffix and renaming events (e.g. StreamStartedEvent → StreamStarted, StreamStoppedEvent → StreamRetrying) and introducing a new StreamFatalError event.
  • Updating tests to reflect the new event names, renaming error helper function to make_error, and adjusting expected behaviors.
  • Enhancing documentation in the release notes to reflect these updates.

Reviewed Changes

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

File Description
tests/streaming/test_grpc_stream_broadcaster.py Updated tests to use new event names and adjusted error simulation.
src/frequenz/client/base/streaming.py Modified event dataclasses, removed kw_only, and updated event handling.
RELEASE_NOTES.md Edited release notes to align with new event names and examples.
Comments suppressed due to low confidence (1)

tests/streaming/test_grpc_stream_broadcaster.py:48

  • [nitpick] The renaming from 'mock_error' to 'make_error' provides a clearer description of the function's purpose; however, please ensure that this naming is consistent across the tests to avoid any confusion.
def make_error() -> grpc.aio.AioRpcError:

llucax added 10 commits May 28, 2025 14:21
"Example:" is a section, so it cannot have a black line after it. Also
it should be properly indented to be rendered correctly.

Signed-off-by: Leandro Lucarella <[email protected]>
There is no need for the extra indentation inside the code block.

Signed-off-by: Leandro Lucarella <[email protected]>
The suffix doesn't add a lot of extra clarity and make names too long.

Signed-off-by: Leandro Lucarella <[email protected]>
Since all attributes have different types, it is not too error prone
to allow using positional arguments, and this makes the dataclass
automatically provides a `__match__` dunder method that allows for less
verbose match syntax.

We also update examples to use the match syntax to extra the event
information more easily.

Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
This event is sent when the stream is about to stop for good due to an
error (this event is NOT sent when the stream stops due to normal stream
termination).

Signed-off-by: Leandro Lucarella <[email protected]>
Only the types of the events were checked by the tests, not their state,
which doesn't really validate everything works properly.

We couldn't do a proper full comparison because we were using mocks
inside the error object, and mocks have non-deterministic
representations, as they have a unique ID.

To fix this we just create a full gRPC error instance. This is not
enough though, we also need to use a specific instance because 2 gRPC
error created the same are not equal.

Finally, we also need to set the retry strategy jitter to 0 so we can
make sure we have a predictable retry_time.

Signed-off-by: Leandro Lucarella <[email protected]>
This is just to speed up tests, we don't really need to wait. This also
uncovered a bug in the creation of the `StreamStopped` instance, which
was converting `0.0` to `None`.

Signed-off-by: Leandro Lucarella <[email protected]>
This also ensures the stream is really being restarted.

Signed-off-by: Leandro Lucarella <[email protected]>
The new event is sent only when the stream will retry reconnecting
instead of every time the stream stops, as this information is less
important. When the stream stops, 2 things can happen, it is retried or
it finishes. The new event covers the retry case, and the case when
it finishes is covered by the receiver being closed.

With the current approach, we also needed to consume from the retry
strategy even if no retry was going to be attempted, so with this change
we can now only consume from the retry strategy when we actually want
to retry.

Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax force-pushed the streamer-events branch from cbd9a39 to db56d5a Compare May 28, 2025 12:25
@llucax llucax modified the milestones: v0.9.0, v0.11.0 May 28, 2025
@llucax llucax added this pull request to the merge queue May 28, 2025
Merged via the queue into frequenz-floss:v0.x.x with commit 59efdb5 May 28, 2025
5 checks passed
@llucax llucax deleted the streamer-events branch May 28, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:code Affects the code in general part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants