-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: change pool APIs #16544
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
Merged
Merged
upstream: change pool APIs #16544
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43ff01d
WIP: change pool APIs
alyssawilk b43cd2f
reworking APIs
alyssawilk d6b946e
Merge branch 'main' into newStream
alyssawilk f8a6f11
Merge branch 'main' into newStream
alyssawilk 34fe84e
Merge branch 'main' into newStream
alyssawilk dd8542e
comments, coverage, clang
alyssawilk 17ae142
format
alyssawilk 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,52 @@ | |
| namespace Envoy { | ||
| namespace Upstream { | ||
|
|
||
| // HttpPoolData returns information about a given pool as well as a function | ||
| // to create streams on that pool. | ||
| struct HttpPoolData { | ||
|
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: I think tis is probably a class now that it has methods and private members. |
||
| using OnNewStreamFn = std::function<void()>; | ||
|
|
||
| HttpPoolData(OnNewStreamFn on_new_stream, Http::ConnectionPool::Instance* pool) | ||
| : on_new_stream_(on_new_stream), pool_(pool) {} | ||
|
|
||
| Envoy::Http::ConnectionPool::Cancellable* | ||
| newStream(Http::ResponseDecoder& response_decoder, | ||
| Envoy::Http::ConnectionPool::Callbacks& callbacks) { | ||
| on_new_stream_(); | ||
| return pool_->newStream(response_decoder, callbacks); | ||
| } | ||
|
|
||
| Upstream::HostDescriptionConstSharedPtr host() const { return pool_->host(); } | ||
|
|
||
| private: | ||
| friend class HttpPoolDataPeer; | ||
|
|
||
| OnNewStreamFn on_new_stream_; | ||
| Http::ConnectionPool::Instance* pool_; | ||
|
ggreenway marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| // Tcp pool returns information about a given pool, as well as a function to | ||
| // create connections on that pool. | ||
| struct TcpPoolData { | ||
|
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. Ditto |
||
| using OnNewConnectionFn = std::function<void()>; | ||
|
|
||
| TcpPoolData(OnNewConnectionFn on_new_connection, Tcp::ConnectionPool::Instance* pool) | ||
| : on_new_connection_(on_new_connection), pool_(pool) {} | ||
|
|
||
| Envoy::Tcp::ConnectionPool::Cancellable* | ||
| newConnection(Envoy::Tcp::ConnectionPool::Callbacks& callbacks) { | ||
| on_new_connection_(); | ||
| return pool_->newConnection(callbacks); | ||
| } | ||
|
|
||
| Upstream::HostDescriptionConstSharedPtr host() const { return pool_->host(); } | ||
|
|
||
| private: | ||
| friend class TcpPoolDataPeer; | ||
| OnNewConnectionFn on_new_connection_; | ||
| Tcp::ConnectionPool::Instance* pool_; | ||
| }; | ||
|
|
||
| /** | ||
| * A thread local cluster instance that can be used for direct load balancing and host set | ||
| * interactions. In general, an instance of ThreadLocalCluster can only be safely used in the | ||
|
|
@@ -42,10 +88,11 @@ class ThreadLocalCluster { | |
| * @param priority the connection pool priority. | ||
| * @param downstream_protocol the downstream protocol (if one exists) to use in protocol | ||
| * selection. | ||
| * @param context the optional load balancer context. | ||
| * @return the connection pool or nullptr if there is no host available in the cluster. | ||
| * @param context the optional load balancer context. Must continue to be | ||
| * valid until newConnection is called on the pool (if it is to be called). | ||
| * @return the connection pool data or nullopt if there is no host available in the cluster. | ||
| */ | ||
| virtual Http::ConnectionPool::Instance* | ||
| virtual absl::optional<HttpPoolData> | ||
| httpConnPool(ResourcePriority priority, absl::optional<Http::Protocol> downstream_protocol, | ||
| LoadBalancerContext* context) PURE; | ||
|
|
||
|
|
@@ -55,11 +102,12 @@ class ThreadLocalCluster { | |
| * is used is the one defined on the cluster when it was created. | ||
| * | ||
| * @param priority the connection pool priority. | ||
| * @param context the optional load balancer context. | ||
| * @return the connection pool or nullptr if there is no host available in the cluster. | ||
| * @param context the optional load balancer context. Must continue to be | ||
| * valid until newConnection is called on the pool (if it is to be called). | ||
| * @return the connection pool data or nullopt if there is no host available in the cluster. | ||
| */ | ||
| virtual Tcp::ConnectionPool::Instance* tcpConnPool(ResourcePriority priority, | ||
| LoadBalancerContext* context) PURE; | ||
| virtual absl::optional<TcpPoolData> tcpConnPool(ResourcePriority priority, | ||
| LoadBalancerContext* context) PURE; | ||
|
|
||
| /** | ||
| * Allocate a load balanced TCP connection for a cluster. The created connection is already | ||
|
|
||
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
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
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.
nit: It seems like this isn't so much "pool data" as it is "stream data" in that it contains a host and a function for creating a stream, but does not provide any direct access to a poo per se. Perhaps HttpStreamData?
I think this extends down to httpConnPool() which no longer returns a pool but instead returns stream data, if I'm reading this right.