Skip to content

Conversation

@shsms
Copy link
Contributor

@shsms shsms commented Oct 25, 2024

This change the default behaviour of GrpcStreamBroadcaster to not reconnect when the server closes the stream. This can be overridden by setting the retry_on_exhausted_stream parameter to True.

@shsms shsms requested a review from a team as a code owner October 25, 2024 14:40
@github-actions github-actions bot added the part:code Affects the code in general label Oct 25, 2024
@shsms shsms requested review from llucax and removed request for phillip-wenig-frequenz October 25, 2024 16:15
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

LGTM. I think it makes sense in general, and will be useful when the microgrid API start streaming set power results (instead of using just one reply), but I wonder if you have any other use case where this is needed now.

Not approving because the CI is failing (and needs release notes), so I will probably need to approve again anyways.

@llucax llucax added this to the v0.7.0 milestone Oct 28, 2024
@llucax llucax added the type:enhancement New feature or enhancement visitble to users label Oct 28, 2024
shsms added 5 commits October 28, 2024 13:26
When the stream is exhausted and the server closes the stream, we no
longer automatically reconnect.  But this can be changed by setting
the `retry_on_exhausted_stream` parameter to `True`.

Signed-off-by: Sahas Subramanian <[email protected]>
Based on how it is configured, the `GrpcStreamBroadcaster` can stop
running when the retry limit has been reached or when the server
closes the connection.

The `is_running` method can be used to find out if that has happened.

Signed-off-by: Sahas Subramanian <[email protected]>
This is because the default success case should never retry at all
from now on.

Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests labels Oct 28, 2024
@shsms
Copy link
Contributor Author

shsms commented Oct 28, 2024

but I wonder if you have any other use case where this is needed now.

The electricity trading API makes time limited streaming requests and at the end, the streamers need to exit, but they keep trying to reconnect and spam the logs.

I've updated the tests and added release notes.

@shsms shsms requested a review from llucax October 28, 2024 15:45
@shsms shsms enabled auto-merge October 28, 2024 15:48
@llucax llucax disabled auto-merge October 29, 2024 09:22
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

Only one thing about the tests that really got me thinking for a while, so it might be worth changing. I will approve because I don't consider this a blocker, but I disabled auto-merge in case you want to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was really confused by the parametrization with only one value. Given that the tests with retry_on_exhausted_stream with True and False are almost identical1, wouldn't it make more sense to just take the argument in the test too and check differently for each value?

Footnotes

  1. Diff:

    @@ -15,7 +15,10 @@
             receiver_ready_event.set()
             async for item in receiver:
                 items.append(item)
    -    no_retry.next_interval.assert_called_once_with()
    +    assert (
    +        no_retry.next_interval.call_count == 0
    +    ), "next_interval should not be called when streaming is successful"
    +
         assert items == [
             "transformed_0",
             "transformed_1",
    @@ -26,8 +29,7 @@
         assert caplog.record_tuples == [
             (
                 "frequenz.client.base.streaming",
    -            logging.ERROR,
    -            "test_helper: connection ended, retry limit exceeded (mock progress), "
    -            "giving up. Stream exhausted.",
    +            logging.INFO,
    +            "test_helper: connection closed, stream exhausted",
             )
         ]
    

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 can only think of parameterising the cases as a way to make it look nice, but given that there are only two options, I'm not sure it is worth it.

@shsms shsms added this pull request to the merge queue Oct 29, 2024
Merged via the queue into frequenz-floss:v0.x.x with commit 92028a8 Oct 29, 2024
14 checks passed
@shsms shsms deleted the end-streaming branch October 29, 2024 09:41
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 type:enhancement New feature or enhancement visitble to users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants