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

upstream: stats scope for dual filters #23103

Merged
merged 5 commits into from
Sep 14, 2022
Merged
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
12 changes: 7 additions & 5 deletions source/docs/upstream_filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ functionality analysis. Make sure
* Either the filter does not sendLocalReply, or you test and document how
sendLocalReply code paths will play with hedging / retries (cut off the
hedge attempt, and local-reply failures won't trigger retries)
* Either the filter does not access streamInfo in a non-cost way, or you test
* Either the filter does not access streamInfo in a non-const way, or you test
and document how the filter interacts with hedging and retries. Note that
for hedging, a single downstream StreamInfo is accessible in parallel to
both instances of the upstream filter instance, so it must be resiliant to
parallel access.
* Any code accessing the downstream connection checks to make sure it is
present. The downstream connection will not be available for mirrored/shadowed requests.

Once you've done this, you're ready to convert. An example converted filter is the Envoy
[Buffer](https://github.com/envoyproxy/envoy/blob/main/source/extensions/filters/http/buffer/config.cc)
Expand All @@ -25,12 +27,12 @@ Assuming your filter inherits from FactoryBase:
Please note if you use the init manager or a stats context you *must* get
them from DualInfo rather than from the server factory context or xDS
reloads will not work correctly and may leak memory.
* Add ``UpstreamMyFilterFactory = MyFilterFactory;`` and
``DECLARE_FACTORY(UpstreamMyFilterFactory`` in your config.h file and
``REGISTER_FACTORY(UpstreamMyFilterFactory,
                 Server::Configuration::UpstreamHttpFilterConfigFactory){"envoy.my_filter"};`` to
* Add ``using UpstreamMyFilterFactory = MyFilterFactory;`` in your config.h file and
``REGISTER_FACTORY(UpstreamMyFilterFactory, Server::Configuration::UpstreamHttpFilterConfigFactory);`` to
your config.cc file.
* If your filter is listed in ``source/extensions/extensions_metadata.yaml``
add ``envoy.filters.http.upstream`` to the filter category.

Your filter should now be available as an upstream filter.

An example PR for conversion is [23071](https://github.com/envoyproxy/envoy/pull/23071)
5 changes: 3 additions & 2 deletions source/extensions/filters/http/common/factory_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ class DualFactoryBase : public CommonFactoryBase<ConfigProto, RouteConfigProto>,

struct DualInfo {
DualInfo(Server::Configuration::UpstreamHttpFactoryContext& context)
: init_manager(context.initManager()) {}
: init_manager(context.initManager()), scope(context.scope()) {}
DualInfo(Server::Configuration::FactoryContext& context)
: init_manager(context.initManager()) {}
: init_manager(context.initManager()), scope(context.scope()) {}
Init::Manager& init_manager;
Stats::Scope& scope;
};

Http::FilterFactoryCb
Expand Down
1 change: 1 addition & 0 deletions test/mocks/server/factory_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ MockFactoryContext::~MockFactoryContext() = default;
MockUpstreamHttpFactoryContext::MockUpstreamHttpFactoryContext() {
ON_CALL(*this, getServerFactoryContext()).WillByDefault(ReturnRef(server_factory_context_));
ON_CALL(*this, initManager()).WillByDefault(ReturnRef(init_manager_));
ON_CALL(*this, scope()).WillByDefault(ReturnRef(scope_));
}

} // namespace Configuration
Expand Down
1 change: 1 addition & 0 deletions test/mocks/server/factory_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class MockUpstreamHttpFactoryContext : public UpstreamHttpFactoryContext {
MOCK_METHOD(Stats::Scope&, scope, ());
testing::NiceMock<Init::MockManager> init_manager_;
testing::NiceMock<MockServerFactoryContext> server_factory_context_;
testing::NiceMock<Stats::MockIsolatedStatsStore> scope_;
};

} // namespace Configuration
Expand Down