Skip to content

Conversation

@parthea
Copy link
Contributor

@parthea parthea commented Dec 17, 2024

This PR adds showcase integration tests for reading response metadata using the following matrix: [(gRPC, REST), (sync , async)]
This PR depends on #2370.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Dec 17, 2024
@parthea parthea force-pushed the add-showcase-test-rest-interceptors-metadata branch from 4d0f596 to a48fc54 Compare December 17, 2024 17:07
@parthea parthea marked this pull request as ready for review December 17, 2024 17:07
@parthea parthea requested a review from a team as a code owner December 17, 2024 17:07
self.request_metadata = []
self.response_metadata = []

async def _add_metadata(self, client_call_details):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
async def _add_metadata(self, client_call_details):
async def _add_request_metadata(self, client_call_details):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in e302dc7

response_it = continuation(client_call_details, request)
return response_it

async def intercept_stream_unary(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use more descriptive names to differentiate this method from the previous one. I realize previously existing classes established this pattern, but we should clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not something that we can change as it's an abstract method in gRPC that we're overriding

https://grpc.github.io/grpc/python/grpc.html#grpc.StreamUnaryClientInterceptor.intercept_stream_unary

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack. Too bad.

return response_it


class MetadataClienRestInterceptor(EchoRestInterceptor):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would clarify in the name that this is for the echo service

Suggested change
class MetadataClienRestInterceptor(EchoRestInterceptor):
class EchoMetadataClienRestInterceptor(EchoRestInterceptor):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1ae8aaa



@pytest.fixture
def intercepted_echo_grpc_async():
Copy link
Contributor

Choose a reason for hiding this comment

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

Put the two grpc fixtures next to each other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7147a58



@pytest.fixture
def intercepted_echo_rest():
Copy link
Contributor

Choose a reason for hiding this comment

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

We're waiting for REST async or can we test that now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 05f6c65



def test_unary_stream(intercepted_echo):
def test_unary_stream(intercepted_echo_grpc):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to test async grpc here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 05f6c65



@pytest.mark.parametrize(
"transport,response_metadata",
Copy link
Contributor

Choose a reason for hiding this comment

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

How do the interceptors used int his file know about the response metadata they should be injecting? Or is this real response metadata from Showcase? I'm not finding it by doing a search n the Showcase repo.

Copy link
Contributor Author

@parthea parthea Mar 24, 2025

Choose a reason for hiding this comment

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

The interceptors aren't injecting anything here. There is a feature of the echo rpc which adds response headers(metadata) with the X-Showcase-Request prefix automatically for REST , using information from the request. This was added in googleapis/gapic-showcase#1509. For gRPC, I believe this feature was added in googleapis/gapic-showcase#970

Base automatically changed from add-rest-response-metadata to main December 18, 2024 18:57
@parthea parthea assigned parthea and unassigned vchudnov-g Dec 18, 2024
@parthea parthea marked this pull request as draft January 29, 2025 11:51
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Mar 22, 2025
@parthea parthea added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 23, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 23, 2025
@parthea parthea marked this pull request as ready for review March 24, 2025 14:24
@parthea parthea assigned vchudnov-g and unassigned parthea Mar 25, 2025
Copy link
Contributor

@vchudnov-g vchudnov-g left a comment

Choose a reason for hiding this comment

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

One q.

response_it = continuation(client_call_details, request)
return response_it

async def intercept_stream_unary(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ack. Too bad.

@pytest.fixture
def intercepted_echo_grpc_async():
# The interceptor adds 'showcase-trailer' client metadata. Showcase server
# echos any metadata with key 'showcase-trailer', so the same metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: sp. Above as well

Suggested change
# echos any metadata with key 'showcase-trailer', so the same metadata
# echoes any metadata with key 'showcase-trailer', so the same metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6495273

@parthea parthea enabled auto-merge (squash) March 28, 2025 20:26
@parthea parthea merged commit 7542410 into main Mar 28, 2025
121 checks passed
@parthea parthea deleted the add-showcase-test-rest-interceptors-metadata branch March 28, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants