-
Notifications
You must be signed in to change notification settings - Fork 5.5k
router: scoped rds (2c): implement scoped rds API #6932
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
htuch
merged 42 commits into
envoyproxy:master
from
AndresGuedez:scoped-rds-config-provider
May 22, 2019
Merged
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
cdae885
Support scoped routing configuration.
AndresGuedez db48450
Derive test class from TestBase.
AndresGuedez 756afcd
fix_format fixes.
AndresGuedez 8e624ea
Merge remote-tracking branch 'upstream/master' into scoped-rds-inline…
AndresGuedez 98149e5
Minor cleanup.
AndresGuedez 76b7196
Fix srds.proto docs.
AndresGuedez f924eb7
Pendatic spelling and docs cleanup.
AndresGuedez 51d8dff
fix_format.
AndresGuedez ccca775
More detailed documentation/examples for SRDS.
AndresGuedez e5d87db
fix_format.
AndresGuedez 9c3d45b
Update pedantic spelling dictionary.
AndresGuedez afcc2a5
Clarify Scope.Key documentation.
AndresGuedez c774f00
Use EXPECT_NO_THROW() to validate successful allocation/construction.
AndresGuedez 8cc1b13
fix_format.
AndresGuedez 71f2a74
Modify SRDS to support delta updates and ease transition to incremental.
AndresGuedez 5aed783
Support delta SRDS proto in integration test.
AndresGuedez 15b1c7c
Cleanup.
AndresGuedez b216034
Add comments.
AndresGuedez c8f531b
Merge remote-tracking branch 'upstream/master' into scoped-rds-inline…
AndresGuedez 39309ac
Fix build failures after master merge.
AndresGuedez 8fe33ad
Cleanup and comments.
AndresGuedez 8c38526
Fix format.
AndresGuedez dd2261c
Comments.
AndresGuedez a7a621b
Merge remote-tracking branch 'upstream/master' into scoped-rds-inline…
AndresGuedez 090bbd8
Cleanup and minor refactor of ConfigProvider framework.
AndresGuedez 8b8a5e7
clang-tidy cleanup.
AndresGuedez 43c95e8
More clang-tidy cleanup.
AndresGuedez 6adaa22
Fix build break.
AndresGuedez 3a4d4e6
Merge remote-tracking branch 'origin/scoped-rds-inline-dynamic' into …
AndresGuedez 2a4ee03
Merge remote-tracking branch 'upstream/master' into scoped-rds-config…
AndresGuedez d401e7c
Fix GCC compiler warning related to hidden overloads.
AndresGuedez 52d32b5
Improve test coverage.
AndresGuedez c611a46
Improve test coverage.
AndresGuedez e507e55
Cleanup.
AndresGuedez 22645d1
Cleanup.
AndresGuedez f842132
Use a namespace instead of a class with a static function.
AndresGuedez 68ed29b
Fix clang-tidy issues.
AndresGuedez a5c87fc
Cleanup.
AndresGuedez 28f39a6
Remove dead code and other minor cleanup.
AndresGuedez a8f97f6
Remove unused code and other minor cleanup.
AndresGuedez bed4340
Cleanup.
AndresGuedez 6716559
Fix coverage test.
AndresGuedez 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "envoy/config/config_provider.h" | ||
| #include "envoy/router/router.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Router { | ||
|
|
||
| /** | ||
| * The scoped routing configuration. | ||
| */ | ||
| class ScopedConfig : public Envoy::Config::ConfigProvider::Config { | ||
| public: | ||
| ~ScopedConfig() override = default; | ||
|
|
||
| /** | ||
| * Based on the incoming HTTP request headers, returns the configuration to use for selecting a | ||
| * target route. | ||
| * @param headers the request headers to match the scoped routing configuration against. | ||
| * @return ConfigConstSharedPtr the router's Config matching the request headers. | ||
| */ | ||
| virtual ConfigConstSharedPtr getRouterConfig(const Http::HeaderMap& headers) const PURE; | ||
| }; | ||
|
|
||
| using ScopedConfigConstSharedPtr = std::shared_ptr<const ScopedConfig>; | ||
|
|
||
| } // namespace Router | ||
| } // 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
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,16 @@ | ||
| #include "common/router/scoped_config_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Router { | ||
|
|
||
| void ThreadLocalScopedConfigImpl::addOrUpdateRoutingScope(const ScopedRouteInfoConstSharedPtr&) {} | ||
|
|
||
| void ThreadLocalScopedConfigImpl::removeRoutingScope(const std::string&) {} | ||
|
|
||
| Router::ConfigConstSharedPtr | ||
| ThreadLocalScopedConfigImpl::getRouterConfig(const Http::HeaderMap&) const { | ||
| return std::make_shared<const NullConfigImpl>(); | ||
| } | ||
|
|
||
| } // namespace Router | ||
| } // 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,55 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/api/v2/srds.pb.h" | ||
| #include "envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.pb.h" | ||
| #include "envoy/router/router.h" | ||
| #include "envoy/router/scopes.h" | ||
| #include "envoy/thread_local/thread_local.h" | ||
|
|
||
| #include "common/router/config_impl.h" | ||
| #include "common/router/scoped_config_manager.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Router { | ||
|
|
||
| /** | ||
| * TODO(AndresGuedez): implement scoped routing logic. | ||
| * | ||
| * Each Envoy worker is assigned an instance of this type. When config updates are received, | ||
| * addOrUpdateRoutingScope() and removeRoutingScope() are called to update the set of scoped routes. | ||
| * | ||
| * ConnectionManagerImpl::refreshCachedRoute() will call getRouterConfig() to obtain the | ||
| * Router::ConfigConstSharedPtr to use for route selection. | ||
| */ | ||
| class ThreadLocalScopedConfigImpl : public ScopedConfig, public ThreadLocal::ThreadLocalObject { | ||
| public: | ||
| ThreadLocalScopedConfigImpl( | ||
| envoy::config::filter::network::http_connection_manager::v2::ScopedRoutes::ScopeKeyBuilder | ||
| scope_key_builder) | ||
| : scope_key_builder_(std::move(scope_key_builder)) {} | ||
|
|
||
| ~ThreadLocalScopedConfigImpl() override = default; | ||
|
htuch marked this conversation as resolved.
Outdated
|
||
|
|
||
| void addOrUpdateRoutingScope(const ScopedRouteInfoConstSharedPtr& scoped_route_info); | ||
| void removeRoutingScope(const std::string& scope_name); | ||
|
|
||
| // Envoy::Router::ScopedConfig | ||
| Router::ConfigConstSharedPtr getRouterConfig(const Http::HeaderMap& headers) const override; | ||
|
|
||
| private: | ||
| const envoy::config::filter::network::http_connection_manager::v2::ScopedRoutes::ScopeKeyBuilder | ||
| scope_key_builder_; | ||
| }; | ||
|
|
||
| /** | ||
| * A NULL implementation of the scoped routing configuration. | ||
| */ | ||
| class NullScopedConfigImpl : public ScopedConfig { | ||
| public: | ||
| Router::ConfigConstSharedPtr getRouterConfig(const Http::HeaderMap&) const override { | ||
| return std::make_shared<const NullConfigImpl>(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace Router | ||
| } // 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,22 @@ | ||
| #include "common/router/scoped_config_manager.h" | ||
|
|
||
| #include "envoy/common/exception.h" | ||
|
|
||
| #include "common/common/fmt.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Router { | ||
|
|
||
| ScopedRouteInfoConstSharedPtr ScopedConfigManager::addOrUpdateRoutingScope( | ||
| const envoy::api::v2::ScopedRouteConfiguration& config_proto, const std::string&) { | ||
| auto scoped_route_info = std::make_shared<const ScopedRouteInfo>(config_proto); | ||
| scoped_route_map_[config_proto.name()] = scoped_route_info; | ||
| return scoped_route_info; | ||
| } | ||
|
|
||
| bool ScopedConfigManager::removeRoutingScope(const std::string& name) { | ||
| return scoped_route_map_.erase(name) == 0; | ||
| } | ||
|
|
||
| } // namespace Router | ||
| } // 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,49 @@ | ||
| #pragma once | ||
|
|
||
| #include <map> | ||
| #include <string> | ||
|
|
||
| #include "envoy/api/v2/srds.pb.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Router { | ||
|
|
||
| // The internal representation of the configuration distributed via the ScopedRouteConfiguration | ||
| // proto. | ||
| class ScopedRouteInfo { | ||
| public: | ||
| ScopedRouteInfo(const envoy::api::v2::ScopedRouteConfiguration& config_proto) | ||
| : config_proto_(config_proto) {} | ||
|
|
||
| // TODO(AndresGuedez): Add the necessary APIs required for the scoped routing logic. | ||
|
|
||
| const envoy::api::v2::ScopedRouteConfiguration config_proto_; | ||
| }; | ||
| using ScopedRouteInfoConstSharedPtr = std::shared_ptr<const ScopedRouteInfo>; | ||
|
|
||
| // A manager for routing configuration scopes. | ||
| // An instance of the manager is owned by each ScopedRdsConfigSubscription. When config updates are | ||
| // received (on the main thread), the manager is called to track changes to the set of scoped route | ||
| // configurations and build <ScopedRouteInfo>s as needed. | ||
| class ScopedConfigManager { | ||
| public: | ||
| // Ordered map for consistent config dumping. | ||
| using ScopedRouteMap = std::map<std::string, ScopedRouteInfoConstSharedPtr>; | ||
|
|
||
| // Adds/updates a routing scope specified via the Scoped RDS API. This scope will be added to the | ||
| // set of scopes matched against the scope keys built for each HTTP request. | ||
| ScopedRouteInfoConstSharedPtr | ||
| addOrUpdateRoutingScope(const envoy::api::v2::ScopedRouteConfiguration& scoped_route_config, | ||
| const std::string& version_info); | ||
|
|
||
| // Removes a routing scope from the set of scopes matched against each HTTP request. | ||
| bool removeRoutingScope(const std::string& scope_name); | ||
|
|
||
| const ScopedRouteMap& scopedRouteMap() const { return scoped_route_map_; } | ||
|
|
||
| private: | ||
| ScopedRouteMap scoped_route_map_; | ||
| }; | ||
|
|
||
| } // namespace Router | ||
| } // 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.
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.
I think it's important to distinguish between three concepts; "route config", "router config" and "HTTP connection manager route configuration". I think you mean the first or last year, rather than the middle?
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.
This returns an
Envoy::Router::Config, hence the name. However, I agree it is fairly confusing since the documentation refers to it by yet another name (route table).I am fine switching to
getRouteTableor evengetRouteConfigurationif you think either of those more directly convey the meaning.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.
getRouteConfigurationor even the shortergetRouteConfigwould be clearer to me.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.
Done.