Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions envoy/rds/BUILD
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",
],
)
19 changes: 19 additions & 0 deletions envoy/rds/config.h
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
61 changes: 61 additions & 0 deletions envoy/rds/config_traits.h
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 is 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 const std::string& resourceType() const PURE;

/**
* 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
61 changes: 61 additions & 0 deletions envoy/rds/route_config_provider.h
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() const 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 const absl::optional<ConfigInfo>& configInfo() const PURE;

/**
* @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
63 changes: 63 additions & 0 deletions envoy/rds/route_config_update_receiver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#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 the hash of the new config has been different than
* the hash of the current one and RouteConfiguration has been updated.
* @throw EnvoyException if the new config is invalid and can't be applied.
*/
virtual bool onRdsUpdate(const Protobuf::Message& rc, const std::string& version_info) 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 const absl::optional<RouteConfigProvider::ConfigInfo>& configInfo() const PURE;

/**
* @return Protobuf::Message& current RouteConfiguration.
*/
virtual const Protobuf::Message& protobufConfiguration() const 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
2 changes: 2 additions & 0 deletions envoy/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ envoy_cc_library(
deps = [
":router_interface",
"//envoy/http:filter_interface",
"//envoy/rds:rds_interface",
"@envoy_api//envoy/config/route/v3:pkg_cc_proto",
],
)
Expand Down Expand Up @@ -70,6 +71,7 @@ envoy_cc_library(
"//envoy/http:conn_pool_interface",
"//envoy/http:hash_policy_interface",
"//envoy/http:header_map_interface",
"//envoy/rds:rds_interface",
"//envoy/tcp:conn_pool_interface",
"//envoy/tracing:http_tracer_interface",
"//envoy/upstream:resource_manager_interface",
Expand Down
40 changes: 6 additions & 34 deletions envoy/router/rds.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "envoy/config/route/v3/route.pb.h"
#include "envoy/http/filter.h"
#include "envoy/rds/route_config_provider.h"
#include "envoy/router/router.h"

namespace Envoy {
Expand All @@ -12,43 +13,14 @@ namespace Router {
/**
* A provider for constant route configurations.
*/
class RouteConfigProvider {
class RouteConfigProvider : public Rds::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 envoy::config::route::v3::RouteConfiguration& config_;

// The discovery version that supplied this route. This will be set to "" in the case of
// static clusters.
std::string version_;
};

virtual ~RouteConfigProvider() = default;

/**
* @return Router::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 Router::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;

/**
* @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.
* Same purpose as Rds::RouteConfigProvider::config()
* but the return is downcasted to proper type.
* @return downcasted ConfigConstSharedPtr from Rds::ConfigConstSharedPtr
*/
virtual void onConfigUpdate() PURE;
virtual ConfigConstSharedPtr configCast() const PURE;

/**
* Callback used to request an update to the route configuration from the management server.
Expand Down
56 changes: 7 additions & 49 deletions envoy/router/route_config_update_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "envoy/common/pure.h"
#include "envoy/common/time.h"
#include "envoy/config/route/v3/route.pb.h"
#include "envoy/router/rds.h"
#include "envoy/rds/route_config_update_receiver.h"
#include "envoy/service/discovery/v3/discovery.pb.h"

#include "source/common/protobuf/protobuf.h"
Expand All @@ -18,19 +18,15 @@ namespace Router {
/**
* A primitive that keeps track of updates to a RouteConfiguration.
*/
class RouteConfigUpdateReceiver {
class RouteConfigUpdateReceiver : public Rds::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.
* @throw EnvoyException if the new config can't be applied.
* Same purpose as Rds::RouteConfigUpdateReceiver::protobufConfiguration()
* but the return is downcasted to proper type.
* @return current RouteConfiguration downcasted from Protobuf::Message&
*/
virtual bool onRdsUpdate(const envoy::config::route::v3::RouteConfiguration& rc,
const std::string& version_info) PURE;
virtual const envoy::config::route::v3::RouteConfiguration&
protobufConfigurationCast() const PURE;

using VirtualHostRefVector =
std::vector<std::reference_wrapper<const envoy::config::route::v3::VirtualHost>>;
Expand All @@ -48,16 +44,6 @@ class RouteConfigUpdateReceiver {
const Protobuf::RepeatedPtrField<std::string>& removed_resources,
const std::string& version_info) PURE;

/**
* @return std::string& the name of RouteConfiguration.
*/
virtual const std::string& routeConfigName() const PURE;

/**
* @return std::string& the version of RouteConfiguration.
*/
virtual const std::string& configVersion() const PURE;

/**
* @return bool return whether VHDS configuration has been changed in the last RDS update.
*/
Expand All @@ -66,34 +52,6 @@ class RouteConfigUpdateReceiver {
// intent and the lifecycle of the "last update state" less muddled.
virtual bool vhdsConfigurationChanged() 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;

/**
* @return envoy::config::route::v3::RouteConfiguration& current RouteConfiguration.
*/
virtual const envoy::config::route::v3::RouteConfiguration& protobufConfiguration() PURE;

/**
* @return Router::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;

/**
* @return the union of all resource names and aliases (if any) received with the last VHDS
* update.
Expand Down
Loading