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

grpc: Allow to set parent context to a client to propagate stream info #13356

Merged
merged 28 commits into from
Oct 9, 2020
Merged

grpc: Allow to set parent context to a client to propagate stream info #13356

merged 28 commits into from
Oct 9, 2020

Conversation

dio
Copy link
Member

@dio dio commented Oct 1, 2020

Commit Message: This patch allows to set parent context which carries the current request stream info to a gRPC async client instance.

Risk Level: Low
Testing: Added
Docs Changes: Updated
Release Notes: Added
Fixes #13345

dio added 2 commits October 1, 2020 12:23
This patch allows to set parent context to an async client instance.

Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
@dio
Copy link
Member Author

dio commented Oct 1, 2020

@htuch I'm not sure if this is the right way to solve #13345. If you have time could you please tell me your opinion on this? Thank you!

dio added 3 commits October 2, 2020 01:32
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

@dio makes sense to me!

source/common/grpc/async_client_impl.cc Outdated Show resolved Hide resolved
source/common/grpc/async_client_impl.cc Outdated Show resolved Hide resolved
source/common/grpc/async_client_impl.h Show resolved Hide resolved
dio added 2 commits October 3, 2020 02:27
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #13356 was synchronize by dio.

see: more, trace.

@dio dio changed the title WIP: async_client: Allow to set parent context to propagate stream info async_client: Allow to set parent context to propagate stream info Oct 3, 2020
Signed-off-by: Dhi Aurrahman <[email protected]>
@dio dio changed the title async_client: Allow to set parent context to propagate stream info grpc: Allow to set parent context to a client to propagate stream info Oct 3, 2020
dio added 6 commits October 3, 2020 18:18
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
@dio dio marked this pull request as ready for review October 4, 2020 06:28
@dio dio requested a review from zuercher as a code owner October 4, 2020 06:28
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Looks good, main question is on whether header parser can be simplified..
/wait

@@ -287,5 +294,26 @@ void HeaderParser::evaluateHeaders(Http::HeaderMap& headers,
}
}

void HeaderParser::evaluateHeaders(Http::HeaderMap& headers,
const StreamInfo::StreamInfo* stream_info) const {
Copy link
Member

Choose a reason for hiding this comment

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

Could we use a null StreamInfo rather than duplicate the add/remove logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, do you mean to have something like NullStreamInfoImpl?

Copy link
Member Author

@dio dio Oct 7, 2020

Choose a reason for hiding this comment

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

The only problem with that probably if we have an input that creates StreamInfoHeaderFormatter (or CompoundHeaderFormatter) we need to always act as PlainHeaderFormatter.

For example: given the following HeaderValue:

- name: key
  value: %DOWNSTREAM_LOCAL_ADDRESS%

This creates StreamInfoHeaderFormatter, if we have NullStreamInfoImpl we need to provide a default value for stream_info.downstreamLocalAddress(), which probably could be misleading?

Copy link
Member

Choose a reason for hiding this comment

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

OK, fair enough, but could we merge the control flow so that we have only one internal evaluateHeadersInt and this can branch at the leaves on what to do?

Copy link
Member Author

@dio dio Oct 8, 2020

Choose a reason for hiding this comment

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

Have done a bit of refactoring, hope it aligns with your expectation :).

@@ -94,6 +101,36 @@ TEST_F(EnvoyGoogleAsyncClientImplTest, StreamHttpStartFail) {
EXPECT_TRUE(grpc_stream == nullptr);
}

TEST_F(EnvoyGoogleAsyncClientImplTest, MetadataIsInitialized) {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@@ -57,6 +57,8 @@ void GrpcClientImpl::check(RequestCallbacks& callbacks, Event::Dispatcher& dispa
}
}

options.setParentContext(Http::AsyncClient::ParentContext{&stream_info});
Copy link
Member

Choose a reason for hiding this comment

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

It might be good one day to be able to have async clients automatically detect this information, maybe by introducing a StreamAsyncClient that can pick up on this context. In any case, I think what you have is fine for now.

Signed-off-by: Dhi Aurrahman <[email protected]>
dio added 11 commits October 7, 2020 01:21
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@repokitteh-read-only repokitteh-read-only bot removed the api label Oct 9, 2020
@htuch htuch merged commit e5aa696 into envoyproxy:master Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow interpreting variables in initial_metadata for a ext_authz grpc service
2 participants