Skip to content
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

Add scoped routing #8

Closed
wants to merge 19 commits into from
Closed
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
2 changes: 2 additions & 0 deletions include/envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ struct ResponseCodeDetailValues {
// The request was rejected because it attempted an unsupported upgrade.
const std::string UpgradeFailed = "upgrade_failed";

// The request was rejected by the HCM because there was no route configuration found.
const std::string RouteConfigurationNotFound = "route_configuration_not_found";
// The request was rejected by the router filter because there was no route found.
const std::string RouteNotFound = "route_not_found";
// A direct response was generated by the router filter.
Expand Down
1 change: 1 addition & 0 deletions source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ envoy_cc_library(
"//include/envoy/router:rds_interface",
"//include/envoy/router:scopes_interface",
"//include/envoy/runtime:runtime_interface",
"//include/envoy/server:admin_interface",
"//include/envoy/server:overload_manager_interface",
"//include/envoy/ssl:connection_interface",
"//include/envoy/stats:stats_interface",
Expand Down
45 changes: 44 additions & 1 deletion source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "envoy/event/dispatcher.h"
#include "envoy/network/drain_decision.h"
#include "envoy/router/router.h"
#include "envoy/server/admin.h"
#include "envoy/ssl/connection.h"
#include "envoy/stats/scope.h"
#include "envoy/tracing/http_tracer.h"
Expand Down Expand Up @@ -431,12 +432,25 @@ void ConnectionManagerImpl::chargeTracingStats(const Tracing::Reason& tracing_re

ConnectionManagerImpl::ActiveStream::ActiveStream(ConnectionManagerImpl& connection_manager)
: connection_manager_(connection_manager),
snapped_route_config_(connection_manager.config_.routeConfigProvider()->config()),
stream_id_(connection_manager.random_generator_.random()),
request_response_timespan_(new Stats::Timespan(
connection_manager_.stats_.named_.downstream_rq_time_, connection_manager_.timeSource())),
stream_info_(connection_manager_.codec_->protocol(), connection_manager_.timeSource()),
upstream_options_(std::make_shared<Network::Socket::Options>()) {
// For Admin thread, we don't use routeConfigProvider or SRDS route provider.
ASSERT(dynamic_cast<Server::Admin*>(&connection_manager_.config_) != nullptr ||
((connection_manager.config_.routeConfigProvider() == nullptr &&
connection_manager.config_.scopedRouteConfigProvider() != nullptr) ||
(connection_manager.config_.routeConfigProvider() != nullptr &&
connection_manager.config_.scopedRouteConfigProvider() == nullptr)),
"Either routeConfigProvider or scopedRouteConfigProvider should be set in "
"ConnectionManagerImpl.");
if (connection_manager.config_.routeConfigProvider() != nullptr) {
snapped_route_config_ = connection_manager.config_.routeConfigProvider()->config();
} else if (connection_manager.config_.scopedRouteConfigProvider() != nullptr) {
snapped_scoped_routes_config_ =
connection_manager_.config_.scopedRouteConfigProvider()->config<Router::ScopedConfig>();
}
ScopeTrackerScopeState scope(this,
connection_manager_.read_callbacks_->connection().dispatcher());

Expand Down Expand Up @@ -612,6 +626,35 @@ void ConnectionManagerImpl::ActiveStream::decodeHeaders(HeaderMapPtr&& headers,
ScopeTrackerScopeState scope(this,
connection_manager_.read_callbacks_->connection().dispatcher());
request_headers_ = std::move(headers);
// For Admin thread, we don't use routeConfigProvider or SRDS route provider.
if (dynamic_cast<Server::Admin*>(&connection_manager_.config_) == nullptr &&
connection_manager_.config_.scopedRouteConfigProvider() != nullptr) {
ASSERT(snapped_route_config_ == nullptr,
"Route config already latched to the active stream when scoped RDS is enabled.");
if (snapped_scoped_routes_config_ == nullptr) {
ENVOY_STREAM_LOG(trace, "snapped scoped routes config is null when SRDS is enabled.", *this);
// Stop decoding now.
maybeEndDecode(true);
sendLocalReply(
Grpc::Common::hasGrpcContentType(*request_headers_), Http::Code::InternalServerError,
"scoped routes config not set when SRDS is enabled", nullptr, is_head_request_,
absl::nullopt, StreamInfo::ResponseCodeDetails::get().RouteConfigurationNotFound);
return;
}
snapped_route_config_ = snapped_scoped_routes_config_->getRouteConfig(*request_headers_);
// NOTE: if a RDS subscription hasn't got a RouteConfiguration back, a Router::NullConfigImpl is
// returned, in that case we let it pass.
if (snapped_route_config_ == nullptr) {
ENVOY_STREAM_LOG(trace, "can't find SRDS scope.", *this);
// Stop decoding now.
maybeEndDecode(true);
sendLocalReply(Grpc::Common::hasGrpcContentType(*request_headers_), Http::Code::NotFound,
"route scope not found", nullptr, is_head_request_, absl::nullopt,
StreamInfo::ResponseCodeDetails::get().RouteConfigurationNotFound);
return;
}
}

if (Http::Headers::get().MethodValues.Head ==
request_headers_->Method()->value().getStringView()) {
is_head_request_ = true;
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/conn_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>,

ConnectionManagerImpl& connection_manager_;
Router::ConfigConstSharedPtr snapped_route_config_;
Router::ScopedConfigConstSharedPtr snapped_scoped_route_config_;
Router::ScopedConfigConstSharedPtr snapped_scoped_routes_config_;
Tracing::SpanPtr active_span_;
const uint64_t stream_id_;
StreamEncoder* response_encoder_{};
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/scoped_config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ScopedRouteInfo {
const std::string& scopeName() const { return config_proto_.name(); }

private:
envoy::api::v2::ScopedRouteConfiguration config_proto_;
const envoy::api::v2::ScopedRouteConfiguration config_proto_;
ScopeKey scope_key_;
ConfigConstSharedPtr route_config_;
};
Expand Down
1 change: 0 additions & 1 deletion source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ void ScopedRdsConfigSubscription::onConfigUpdate(
}
onConfigUpdate(to_add_repeated, to_remove_repeated, version_info);
} // namespace Router

ScopedRdsConfigProvider::ScopedRdsConfigProvider(
ScopedRdsConfigSubscriptionSharedPtr&& subscription)
: MutableConfigProviderCommonBase(std::move(subscription), ConfigProvider::ApiType::Delta) {}
Expand Down
15 changes: 2 additions & 13 deletions test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,6 @@ envoy_cc_test_library(
],
)

envoy_cc_test_library(
name = "conn_manager_impl_common_lib",
hdrs = ["conn_manager_impl_common.h"],
deps = [
"//include/envoy/common:time_interface",
"//include/envoy/config:config_provider_interface",
"//include/envoy/router:rds_interface",
"//test/mocks/router:router_mocks",
],
)

envoy_proto_library(
name = "conn_manager_impl_fuzz_proto",
srcs = ["conn_manager_impl_fuzz.proto"],
Expand All @@ -153,7 +142,6 @@ envoy_cc_fuzz_test(
srcs = ["conn_manager_impl_fuzz_test.cc"],
corpus = "conn_manager_impl_corpus",
deps = [
":conn_manager_impl_common_lib",
":conn_manager_impl_fuzz_proto_cc",
"//source/common/common:empty_string",
"//source/common/http:conn_manager_lib",
Expand All @@ -166,6 +154,7 @@ envoy_cc_fuzz_test(
"//test/mocks/http:http_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/network:network_mocks",
"//test/mocks/router:router_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/ssl:ssl_mocks",
"//test/mocks/tracing:tracing_mocks",
Expand All @@ -179,7 +168,6 @@ envoy_cc_test(
name = "conn_manager_impl_test",
srcs = ["conn_manager_impl_test.cc"],
deps = [
":conn_manager_impl_common_lib",
"//include/envoy/access_log:access_log_interface",
"//include/envoy/buffer:buffer_interface",
"//include/envoy/event:dispatcher_interface",
Expand All @@ -206,6 +194,7 @@ envoy_cc_test(
"//test/mocks/http:http_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/network:network_mocks",
"//test/mocks/router:router_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/server:server_mocks",
"//test/mocks/ssl:ssl_mocks",
Expand Down
54 changes: 0 additions & 54 deletions test/common/http/conn_manager_impl_common.h

This file was deleted.

25 changes: 18 additions & 7 deletions test/common/http/conn_manager_impl_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "common/network/address_impl.h"
#include "common/network/utility.h"

#include "test/common/http/conn_manager_impl_common.h"
#include "test/common/http/conn_manager_impl_fuzz.pb.h"
#include "test/fuzz/fuzz_runner.h"
#include "test/fuzz/utility.h"
Expand All @@ -29,6 +28,7 @@
#include "test/mocks/http/mocks.h"
#include "test/mocks/local_info/mocks.h"
#include "test/mocks/network/mocks.h"
#include "test/mocks/router/mocks.h"
#include "test/mocks/runtime/mocks.h"
#include "test/mocks/ssl/mocks.h"
#include "test/mocks/tracing/mocks.h"
Expand All @@ -46,13 +46,15 @@ namespace Http {
class FuzzConfig : public ConnectionManagerConfig {
public:
FuzzConfig()
: route_config_provider_(time_system_), scoped_route_config_provider_(time_system_),
stats_{{ALL_HTTP_CONN_MAN_STATS(POOL_COUNTER(fake_stats_), POOL_GAUGE(fake_stats_),
: stats_{{ALL_HTTP_CONN_MAN_STATS(POOL_COUNTER(fake_stats_), POOL_GAUGE(fake_stats_),
POOL_HISTOGRAM(fake_stats_))},
"",
fake_stats_},
tracing_stats_{CONN_MAN_TRACING_STATS(POOL_COUNTER(fake_stats_))},
listener_stats_{CONN_MAN_LISTENER_STATS(POOL_COUNTER(fake_stats_))} {
ON_CALL(route_config_provider_, lastUpdated()).WillByDefault(Return(time_system_.systemTime()));
ON_CALL(scoped_route_config_provider_, lastUpdated())
.WillByDefault(Return(time_system_.systemTime()));
access_logs_.emplace_back(std::make_shared<NiceMock<AccessLog::MockInstance>>());
}

Expand Down Expand Up @@ -85,9 +87,17 @@ class FuzzConfig : public ConnectionManagerConfig {
std::chrono::milliseconds streamIdleTimeout() const override { return stream_idle_timeout_; }
std::chrono::milliseconds requestTimeout() const override { return request_timeout_; }
std::chrono::milliseconds delayedCloseTimeout() const override { return delayed_close_timeout_; }
Router::RouteConfigProvider* routeConfigProvider() override { return &route_config_provider_; }
Router::RouteConfigProvider* routeConfigProvider() override {
if (use_srds_) {
return nullptr;
}
return &route_config_provider_;
}
Config::ConfigProvider* scopedRouteConfigProvider() override {
return &scoped_route_config_provider_;
if (use_srds_) {
return &scoped_route_config_provider_;
}
return nullptr;
}
const std::string& serverName() override { return server_name_; }
ConnectionManagerStats& stats() override { return stats_; }
Expand Down Expand Up @@ -120,8 +130,9 @@ class FuzzConfig : public ConnectionManagerConfig {
NiceMock<MockFilterChainFactory> filter_factory_;
Event::SimulatedTimeSystem time_system_;
SlowDateProviderImpl date_provider_{time_system_};
ConnectionManagerImplHelper::RouteConfigProvider route_config_provider_;
ConnectionManagerImplHelper::ScopedRouteConfigProvider scoped_route_config_provider_;
bool use_srds_{};
Router::MockRouteConfigProvider route_config_provider_;
Router::MockScopedRouteConfigProvider scoped_route_config_provider_;
std::string server_name_;
Stats::IsolatedStoreImpl fake_stats_;
ConnectionManagerStats stats_;
Expand Down
Loading