Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cdae885
Support scoped routing configuration.
AndresGuedez Feb 5, 2019
db48450
Derive test class from TestBase.
AndresGuedez Feb 5, 2019
756afcd
fix_format fixes.
AndresGuedez Feb 5, 2019
8e624ea
Merge remote-tracking branch 'upstream/master' into scoped-rds-inline…
AndresGuedez Feb 5, 2019
98149e5
Minor cleanup.
AndresGuedez Feb 5, 2019
76b7196
Fix srds.proto docs.
AndresGuedez Feb 5, 2019
f924eb7
Pendatic spelling and docs cleanup.
AndresGuedez Feb 6, 2019
51d8dff
fix_format.
AndresGuedez Feb 6, 2019
ccca775
More detailed documentation/examples for SRDS.
AndresGuedez Feb 27, 2019
e5d87db
fix_format.
AndresGuedez Feb 27, 2019
9c3d45b
Update pedantic spelling dictionary.
AndresGuedez Feb 27, 2019
afcc2a5
Clarify Scope.Key documentation.
AndresGuedez Feb 27, 2019
c774f00
Use EXPECT_NO_THROW() to validate successful allocation/construction.
AndresGuedez Feb 27, 2019
8cc1b13
fix_format.
AndresGuedez Feb 27, 2019
71f2a74
Modify SRDS to support delta updates and ease transition to incremental.
AndresGuedez Mar 23, 2019
5aed783
Support delta SRDS proto in integration test.
AndresGuedez Mar 29, 2019
15b1c7c
Cleanup.
AndresGuedez Apr 5, 2019
b216034
Add comments.
AndresGuedez Apr 10, 2019
c8f531b
Merge remote-tracking branch 'upstream/master' into scoped-rds-inline…
AndresGuedez Apr 11, 2019
39309ac
Fix build failures after master merge.
AndresGuedez Apr 12, 2019
8fe33ad
Cleanup and comments.
AndresGuedez Apr 12, 2019
8c38526
Fix format.
AndresGuedez Apr 12, 2019
dd2261c
Comments.
AndresGuedez Apr 13, 2019
a7a621b
Merge remote-tracking branch 'upstream/master' into scoped-rds-inline…
AndresGuedez Apr 15, 2019
090bbd8
Cleanup and minor refactor of ConfigProvider framework.
AndresGuedez Apr 16, 2019
8b8a5e7
clang-tidy cleanup.
AndresGuedez Apr 17, 2019
43c95e8
More clang-tidy cleanup.
AndresGuedez Apr 17, 2019
6adaa22
Fix build break.
AndresGuedez Apr 17, 2019
3a4d4e6
Merge remote-tracking branch 'origin/scoped-rds-inline-dynamic' into …
AndresGuedez May 14, 2019
2a4ee03
Merge remote-tracking branch 'upstream/master' into scoped-rds-config…
AndresGuedez May 14, 2019
d401e7c
Fix GCC compiler warning related to hidden overloads.
AndresGuedez May 14, 2019
52d32b5
Improve test coverage.
AndresGuedez May 20, 2019
c611a46
Improve test coverage.
AndresGuedez May 20, 2019
e507e55
Cleanup.
AndresGuedez May 20, 2019
22645d1
Cleanup.
AndresGuedez May 20, 2019
f842132
Use a namespace instead of a class with a static function.
AndresGuedez May 20, 2019
68ed29b
Fix clang-tidy issues.
AndresGuedez May 21, 2019
a5c87fc
Cleanup.
AndresGuedez May 21, 2019
28f39a6
Remove dead code and other minor cleanup.
AndresGuedez May 21, 2019
a8f97f6
Remove unused code and other minor cleanup.
AndresGuedez May 21, 2019
bed4340
Cleanup.
AndresGuedez May 21, 2019
6716559
Fix coverage test.
AndresGuedez May 21, 2019
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
1 change: 1 addition & 0 deletions api/envoy/admin/v2alpha/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ api_proto_library_internal(
"//envoy/api/v2:cds",
"//envoy/api/v2:lds",
"//envoy/api/v2:rds",
"//envoy/api/v2:srds",
"//envoy/config/bootstrap/v2:bootstrap",
],
)
Expand Down
41 changes: 41 additions & 0 deletions api/envoy/admin/v2alpha/config_dump.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option java_package = "io.envoyproxy.envoy.admin.v2alpha";
import "envoy/api/v2/cds.proto";
import "envoy/api/v2/lds.proto";
import "envoy/api/v2/rds.proto";
import "envoy/api/v2/srds.proto";
import "envoy/config/bootstrap/v2/bootstrap.proto";

import "google/protobuf/any.proto";
Expand Down Expand Up @@ -178,3 +179,43 @@ message RoutesConfigDump {
// The dynamically loaded route configs.
repeated DynamicRouteConfig dynamic_route_configs = 3 [(gogoproto.nullable) = false];
}

