Skip to content

Commit

Permalink
Update grpc
Browse files Browse the repository at this point in the history
Fixes #1030
  • Loading branch information
ocelotl committed Aug 21, 2020
1 parent 281a0e6 commit 6e0dc08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages=find_namespace:
install_requires =
opentelemetry-api == 0.13dev0
opentelemetry-sdk == 0.13dev0
grpcio == 1.30
grpcio >= 1.0.0, < 2.0.0

[options.extras_require]
test =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ def test_stream_stream(self):
40, 40, "/GRPCTestServer/BidirectionalStreamingMethod"
)

def _verify_error_records(self, method):
def _verify_error_records(
self, method, status_code=grpc.StatusCode.UNAVAILABLE
):
# Updating grpc to 1.31.0 makes the status codes for two test cases
# change, this is why the status code is passed as an argument now.
# pylint: disable=protected-access,no-member
self.channel._interceptor.controller.tick()
records = self.memory_metrics_exporter.get_exported_metrics()
Expand All @@ -193,11 +197,7 @@ def _verify_error_records(self, method):

self.assertEqual(errors.instrument.name, "grpcio/client/errors")
self.assertEqual(
errors.labels,
(
("method", method),
("status_code", grpc.StatusCode.INVALID_ARGUMENT),
),
errors.labels, (("method", method), ("status_code", status_code),),
)
self.assertEqual(errors.aggregator.checkpoint, 1)

Expand All @@ -206,15 +206,17 @@ def _verify_error_records(self, method):
(
("error", True),
("method", method),
("status_code", grpc.StatusCode.INVALID_ARGUMENT),
("status_code", status_code),
),
)

def test_error_simple(self):
with self.assertRaises(grpc.RpcError):
simple_method(self._stub, error=True)

self._verify_error_records("/GRPCTestServer/SimpleMethod")
self._verify_error_records(
"/GRPCTestServer/SimpleMethod", grpc.StatusCode.INVALID_ARGUMENT
)

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
Expand All @@ -228,7 +230,10 @@ def test_error_stream_unary(self):
with self.assertRaises(grpc.RpcError):
client_streaming_method(self._stub, error=True)

self._verify_error_records("/GRPCTestServer/ClientStreamingMethod")
self._verify_error_records(
"/GRPCTestServer/ClientStreamingMethod",
grpc.StatusCode.INVALID_ARGUMENT,
)
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
span = spans[0]
Expand All @@ -241,7 +246,10 @@ def test_error_unary_stream(self):
with self.assertRaises(grpc.RpcError):
server_streaming_method(self._stub, error=True)

self._verify_error_records("/GRPCTestServer/ServerStreamingMethod")
self._verify_error_records(
"/GRPCTestServer/ServerStreamingMethod",
grpc.StatusCode.INVALID_ARGUMENT,
)

spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 1)
Expand All @@ -264,7 +272,7 @@ def test_error_stream_stream(self):
span = spans[0]
self.assertEqual(
span.status.canonical_code.value,
grpc.StatusCode.INVALID_ARGUMENT.value[0],
grpc.StatusCode.UNAVAILABLE.value[0],
)


Expand Down

0 comments on commit 6e0dc08

Please sign in to comment.