-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: allow configuration of connection pool limits #6298
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
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9603d2d
add max_connection_pools to circut breakers.
klarose 0414028
Implement per ResourcePriority conn pool limits.
klarose bc6b6cb
Add tests for conn pool resource max
klarose ce8561f
Allow connection pool get to fail, and add integration test
klarose ebfbd13
Rename priority_conn_pool_map
klarose 189cab1
various fixes
klarose 5b77fe8
various code review fixes
klarose aabd569
add docs and release notes for circuit breaker
klarose f83dc2e
Merge branch 'master' into add_limit_config
klarose f8fcf3f
remove extraneous whitespace
klarose 0986d93
fix typo
klarose e1758b2
Merge branch 'master' into add_limit_config
klarose 3c0327b
various code review fixes
klarose 3a7dce7
fix deferred delete issue
klarose 0e9624b
Merge branch 'master' into add_limit_config
klarose 2fbf429
Revert "fix deferred delete issue"
klarose f105196
more code review fixes
klarose 76ab094
Merge branch 'master' into add_limit_config
klarose 1e7dd22
Merge branch 'master' into add_limit_config
klarose b3b17b7
fix a camel-case nit
klarose 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/event/dispatcher.h" | ||
| #include "envoy/upstream/resource_manager.h" | ||
| #include "envoy/upstream/upstream.h" | ||
|
|
||
| #include "common/upstream/conn_pool_map.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Upstream { | ||
| /** | ||
| * A class mapping keys to connection pools, with some recycling logic built in. | ||
| */ | ||
| template <typename KEY_TYPE, typename POOL_TYPE> class PriorityConnPoolMap { | ||
| public: | ||
| using ConnPoolMapType = ConnPoolMap<KEY_TYPE, POOL_TYPE>; | ||
| using PoolFactory = typename ConnPoolMapType::PoolFactory; | ||
| using DrainedCb = typename ConnPoolMapType::DrainedCb; | ||
| using OptPoolRef = typename ConnPoolMapType::OptPoolRef; | ||
|
|
||
| PriorityConnPoolMap(Event::Dispatcher& dispatcher, const HostConstSharedPtr host); | ||
| ~PriorityConnPoolMap(); | ||
| /** | ||
| * Returns an existing pool for the given priority and `key`, or creates a new one using | ||
| * `factory`. Note that it is possible for this to fail if a limit on the number of pools allowed | ||
| * is reached. | ||
| * @return The pool corresponding to `key`, or `absl::nullopt`. | ||
| */ | ||
| OptPoolRef getPool(ResourcePriority priority, KEY_TYPE key, const PoolFactory& factory); | ||
|
|
||
| /** | ||
| * @return the number of pools across all priorities. | ||
| */ | ||
| size_t size() const; | ||
|
|
||
| /** | ||
| * Destroys all mapped pools. | ||
| */ | ||
| void clear(); | ||
|
|
||
| /** | ||
| * Adds a drain callback to all mapped pools. Any future mapped pools with have the callback | ||
| * automatically added. Be careful with the callback. If it itself calls into `this`, modifying | ||
| * the state of `this`, there is a good chance it will cause corruption due to the callback firing | ||
| * immediately. | ||
| */ | ||
| void addDrainedCallback(const DrainedCb& cb); | ||
|
|
||
| /** | ||
| * Instructs each connection pool to drain its connections. | ||
| */ | ||
| void drainConnections(); | ||
|
|
||
| private: | ||
| std::array<std::unique_ptr<ConnPoolMapType>, NumResourcePriorities> conn_pool_maps_; | ||
| }; | ||
|
|
||
| } // namespace Upstream | ||
| } // namespace Envoy |
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #pragma once | ||
|
|
||
| #include "common/upstream/conn_pool_map_impl.h" | ||
| #include "common/upstream/priority_conn_pool_map.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Upstream { | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::PriorityConnPoolMap(Envoy::Event::Dispatcher& dispatcher, | ||
| const HostConstSharedPtr host) { | ||
|
klarose marked this conversation as resolved.
Outdated
|
||
| for (size_t pool_map_index = 0; pool_map_index < NumResourcePriorities; ++pool_map_index) { | ||
| ResourcePriority priority = static_cast<ResourcePriority>(pool_map_index); | ||
| conn_pool_maps_[pool_map_index].reset(new ConnPoolMapType(dispatcher, host, priority)); | ||
| } | ||
| } | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::~PriorityConnPoolMap() = default; | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| typename PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::OptPoolRef | ||
| PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::getPool(ResourcePriority priority, KEY_TYPE key, | ||
| const PoolFactory& factory) { | ||
| size_t index = static_cast<size_t>(priority); | ||
| ASSERT(index < conn_pool_maps_.size()); | ||
| return conn_pool_maps_[index]->getPool(key, factory); | ||
| } | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| size_t PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::size() const { | ||
| size_t size = 0; | ||
| for (const auto& pool_map : conn_pool_maps_) { | ||
| size += pool_map->size(); | ||
| } | ||
| return size; | ||
| } | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::clear() { | ||
| for (auto& pool_map : conn_pool_maps_) { | ||
| pool_map->clear(); | ||
| } | ||
| } | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::addDrainedCallback(const DrainedCb& cb) { | ||
| for (auto& pool_map : conn_pool_maps_) { | ||
| pool_map->addDrainedCallback(cb); | ||
| } | ||
| } | ||
|
|
||
| template <typename KEY_TYPE, typename POOL_TYPE> | ||
| void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::drainConnections() { | ||
| for (auto& pool_map : conn_pool_maps_) { | ||
| pool_map->drainConnections(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Upstream | ||
| } // namespace Envoy | ||
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.
Uh oh!
There was an error while loading. Please reload this page.