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

filter: add network filters to the upstreams #7503

Merged
merged 34 commits into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ff675d2
filters: install network filters on upstream connections #173
alanconway Jun 7, 2018
33a37b3
merge fix
kyessenov Jul 8, 2019
e599e54
format fix
kyessenov Jul 8, 2019
b04f2d8
fix breakages
kyessenov Jul 8, 2019
6764c12
fix merge failure
kyessenov Jul 9, 2019
f2dd752
update to new style
kyessenov Jul 9, 2019
3a8fc53
fix API build
kyessenov Jul 9, 2019
29d38c0
link to docs
kyessenov Jul 9, 2019
fd3e05e
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 11, 2019
94387ab
add integration test
kyessenov Jul 11, 2019
051a52e
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 12, 2019
6a363bd
update docs and tests
kyessenov Jul 12, 2019
a3c5ae2
trying to fix docs
kyessenov Jul 15, 2019
1b4a3ff
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 16, 2019
855b709
add a release note
kyessenov Jul 16, 2019
3b96763
magic number
kyessenov Jul 16, 2019
edbd8b6
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 17, 2019
b4a1df9
fix stats bound again
kyessenov Jul 17, 2019
f9e616f
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 23, 2019
2fa5594
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 23, 2019
515d224
update proto
kyessenov Jul 23, 2019
8bd08d1
docs
kyessenov Jul 23, 2019
8621f2a
typo
kyessenov Jul 24, 2019
ce2b586
proto correction
kyessenov Jul 24, 2019
7a36ddc
create upstream filter factory context
kyessenov Jul 24, 2019
dc048de
Merge remote-tracking branch 'upstream/master' into upstream-filter
kyessenov Jul 24, 2019
a654705
write filter makes more sense for upstream
kyessenov Jul 24, 2019
236d31d
bump-up stat number
kyessenov Jul 25, 2019
5d8de6e
clang-tidy
kyessenov Jul 25, 2019
bea06ed
review feedback
kyessenov Jul 25, 2019
ca2ed10
bump up stats integration test
kyessenov Jul 26, 2019
1a88776
review
kyessenov Jul 26, 2019
2d533b9
minor nit
kyessenov Jul 26, 2019
34de48a
nit
kyessenov Jul 26, 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
6 changes: 3 additions & 3 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ ClusterLoadReportStats ClusterInfoImpl::generateLoadReportStats(Stats::Scope& sc
}

// Implements the FactoryContext interface required by network filters.
class ClusterInfoImpl::FactoryContextImpl : public Server::Configuration::CommonFactoryContext {
class FactoryContextImpl : public Server::Configuration::CommonFactoryContext {
public:
// Create from a TransportSocketFactoryContext using parent stats_scope and runtime
// other contexts taken from TransportSocketFactoryContext.
Expand Down Expand Up @@ -695,9 +695,9 @@ ClusterInfoImpl::ClusterInfoImpl(
ENVOY_LOG(debug, " name: {}", string_name);
auto& factory = Config::Utility::getAndCheckFactory<
Server::Configuration::NamedUpstreamNetworkFilterConfigFactory>(string_name);
auto message = factory.createEmptyConfigProto().get();
auto message = factory.createEmptyConfigProto();
if (!proto_config.typed_config().value().empty()) {
proto_config.typed_config().UnpackTo(message);
proto_config.typed_config().UnpackTo(message.get());
}
Network::FilterFactoryCb callback =
factory.createFilterFactoryFromProto(*message, *factory_context_);
Expand Down
2 changes: 0 additions & 2 deletions source/common/upstream/upstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ class ClusterInfoImpl : public ClusterInfo, protected Logger::Loggable<Logger::I
const bool warm_hosts_;
absl::optional<std::string> eds_service_name_;
const absl::optional<envoy::api::v2::Cluster::CustomClusterType> cluster_type_;

class FactoryContextImpl;
const std::unique_ptr<Server::Configuration::CommonFactoryContext> factory_context_;
std::vector<Network::FilterFactoryCb> filter_factories_;
};
Expand Down
2 changes: 1 addition & 1 deletion test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ class TestUpstreamNetworkFilterConfigFactory
};
}
ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()};
return std::make_unique<Envoy::ProtobufWkt::Empty>();
}
std::string name() override { return "envoy.test.filter"; }
};
Expand Down
17 changes: 12 additions & 5 deletions test/integration/cluster_filter_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ namespace {

class PoliteFilter : public Network::Filter, Logger::Loggable<Logger::Id::filter> {
public:
PoliteFilter(const ProtobufWkt::StringValue& value) : greeting(value.value()) {}

Network::FilterStatus onData(Buffer::Instance& data, bool end_stream) override {
ENVOY_CONN_LOG(debug, "polite: onData {} bytes {} end_stream", read_callbacks_->connection(),
data.length(), end_stream);
if (!read_greeted_) {
Buffer::OwnedImpl greeter("surely ");
Buffer::OwnedImpl greeter(greeting);
read_callbacks_->injectReadDataToFilterChain(greeter, false);
read_greeted_ = true;
}
Expand Down Expand Up @@ -44,6 +46,7 @@ class PoliteFilter : public Network::Filter, Logger::Loggable<Logger::Id::filter
}

private:
std::string greeting;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const std::string greeting_;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry you are missing the trailing underscore.

/wait

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh, thanks.

Network::ReadFilterCallbacks* read_callbacks_{};
Network::WriteFilterCallbacks* write_callbacks_{};
bool read_greeted_{false};
Expand All @@ -54,15 +57,16 @@ class PoliteFilterConfigFactory
: public Server::Configuration::NamedUpstreamNetworkFilterConfigFactory {
public:
Network::FilterFactoryCb
createFilterFactoryFromProto(const Protobuf::Message&,
createFilterFactoryFromProto(const Protobuf::Message& proto_config,
Server::Configuration::CommonFactoryContext&) override {
return [](Network::FilterManager& filter_manager) -> void {
filter_manager.addFilter(std::make_shared<PoliteFilter>());
auto config = dynamic_cast<const ProtobufWkt::StringValue&>(proto_config);
return [config](Network::FilterManager& filter_manager) -> void {
filter_manager.addFilter(std::make_shared<PoliteFilter>(config));
};
}

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Empty()};
return std::make_unique<ProtobufWkt::StringValue>();
}

std::string name() override { return "envoy.upstream.polite"; }
Expand All @@ -84,6 +88,9 @@ class ClusterFilterIntegrationTest : public testing::TestWithParam<Network::Addr
auto* cluster_0 = bootstrap.mutable_static_resources()->mutable_clusters(0);
auto* filter = cluster_0->add_filters();
filter->set_name("envoy.upstream.polite");
ProtobufWkt::StringValue config;
config.set_value("surely ");
filter->mutable_typed_config()->PackFrom(config);
});
BaseIntegrationTest::initialize();
}
Expand Down