Skip to content

Commit

Permalink
auto-merge envoyproxy/envoy[main] into envoyproxy/envoy-openssl[main]
Browse files Browse the repository at this point in the history
* upstream/main:
  srds: minor perf: move scoped_route_config to ScopedRouteInfo (#36270)
  • Loading branch information
sync-envoy[bot] committed Sep 30, 2024
2 parents cd50f2d + f7bde8c commit 4296c2a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions source/common/router/scoped_config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ HeaderValueExtractorImpl::computeFragment(const Http::HeaderMap& headers) const
return nullptr;
}

ScopedRouteInfo::ScopedRouteInfo(envoy::config::route::v3::ScopedRouteConfiguration config_proto,
ScopedRouteInfo::ScopedRouteInfo(envoy::config::route::v3::ScopedRouteConfiguration&& config_proto,
ConfigConstSharedPtr route_config)
: config_proto_(config_proto), route_config_(route_config),
config_hash_(MessageUtil::hash(config_proto)) {
: config_proto_(std::move(config_proto)), route_config_(route_config),
config_hash_(MessageUtil::hash(config_proto_)) {
// TODO(stevenzzzz): Maybe worth a KeyBuilder abstraction when there are more than one type of
// Fragment.
for (const auto& fragment : config_proto_.key().fragments()) {
Expand Down
6 changes: 3 additions & 3 deletions source/common/router/scoped_config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ScopeKeyBuilderImpl : public ScopeKeyBuilderBase {
// ScopedRouteConfiguration and corresponding RouteConfigProvider.
class ScopedRouteInfo {
public:
ScopedRouteInfo(envoy::config::route::v3::ScopedRouteConfiguration config_proto,
ScopedRouteInfo(envoy::config::route::v3::ScopedRouteConfiguration&& config_proto,
ConfigConstSharedPtr route_config);

const ConfigConstSharedPtr& routeConfig() const { return route_config_; }
Expand All @@ -89,9 +89,9 @@ class ScopedRouteInfo {
uint64_t configHash() const { return config_hash_; }

private:
envoy::config::route::v3::ScopedRouteConfiguration config_proto_;
const envoy::config::route::v3::ScopedRouteConfiguration config_proto_;
ScopeKey scope_key_;
ConfigConstSharedPtr route_config_;
const ConfigConstSharedPtr route_config_;
const uint64_t config_hash_;
};
using ScopedRouteInfoConstSharedPtr = std::shared_ptr<const ScopedRouteInfo>;
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ makeScopedRouteInfos(ProtobufTypes::ConstMessagePtrVector&& config_protos,
config_provider_manager.routeConfigProviderManager().createStaticRouteConfigProvider(
scoped_route_config.route_configuration(), factory_context,
factory_context.messageValidationContext().staticValidationVisitor());
scopes.push_back(std::make_shared<const ScopedRouteInfo>(scoped_route_config,
scopes.push_back(std::make_shared<const ScopedRouteInfo>(std::move(scoped_route_config),
route_config_provider->configCast()));
}

Expand Down
16 changes: 10 additions & 6 deletions test/common/router/scoped_config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,23 @@ TEST_F(ScopedRouteInfoTest, Creation) {

// Tests that config hash changes if ScopedRouteConfiguration of the ScopedRouteInfo changes.
TEST_F(ScopedRouteInfoTest, Hash) {
const envoy::config::route::v3::ScopedRouteConfiguration config_copy = scoped_route_config_;
info_ = std::make_unique<ScopedRouteInfo>(scoped_route_config_, route_config_);
envoy::config::route::v3::ScopedRouteConfiguration scoped_route_config1 = scoped_route_config_;
info_ = std::make_unique<ScopedRouteInfo>(std::move(scoped_route_config1), route_config_);
EXPECT_EQ(info_->routeConfig().get(), route_config_.get());
EXPECT_TRUE(TestUtility::protoEqual(info_->configProto(), config_copy));
EXPECT_TRUE(TestUtility::protoEqual(info_->configProto(), scoped_route_config_));
EXPECT_EQ(info_->scopeName(), "foo_scope");
EXPECT_EQ(info_->scopeKey(), makeKey({"foo", "bar"}));

const auto info2 = std::make_unique<ScopedRouteInfo>(scoped_route_config_, route_config_);
envoy::config::route::v3::ScopedRouteConfiguration scoped_route_config2 = scoped_route_config_;
const auto info2 =
std::make_unique<ScopedRouteInfo>(std::move(scoped_route_config2), route_config_);
ASSERT_EQ(info2->configHash(), info_->configHash());

// Mutate the config and hash should be different now.
scoped_route_config_.set_on_demand(true);
const auto info3 = std::make_unique<ScopedRouteInfo>(scoped_route_config_, route_config_);
envoy::config::route::v3::ScopedRouteConfiguration scoped_route_config3 = scoped_route_config_;
scoped_route_config3.set_on_demand(true);
const auto info3 =
std::make_unique<ScopedRouteInfo>(std::move(scoped_route_config3), route_config_);
ASSERT_NE(info3->configHash(), info_->configHash());
}

Expand Down

0 comments on commit 4296c2a

Please sign in to comment.