-
Notifications
You must be signed in to change notification settings - Fork 5.5k
rds: extracting base classes as reusable generic routing DS implementation. #18846
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 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
984af86
Extracting reusable base calsses for generic routing DS.
378d7a4
Fix review comments
f8c0f79
Move every logic to Rds::RouteConfigProviderManagerImpl
392ec17
Merge branch 'main' into generic_rds
62d0be9
Fix review comments
b1f49de
Kick CI
3231a66
Test for provider erase
2027ab0
Separate proto functions from ConfigTraits to ProtoTraits
778f7f3
Eliminating ProtoTraits::cloneProto
cb04402
Simplify ProtoTraits interface
8064f18
Eliminate cast from Router::RouteConfigUpdateReceiverImpl::onRdsUpdate
d51349a
Simplifying Router::RdsRouteConfigSubscription and Router::RdsRouteCo…
e5f04b9
Eliminating Rds::RouteConfigProviderManager interface
86d2d8d
Increase coverage
bdc739e
Fix review comments
3b5f797
Fix review comments
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "rds_interface", | ||
| hdrs = [ | ||
| "config.h", | ||
| "config_traits.h", | ||
| "route_config_provider.h", | ||
| "route_config_update_receiver.h", | ||
| ], | ||
| ) |
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,19 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| namespace Envoy { | ||
| namespace Rds { | ||
|
|
||
| /** | ||
| * Base class for router configuration classes used with Rds. | ||
| */ | ||
| class Config { | ||
| public: | ||
| virtual ~Config() = default; | ||
| }; | ||
|
|
||
| using ConfigConstSharedPtr = std::shared_ptr<const Config>; | ||
|
|
||
| } // namespace Rds | ||
| } // 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 <memory> | ||
|
|
||
| #include "envoy/common/pure.h" | ||
| #include "envoy/rds/config.h" | ||
|
|
||
| #include "source/common/protobuf/protobuf.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Rds { | ||
|
|
||
| /** | ||
| * Traits of the protocol specific route configuration and proto. | ||
| * The generic rds classes will call the methods of this interface | ||
| * to get information which are not visible for them directly. | ||
| */ | ||
| class ProtoTraits { | ||
| public: | ||
| virtual ~ProtoTraits() = default; | ||
|
|
||
| /** | ||
| * Give the full name of the route configuration proto description. | ||
| * For example 'envoy.config.route.v3.RouteConfiguration' | ||
| */ | ||
| virtual std::string resourceType() const PURE; | ||
|
tkovacs-2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Gives back the name field tag number of the route configuration proto. | ||
| */ | ||
| virtual int resourceNameFieldNumber() const PURE; | ||
|
|
||
| /** | ||
| * Create an empty route configuration proto object. | ||
| */ | ||
| virtual ProtobufTypes::MessagePtr createEmptyProto() const PURE; | ||
| }; | ||
|
|
||
| class ConfigTraits { | ||
| public: | ||
| virtual ~ConfigTraits() = default; | ||
|
|
||
| /** | ||
| * Create a dummy config object without actual route configuration. | ||
| * This object will be used before the first valid route configuration is fetched. | ||
| */ | ||
| virtual ConfigConstSharedPtr createNullConfig() const PURE; | ||
|
|
||
| /** | ||
| * Create a config object based on a route configuration. | ||
| * The full name of the type of the parameter message is | ||
| * guaranteed to match with the return value of ProtoTraits::resourceType. | ||
| * Both dynamic or static cast can be applied to downcast the message | ||
| * to the corresponding route configuration class. | ||
| * @throw EnvoyException if the new config can't be applied of. | ||
| */ | ||
| virtual ConfigConstSharedPtr createConfig(const Protobuf::Message& rc) const PURE; | ||
| }; | ||
|
|
||
| } // namespace Rds | ||
| } // 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 <memory> | ||
|
|
||
| #include "envoy/common/time.h" | ||
| #include "envoy/rds/config.h" | ||
|
|
||
| #include "source/common/protobuf/protobuf.h" | ||
|
|
||
| #include "absl/types/optional.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Rds { | ||
|
|
||
| /** | ||
| * A provider for constant route configurations. | ||
| */ | ||
| class RouteConfigProvider { | ||
| public: | ||
| struct ConfigInfo { | ||
| // A reference to the currently loaded route configuration. Do not hold this reference beyond | ||
| // the caller of configInfo()'s scope. | ||
| const Protobuf::Message& config_; | ||
|
|
||
| // The discovery version that supplied this route. This will be set to "" in the case of | ||
| // static clusters. | ||
| const std::string version_; | ||
| }; | ||
|
|
||
| virtual ~RouteConfigProvider() = default; | ||
|
|
||
| /** | ||
| * @return ConfigConstSharedPtr a route configuration for use during a single request. The | ||
| * returned config may be different on a subsequent call, so a new config should be acquired for | ||
| * each request flow. | ||
| */ | ||
| virtual ConfigConstSharedPtr config() PURE; | ||
|
|
||
| /** | ||
| * @return the configuration information for the currently loaded route configuration. Note that | ||
| * if the provider has not yet performed an initial configuration load, no information will be | ||
| * returned. | ||
| */ | ||
| virtual absl::optional<ConfigInfo> configInfo() const PURE; | ||
|
tkovacs-2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @return the last time this RouteConfigProvider was updated. Used for config dumps. | ||
| */ | ||
| virtual SystemTime lastUpdated() const PURE; | ||
|
|
||
| /** | ||
| * Callback used to notify RouteConfigProvider about configuration changes. | ||
| */ | ||
| virtual void onConfigUpdate() PURE; | ||
| }; | ||
|
|
||
| using RouteConfigProviderPtr = std::unique_ptr<RouteConfigProvider>; | ||
| using RouteConfigProviderSharedPtr = std::shared_ptr<RouteConfigProvider>; | ||
|
|
||
| } // namespace Rds | ||
| } // 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,67 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "envoy/common/pure.h" | ||
| #include "envoy/common/time.h" | ||
| #include "envoy/rds/route_config_provider.h" | ||
|
|
||
| #include "absl/types/optional.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Rds { | ||
|
|
||
| /** | ||
| * A primitive that keeps track of updates to a RouteConfiguration. | ||
| */ | ||
| class RouteConfigUpdateReceiver { | ||
| public: | ||
| virtual ~RouteConfigUpdateReceiver() = default; | ||
|
|
||
| /** | ||
| * Called on updates via RDS. | ||
| * @param rc supplies the RouteConfiguration. | ||
| * @param version_info supplies RouteConfiguration version. | ||
| * @return bool whether RouteConfiguration has been updated. | ||
|
tkovacs-2 marked this conversation as resolved.
Outdated
|
||
| * @throw EnvoyException if the new config can't be applied. | ||
| */ | ||
| virtual bool onRdsUpdate(const Protobuf::Message& rc, const std::string& version_info) PURE; | ||
|
|
||
| /** | ||
| * @return std::string& the version of RouteConfiguration. | ||
| */ | ||
| virtual const std::string& configVersion() const PURE; | ||
|
|
||
| /** | ||
| * @return uint64_t the hash value of RouteConfiguration. | ||
| */ | ||
| virtual uint64_t configHash() const PURE; | ||
|
|
||
| /** | ||
| * @return absl::optional<RouteConfigProvider::ConfigInfo> containing an instance of | ||
| * RouteConfigProvider::ConfigInfo if RouteConfiguration has been updated at least once. Otherwise | ||
| * returns an empty absl::optional<RouteConfigProvider::ConfigInfo>. | ||
| */ | ||
| virtual absl::optional<RouteConfigProvider::ConfigInfo> configInfo() const PURE; | ||
|
tkovacs-2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @return envoy::config::route::v3::RouteConfiguration& current RouteConfiguration. | ||
|
tkovacs-2 marked this conversation as resolved.
Outdated
|
||
| */ | ||
| virtual const Protobuf::Message& protobufConfiguration() PURE; | ||
|
|
||
| /** | ||
| * @return ConfigConstSharedPtr a parsed and validated copy of current RouteConfiguration. | ||
| * @see protobufConfiguration() | ||
| */ | ||
| virtual ConfigConstSharedPtr parsedConfiguration() const PURE; | ||
|
|
||
| /** | ||
| * @return SystemTime the time of the last update. | ||
| */ | ||
| virtual SystemTime lastUpdated() const PURE; | ||
| }; | ||
|
|
||
| using RouteConfigUpdatePtr = std::unique_ptr<RouteConfigUpdateReceiver>; | ||
|
|
||
| } // namespace Rds | ||
| } // 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
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.