-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[WIP] fix(api_core): configure default max_metadata_size in gRPC helpers #17663
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -304,6 +304,17 @@ def create_channel( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if attempt_direct_path: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target = grpc_helpers._modify_target_for_direct_path(target) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "options" in kwargs and isinstance(kwargs["options"], (list, tuple)): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opts = list(kwargs["options"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not any( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isinstance(opt, (list, tuple)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and len(opt) >= 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and opt[0] == "grpc.max_metadata_size" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for opt in opts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opts.append(("grpc.max_metadata_size", 32768)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kwargs["options"] = opts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+307
to
+316
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. The current implementation only configures
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return aio.secure_channel( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target, composite_credentials, compression=compression, **kwargs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -730,6 +730,15 @@ def test_create_channel(grpc_secure_channel): | |||||||||||||||||||||||||||||||
| credentials.with_scopes.assert_called_once_with(scopes, default_scopes=None) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @mock.patch("google.auth.default", return_value=(mock.sentinel.credentials, None)) | ||||||||||||||||||||||||||||||||
| @mock.patch("grpc.aio.secure_channel") | ||||||||||||||||||||||||||||||||
| def test_create_channel_max_metadata_size(grpc_secure_channel, auth_default): | ||||||||||||||||||||||||||||||||
| options = [("grpc.max_send_message_length", -1)] | ||||||||||||||||||||||||||||||||
| grpc_helpers_async.create_channel("example.com:443", options=options) | ||||||||||||||||||||||||||||||||
| _, kwargs = grpc_secure_channel.call_args | ||||||||||||||||||||||||||||||||
| assert ("grpc.max_metadata_size", 32768) in kwargs["options"] | ||||||||||||||||||||||||||||||||
|
Comment on lines
+735
to
+739
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. Update the test to verify that
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @pytest.mark.asyncio | ||||||||||||||||||||||||||||||||
| async def test_fake_stream_unary_call(): | ||||||||||||||||||||||||||||||||
| fake_call = grpc_helpers_async.FakeStreamUnaryCall() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -925,3 +925,12 @@ def test_subscribe_unsubscribe(self): | |||||||||||||||||||||||||||||||
| def test_close(self): | ||||||||||||||||||||||||||||||||
| channel = grpc_helpers.ChannelStub() | ||||||||||||||||||||||||||||||||
| assert channel.close() is None | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @mock.patch("google.auth.default", return_value=(mock.sentinel.credentials, None)) | ||||||||||||||||||||||||||||||||
| @mock.patch("grpc.secure_channel") | ||||||||||||||||||||||||||||||||
| def test_create_channel_max_metadata_size(grpc_secure_channel, auth_default): | ||||||||||||||||||||||||||||||||
| options = [("grpc.max_send_message_length", -1)] | ||||||||||||||||||||||||||||||||
| grpc_helpers.create_channel("example.com:443", options=options) | ||||||||||||||||||||||||||||||||
| _, kwargs = grpc_secure_channel.call_args | ||||||||||||||||||||||||||||||||
| assert ("grpc.max_metadata_size", 32768) in kwargs["options"] | ||||||||||||||||||||||||||||||||
|
Comment on lines
+932
to
+936
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. Update the test to verify that
Suggested change
|
||||||||||||||||||||||||||||||||
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.
The current implementation only configures
grpc.max_metadata_sizeifoptionsis already present inkwargs. This means that for the default case where no custom options are provided, the defaultmax_metadata_sizewill not be set. To ensure that the default limit is always configured, we should initializeoptionsas an empty list if it is not provided.