-
Notifications
You must be signed in to change notification settings - Fork 931
grpc: allow the user to cancel stream v2 #3823
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
Closed
aidandj
wants to merge
13
commits into
open-telemetry:main
from
aidandj:aidan/allow-the-user-to-cancel-stream-v2
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
62c24e7
Test solution with add done callback
UOndro a2cf54a
Wrap strean response in proxy that manage span lifetime
UOndro 641beb7
Fix failing test, lint, and update changelog
UOndro 58683c1
Revert "Fix failing test, lint, and update changelog"
UOndro ce09c31
Revert "Wrap strean response in proxy that manage span lifetime"
UOndro 9e59ba6
Test calling code first
UOndro 9bdf76a
Fix tests
aidandj 979f0c6
Fix formatting
aidandj fa040d1
Merge branch 'main' into aidan/allow-the-user-to-cancel-stream-v2
aidandj 4225154
Merge branch 'main' into aidan/allow-the-user-to-cancel-stream-v2
aidandj aabae95
Merge branch 'main' into aidan/allow-the-user-to-cancel-stream-v2
aidandj 8e23a2c
Merge branch 'main' into aidan/allow-the-user-to-cancel-stream-v2
aidandj da21d03
Merge branch 'main' into aidan/allow-the-user-to-cancel-stream-v2
aidandj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||
| # limitations under the License. | ||||||
| # pylint:disable=cyclic-import | ||||||
|
|
||||||
| import threading | ||||||
| from unittest import mock | ||||||
|
|
||||||
| import grpc | ||||||
|
|
@@ -171,6 +172,38 @@ def test_unary_stream(self): | |||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| def test_unary_stream_can_be_cancel(self): | ||||||
| done = threading.Event() | ||||||
| responses = server_streaming_method(self._stub, serialize=False) | ||||||
| responses.add_done_callback(lambda _: done.set()) | ||||||
| for resp, _ in enumerate(responses): | ||||||
| if resp == 1: | ||||||
| responses.cancel() | ||||||
| break | ||||||
| self.assertEqual(responses.code(), grpc.StatusCode.CANCELLED) | ||||||
| done.wait(5) | ||||||
| spans = self.memory_exporter.get_finished_spans() | ||||||
| self.assertEqual(len(spans), 1) | ||||||
| span = spans[0] | ||||||
|
|
||||||
| self.assertEqual(span.name, "/GRPCTestServer/ServerStreamingMethod") | ||||||
| self.assertIs(span.kind, trace.SpanKind.CLIENT) | ||||||
|
|
||||||
| # Check version and name in span's instrumentation info | ||||||
| self.assertEqualSpanInstrumentationScope( | ||||||
| span, opentelemetry.instrumentation.grpc | ||||||
| ) | ||||||
|
|
||||||
| self.assertSpanHasAttributes( | ||||||
| span, | ||||||
| { | ||||||
| RPC_METHOD: "ServerStreamingMethod", | ||||||
| RPC_SERVICE: "GRPCTestServer", | ||||||
| RPC_SYSTEM: "grpc", | ||||||
| RPC_GRPC_STATUS_CODE: grpc.StatusCode.CANCELLED.value[0], | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| def test_stream_unary(self): | ||||||
| client_streaming_method(self._stub) | ||||||
| spans = self.memory_exporter.get_finished_spans() | ||||||
|
|
@@ -221,6 +254,40 @@ def test_stream_stream(self): | |||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| def test_stream_stream_can_be_cancel(self): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||
| done = threading.Event() | ||||||
| responses = bidirectional_streaming_method(self._stub, serialize=False) | ||||||
| responses.add_done_callback(lambda _: done.set()) | ||||||
| for resp, _ in enumerate(responses): | ||||||
| if resp == 1: | ||||||
| responses.cancel() | ||||||
| break | ||||||
| self.assertEqual(responses.code(), grpc.StatusCode.CANCELLED) | ||||||
| done.wait(5) | ||||||
| spans = self.memory_exporter.get_finished_spans() | ||||||
| self.assertEqual(len(spans), 1) | ||||||
| span = spans[0] | ||||||
|
|
||||||
| self.assertEqual( | ||||||
| span.name, "/GRPCTestServer/BidirectionalStreamingMethod" | ||||||
| ) | ||||||
| self.assertIs(span.kind, trace.SpanKind.CLIENT) | ||||||
|
|
||||||
| # Check version and name in span's instrumentation info | ||||||
| self.assertEqualSpanInstrumentationScope( | ||||||
| span, opentelemetry.instrumentation.grpc | ||||||
| ) | ||||||
|
|
||||||
| self.assertSpanHasAttributes( | ||||||
| span, | ||||||
| { | ||||||
| RPC_METHOD: "BidirectionalStreamingMethod", | ||||||
| RPC_SERVICE: "GRPCTestServer", | ||||||
| RPC_SYSTEM: "grpc", | ||||||
| RPC_GRPC_STATUS_CODE: grpc.StatusCode.CANCELLED.value[0], | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| def test_error_simple(self): | ||||||
| with self.assertRaises(grpc.RpcError): | ||||||
| simple_method(self._stub, error=True) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think span status as OK makes sense since the choices are unset, ok, or error. Would be good to get others' thoughts on this. The important part is this follows semconv for rpc status code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that canceling a span from the server side should be considered an error, although it may make sense to look at what another language does.