From 0078e565e4c0817877929da94c2c44124c96f485 Mon Sep 17 00:00:00 2001 From: Greg Greenway Date: Thu, 21 Mar 2024 09:43:46 -0700 Subject: [PATCH] fix contrib Signed-off-by: Greg Greenway --- .../rocketmq_proxy/filters/network/source/config.cc | 3 ++- .../filters/network/source/router/route_matcher.cc | 11 +++++++---- .../filters/network/source/router/route_matcher.h | 5 +++-- contrib/rocketmq_proxy/filters/network/test/BUILD | 1 + .../filters/network/test/route_matcher_test.cc | 6 +++++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/contrib/rocketmq_proxy/filters/network/source/config.cc b/contrib/rocketmq_proxy/filters/network/source/config.cc index 4cfb969b14e2..eafed8262dc7 100644 --- a/contrib/rocketmq_proxy/filters/network/source/config.cc +++ b/contrib/rocketmq_proxy/filters/network/source/config.cc @@ -35,7 +35,8 @@ ConfigImpl::ConfigImpl(const RocketmqProxyConfig& config, Server::Configuration::FactoryContext& context) : context_(context), stats_prefix_(fmt::format("rocketmq.{}.", config.stat_prefix())), stats_(RocketmqFilterStats::generateStats(stats_prefix_, context_.scope())), - route_matcher_(new Router::RouteMatcher(config.route_config())), + route_matcher_( + new Router::RouteMatcher(config.route_config(), context.serverFactoryContext())), develop_mode_(config.develop_mode()), transient_object_life_span_(PROTOBUF_GET_MS_OR_DEFAULT(config, transient_object_life_span, TransientObjectLifeSpan)) {} diff --git a/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.cc b/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.cc index d23ab2de9171..8e301377b3b5 100644 --- a/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.cc +++ b/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.cc @@ -12,9 +12,11 @@ namespace RocketmqProxy { namespace Router { RouteEntryImpl::RouteEntryImpl( - const envoy::extensions::filters::network::rocketmq_proxy::v3::Route& route) + const envoy::extensions::filters::network::rocketmq_proxy::v3::Route& route, + Server::Configuration::CommonFactoryContext& context) : topic_name_(route.match().topic()), cluster_name_(route.route().cluster()), - config_headers_(Http::HeaderUtility::buildHeaderDataVector(route.match().headers())) { + config_headers_( + Http::HeaderUtility::buildHeaderDataVector(route.match().headers(), context)) { if (route.route().has_metadata_match()) { const auto filter_it = route.route().metadata_match().filter_metadata().find( @@ -46,9 +48,10 @@ bool RouteEntryImpl::headersMatch(const Http::HeaderMap& headers) const { return Http::HeaderUtility::matchHeaders(headers, config_headers_); } -RouteMatcher::RouteMatcher(const RouteConfig& config) { +RouteMatcher::RouteMatcher(const RouteConfig& config, + Server::Configuration::CommonFactoryContext& context) { for (const auto& route : config.routes()) { - routes_.emplace_back(std::make_shared(route)); + routes_.emplace_back(std::make_shared(route, context)); } ENVOY_LOG(debug, "rocketmq route matcher: routes list size {}", routes_.size()); } diff --git a/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.h b/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.h index 3a4c58715de8..67c02c991463 100644 --- a/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.h +++ b/contrib/rocketmq_proxy/filters/network/source/router/route_matcher.h @@ -26,7 +26,8 @@ class RouteEntryImpl : public RouteEntry, public std::enable_shared_from_this, public Logger::Loggable { public: - RouteEntryImpl(const envoy::extensions::filters::network::rocketmq_proxy::v3::Route& route); + RouteEntryImpl(const envoy::extensions::filters::network::rocketmq_proxy::v3::Route& route, + Server::Configuration::CommonFactoryContext& context); ~RouteEntryImpl() override = default; // Router::RouteEntry @@ -54,7 +55,7 @@ using RouteEntryImplConstSharedPtr = std::shared_ptr; class RouteMatcher : public Logger::Loggable { public: using RouteConfig = envoy::extensions::filters::network::rocketmq_proxy::v3::RouteConfiguration; - RouteMatcher(const RouteConfig& config); + RouteMatcher(const RouteConfig& config, Server::Configuration::CommonFactoryContext& context); RouteConstSharedPtr route(const MessageMetadata& metadata) const; diff --git a/contrib/rocketmq_proxy/filters/network/test/BUILD b/contrib/rocketmq_proxy/filters/network/test/BUILD index 00ac24134fd4..507faac000da 100644 --- a/contrib/rocketmq_proxy/filters/network/test/BUILD +++ b/contrib/rocketmq_proxy/filters/network/test/BUILD @@ -120,6 +120,7 @@ envoy_cc_test( srcs = ["route_matcher_test.cc"], deps = [ "//contrib/rocketmq_proxy/filters/network/source/router:route_matcher", + "//test/mocks/server:server_factory_context_mocks", "//test/test_common:utility_lib", "@envoy_api//contrib/envoy/extensions/filters/network/rocketmq_proxy/v3:pkg_cc_proto", ], diff --git a/contrib/rocketmq_proxy/filters/network/test/route_matcher_test.cc b/contrib/rocketmq_proxy/filters/network/test/route_matcher_test.cc index daef5b3daff0..a2347cd8c604 100644 --- a/contrib/rocketmq_proxy/filters/network/test/route_matcher_test.cc +++ b/contrib/rocketmq_proxy/filters/network/test/route_matcher_test.cc @@ -6,6 +6,9 @@ #include "contrib/envoy/extensions/filters/network/rocketmq_proxy/v3/route.pb.validate.h" #include "contrib/rocketmq_proxy/filters/network/source/metadata.h" #include "contrib/rocketmq_proxy/filters/network/source/router/route_matcher.h" + +#include "test/mocks/server/server_factory_context.h" + #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -46,12 +49,13 @@ name: default_route RouteConfigurationProto config = parseRouteConfigurationFromV2Yaml(yaml); + NiceMock context; MessageMetadata metadata; std::string topic_name = "test_topic"; metadata.setTopicName(topic_name); uint64_t code = 310; metadata.headers().addCopy(Http::LowerCaseString("code"), code); - RouteMatcher matcher(config); + RouteMatcher matcher(config, context); const Envoy::Router::MetadataMatchCriteria* criteria = matcher.route(metadata)->routeEntry()->metadataMatchCriteria(); const std::vector& mmc =