Skip to content

Commit

Permalink
fix contrib
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Greenway <ggreenway@apple.com>
  • Loading branch information
ggreenway committed Mar 21, 2024
1 parent bb98647 commit 0078e56
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion contrib/rocketmq_proxy/filters/network/source/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<RouteEntryImpl>(route));
routes_.emplace_back(std::make_shared<RouteEntryImpl>(route, context));
}
ENVOY_LOG(debug, "rocketmq route matcher: routes list size {}", routes_.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class RouteEntryImpl : public RouteEntry,
public std::enable_shared_from_this<RouteEntryImpl>,
public Logger::Loggable<Logger::Id::rocketmq> {
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
Expand Down Expand Up @@ -54,7 +55,7 @@ using RouteEntryImplConstSharedPtr = std::shared_ptr<const RouteEntryImpl>;
class RouteMatcher : public Logger::Loggable<Logger::Id::rocketmq> {
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;

Expand Down
1 change: 1 addition & 0 deletions contrib/rocketmq_proxy/filters/network/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -46,12 +49,13 @@ name: default_route

RouteConfigurationProto config = parseRouteConfigurationFromV2Yaml(yaml);

NiceMock<Server::Configuration::MockServerFactoryContext> 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<Envoy::Router::MetadataMatchCriterionConstSharedPtr>& mmc =
Expand Down

0 comments on commit 0078e56

Please sign in to comment.