// Envoy's scoped RDS implementation fills this message with all currently loaded route
// configuration scopes (defined via ScopedRouteConfigurationsSet protos). This message lists both
// the scopes defined inline with the higher order object (i.e., the HttpConnectionManager) and the
// dynamically obtained scopes via the SRDS API.
message ScopedRoutesConfigDump {
message InlineScopedRouteConfigs {
// The name assigned to the scoped route configurations.
string name = 1;

// The scoped route configurations.
repeated envoy.api.v2.ScopedRouteConfiguration scoped_route_configs = 2;

// The timestamp when the scoped route config set was last updated.
google.protobuf.Timestamp last_updated = 3;
}

message DynamicScopedRouteConfigs {
// The name assigned to the scoped route configurations.
string name = 1;

// This is the per-resource version information. This version is currently taken from the
// :ref:`version_info <envoy_api_field_DiscoveryResponse.version_info>` field at the time that
// the scoped routes configuration was loaded.
string version_info = 2;

// The scoped route configurations.
repeated envoy.api.v2.ScopedRouteConfiguration scoped_route_configs = 3;

// The timestamp when the scoped route config set was last updated.
google.protobuf.Timestamp last_updated = 4;
}

// The statically loaded scoped route configs.
repeated InlineScopedRouteConfigs inline_scoped_route_configs = 1 [(gogoproto.nullable) = false];

// The dynamically loaded scoped route configs.
repeated DynamicScopedRouteConfigs dynamic_scoped_route_configs = 2
[(gogoproto.nullable) = false];
}
2 changes: 1 addition & 1 deletion include/envoy/config/config_provider_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ConfigProviderManager {
* @return ConfigProviderPtr a newly allocated static config provider.
*/
virtual ConfigProviderPtr
createStaticConfigProvider(std::vector<std::unique_ptr<const Protobuf::Message>>&& config_protos,
createStaticConfigProvider(ProtobufTypes::ConstMessagePtrVector&& config_protos,
Server::Configuration::FactoryContext& factory_context,
const OptionalArg& optarg) {
UNREFERENCED_PARAMETER(config_protos);
Expand Down
10 changes: 10 additions & 0 deletions include/envoy/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "scopes_interface",
hdrs = ["scopes.h"],
deps = [
":router_interface",
"//include/envoy/config:config_provider_interface",
"//include/envoy/http:header_map_interface",
],
)

envoy_cc_library(
name = "router_ratelimit_interface",
hdrs = ["router_ratelimit.h"],
Expand Down
30 changes: 30 additions & 0 deletions include/envoy/router/scopes.h
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 getRouteConfig(const Http::HeaderMap& headers) const PURE;
};

using ScopedConfigConstSharedPtr = std::shared_ptr<const ScopedConfig>;

} // namespace Router
} // namespace Envoy
2 changes: 2 additions & 0 deletions source/common/config/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TypeUrlValues {
const std::string Secret{"type.googleapis.com/envoy.api.v2.auth.Secret"};
const std::string RouteConfiguration{"type.googleapis.com/envoy.api.v2.RouteConfiguration"};
const std::string VirtualHost{"type.googleapis.com/envoy.api.v2.route.VirtualHost"};
const std::string ScopedRouteConfiguration{
"type.googleapis.com/envoy.api.v2.ScopedRouteConfiguration"};
};

typedef ConstSingleton<TypeUrlValues> TypeUrl;
Expand Down
1 change: 1 addition & 0 deletions source/common/protobuf/protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace ProtobufWkt = google::protobuf;
namespace ProtobufTypes {

typedef std::unique_ptr<Protobuf::Message> MessagePtr;
typedef std::vector<std::unique_ptr<const Protobuf::Message>> ConstMessagePtrVector;

typedef int64_t Int64;

Expand Down
40 changes: 40 additions & 0 deletions source/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,46 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "scoped_config_manager_lib",
srcs = ["scoped_config_manager.cc"],
hdrs = ["scoped_config_manager.h"],
deps = [
"@envoy_api//envoy/api/v2:srds_cc",
],
)

envoy_cc_library(
name = "scoped_config_lib",
srcs = ["scoped_config_impl.cc"],
hdrs = ["scoped_config_impl.h"],
deps = [
":config_lib",
":scoped_config_manager_lib",
"//include/envoy/router:scopes_interface",
"//include/envoy/thread_local:thread_local_interface",
"@envoy_api//envoy/api/v2:srds_cc",
"@envoy_api//envoy/config/filter/network/http_connection_manager/v2:http_connection_manager_cc",
],
)

envoy_cc_library(
name = "scoped_rds_lib",
srcs = ["scoped_rds.cc"],
hdrs = ["scoped_rds.h"],
deps = [
":scoped_config_lib",
"//include/envoy/config:subscription_interface",
"//include/envoy/stats:stats_interface",
"//source/common/common:assert_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/config:config_provider_lib",
"//source/common/config:subscription_factory_lib",
"@envoy_api//envoy/admin/v2alpha:config_dump_cc",
"@envoy_api//envoy/api/v2:srds_cc",
],
)

envoy_cc_library(
name = "retry_state_lib",
srcs = ["retry_state_impl.cc"],
Expand Down
16 changes: 16 additions & 0 deletions source/common/router/scoped_config_impl.cc
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::getRouteConfig(const Http::HeaderMap&) const {
return std::make_shared<const NullConfigImpl>();
}

} // namespace Router
} // namespace Envoy
53 changes: 53 additions & 0 deletions source/common/router/scoped_config_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#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)) {}

void addOrUpdateRoutingScope(const ScopedRouteInfoConstSharedPtr& scoped_route_info);
void removeRoutingScope(const std::string& scope_name);

// Envoy::Router::ScopedConfig
Router::ConfigConstSharedPtr getRouteConfig(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 getRouteConfig(const Http::HeaderMap&) const override {
return std::make_shared<const NullConfigImpl>();
}
};

} // namespace Router
} // namespace Envoy
22 changes: 22 additions & 0 deletions source/common/router/scoped_config_manager.cc
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
49 changes: 49 additions & 0 deletions source/common/router/scoped_config_manager.h
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
Loading