Skip to content
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

Make GrpcStreamBroadcaster compatible with both grpcio and grpclib #49

Merged
merged 5 commits into from
May 8, 2024

Conversation

llucax
Copy link
Contributor

@llucax llucax commented May 7, 2024

With this change GrpcStreamBroadcaster can be used with both grpcio and grpclib implementations of gRPC.

This is achieved by using AsyncIterator instead of grpc.aio.UnaryStreamCall in the stream_method parameter of GrpcStreamBroadcaster to make it more generic, and catching exceptions from both grpcio and grpclib in the async for loop.

To deal with any of the libraries being installed, a new module is added to handles exceptions from both libraries, by conditionally importing the exception and provide a dummy one if the library is not installed.

Now both grpcio and grpclib are optional, and can be installed using frequenz-client-base[grpcio] or frequenz-client-base[grpclib] respectively.

We also add some tests for GrpcStreamBroadcaster.

@llucax llucax requested a review from a team as a code owner May 7, 2024 12:29
@llucax llucax requested a review from shsms May 7, 2024 12:29
@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:code Affects the code in general part:docs Affects the documentation labels May 7, 2024
@llucax

This comment was marked as outdated.

@llucax llucax self-assigned this May 7, 2024
@llucax llucax added this to the v0.3.0 milestone May 7, 2024
@llucax
Copy link
Contributor Author

llucax commented May 8, 2024

Updated. Will fix up before merging.

Copy link

@daniel-zullo-frequenz daniel-zullo-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, it only needs fixing up as stated...

@llucax
Copy link
Contributor Author

llucax commented May 8, 2024

Updated.

@llucax
Copy link
Contributor Author

llucax commented May 8, 2024

Enabled auto-merge.

@llucax llucax enabled auto-merge May 8, 2024 09:55
@llucax llucax added this pull request to the merge queue May 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 8, 2024
@llucax
Copy link
Contributor Author

llucax commented May 8, 2024

The good news is the merge queue checks now works correctly, the bad news is I forgot 2 fixes need to be applied to fix the CI, so this PR depends now on this PR to be merged:

@llucax llucax dismissed daniel-zullo-frequenz’s stale review May 8, 2024 11:47

The merge-base changed after approval.

llucax added 2 commits May 8, 2024 13:48
This is a preparation commit to make the client base library compatible
with both `grpcio` and `grpclib`.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This module will provide a way to deal with multiple grpc libraries. For
now it only handles exceptions from both libraries, but it can be
extended to handle other differences in the future.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
llucax added 3 commits May 8, 2024 13:48
With this change `GrpcStreamBroadcaster` can be used with both `grpcio`
and `grpclib` implementations of gRPC. This is achieved by using
`collections.abc.AsyncIterator` instead of `grpc.aio.UnaryStreamCall` in
the `stream_method` parameter of `GrpcStreamBroadcaster` to make it more
generic, and catching exceptions from both `grpcio` and `grpclib` in the
`async for` loop.

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>
@llucax
Copy link
Contributor Author

llucax commented May 8, 2024

Rebased, it needs a new approval.

@llucax llucax enabled auto-merge May 8, 2024 11:48
@llucax llucax modified the milestones: v0.3.0, v0.4.0 May 8, 2024
@llucax llucax added this pull request to the merge queue May 8, 2024
Merged via the queue into frequenz-floss:v0.x.x with commit 3148c60 May 8, 2024
14 checks passed
@llucax llucax deleted the grpclib branch May 8, 2024 11:58
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 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