-
Notifications
You must be signed in to change notification settings - Fork 5.5k
http: unified the filter chain creation in the FilterManager #37112
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
Changes from 5 commits
d28e7cf
b37f5b7
4a73cb7
64eb0f9
0308ca1
e13c9a9
dcd4bdf
2bd2592
f2958c5
b7c67b4
8e4b115
cd2e199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,10 +274,14 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>, | |
| } | ||
| void onDecoderFilterBelowWriteBufferLowWatermark() override; | ||
| void onDecoderFilterAboveWriteBufferHighWatermark() override; | ||
| void upgradeFilterChainCreated() override { | ||
| connection_manager_.stats_.named_.downstream_cx_upgrades_total_.inc(); | ||
| connection_manager_.stats_.named_.downstream_cx_upgrades_active_.inc(); | ||
| state_.successful_upgrade_ = true; | ||
| void upgradeFilterChainCreated(bool created) override { | ||
|
wbpcode marked this conversation as resolved.
Outdated
|
||
| if (created) { | ||
| connection_manager_.stats_.named_.downstream_cx_upgrades_total_.inc(); | ||
| connection_manager_.stats_.named_.downstream_cx_upgrades_active_.inc(); | ||
| state_.upgrade_accepted_ = true; | ||
| } else { | ||
| state_.upgrade_rejected_ = true; | ||
| } | ||
| } | ||
| void disarmRequestTimeout() override; | ||
| void resetIdleTimer() override; | ||
|
|
@@ -334,44 +338,42 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>, | |
|
|
||
| // All state for the stream. Put here for readability. | ||
| struct State { | ||
| State() | ||
| : codec_saw_local_complete_(false), codec_encode_complete_(false), | ||
| on_reset_stream_called_(false), is_zombie_stream_(false), successful_upgrade_(false), | ||
| is_internally_destroyed_(false), is_internally_created_(false), is_tunneling_(false), | ||
| decorated_propagate_(true), deferred_to_next_io_iteration_(false), | ||
| deferred_end_stream_(false) {} | ||
|
|
||
| // It's possibly for the codec to see the completed response but not fully | ||
| // encode it. | ||
| bool codec_saw_local_complete_ : 1; // This indicates that local is complete as the completed | ||
| // response has made its way to the codec. | ||
| bool codec_encode_complete_ : 1; // This indicates that the codec has | ||
| // completed encoding the response. | ||
| bool on_reset_stream_called_ : 1; // Whether the stream has been reset. | ||
| bool is_zombie_stream_ : 1; // Whether stream is waiting for signal | ||
| // the underlying codec to be destroyed. | ||
| bool successful_upgrade_ : 1; | ||
|
Comment on lines
-337
to
-365
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes mainly used to fix clang.tidy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. I think that removing the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an example:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. I think we'd prefer to avoid making this struct larger if we don't need to. Can you do a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you are right, it make the state memory footprint from 2 bytes to 11 bytes. Although I am not sure if that make sense or not for software like envoy. we never pursue extreme low memory overhead. But I still revert all these changes. I think @phlax is working on clang-tidy related things. we can do all these at there or change our clang-tidy rule. :) |
||
| bool codec_saw_local_complete_{}; // This indicates that local is complete as the completed | ||
|
wbpcode marked this conversation as resolved.
Outdated
|
||
|
|
||
| // response has made its way to the codec. | ||
| bool codec_encode_complete_{}; // This indicates that the codec has | ||
| // completed encoding the response. | ||
| bool on_reset_stream_called_{}; // Whether the stream has been reset. | ||
| bool is_zombie_stream_{}; // Whether stream is waiting for signal | ||
| // the underlying codec to be destroyed. | ||
|
|
||
| // Whether the upgrade request has be accepted or rejected by the filter chain. | ||
| // Both are false if the request is not an upgrade request. | ||
| bool upgrade_accepted_{}; | ||
| bool upgrade_rejected_{}; | ||
|
wbpcode marked this conversation as resolved.
Outdated
|
||
|
|
||
| // True if this stream was the original externally created stream, but was | ||
| // destroyed as part of internal redirect. | ||
| bool is_internally_destroyed_ : 1; | ||
| bool is_internally_destroyed_{}; | ||
| // True if this stream is internally created. Currently only used for | ||
| // internal redirects or other streams created via recreateStream(). | ||
| bool is_internally_created_ : 1; | ||
| bool is_internally_created_{}; | ||
|
|
||
| // True if the response headers indicate a successful upgrade or connect | ||
| // response. | ||
| bool is_tunneling_ : 1; | ||
| bool is_tunneling_{}; | ||
|
|
||
| bool decorated_propagate_ : 1; | ||
| bool decorated_propagate_{true}; | ||
|
|
||
| // Indicates that sending headers to the filter manager is deferred to the | ||
| // next I/O cycle. If data or trailers are received when this flag is set | ||
| // they are deferred too. | ||
| // TODO(yanavlasov): encapsulate the entire state of deferred streams into a separate | ||
| // structure, so it can be atomically created and cleared. | ||
| bool deferred_to_next_io_iteration_ : 1; | ||
| bool deferred_end_stream_ : 1; | ||
| bool deferred_to_next_io_iteration_{}; | ||
| bool deferred_end_stream_{}; | ||
| }; | ||
|
|
||
| bool canDestroyStream() const { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,8 +461,10 @@ class FilterManagerCallbacks { | |
|
|
||
| /** | ||
| * Called when the FilterManager creates an Upgrade filter chain. | ||
| * @param created whether the upgrade filter chain was created. If false, the upgrade | ||
| * is rejected. | ||
| */ | ||
| virtual void upgradeFilterChainCreated() PURE; | ||
| virtual void upgradeFilterChainCreated(bool created) PURE; | ||
|
|
||
| /** | ||
| * Called when request activity indicates that the request timeout should be disarmed. | ||
|
|
@@ -639,11 +641,10 @@ class FilterManager : public ScopeTrackedObject, | |
| FilterManager(FilterManagerCallbacks& filter_manager_callbacks, Event::Dispatcher& dispatcher, | ||
| OptRef<const Network::Connection> connection, uint64_t stream_id, | ||
| Buffer::BufferMemoryAccountSharedPtr account, bool proxy_100_continue, | ||
| uint32_t buffer_limit, const FilterChainFactory& filter_chain_factory) | ||
| uint32_t buffer_limit) | ||
| : filter_manager_callbacks_(filter_manager_callbacks), dispatcher_(dispatcher), | ||
| connection_(connection), stream_id_(stream_id), account_(std::move(account)), | ||
| proxy_100_continue_(proxy_100_continue), buffer_limit_(buffer_limit), | ||
| filter_chain_factory_(filter_chain_factory) {} | ||
| proxy_100_continue_(proxy_100_continue), buffer_limit_(buffer_limit) {} | ||
|
|
||
| ~FilterManager() override { | ||
| ASSERT(state_.destroyed_); | ||
|
|
@@ -837,8 +838,15 @@ class FilterManager : public ScopeTrackedObject, | |
| virtual StreamInfo::StreamInfo& streamInfo() PURE; | ||
| virtual const StreamInfo::StreamInfo& streamInfo() const PURE; | ||
|
|
||
| // Set up the Encoder/Decoder filter chain. | ||
| bool createFilterChain(); | ||
| /** | ||
| * Set up the Encoder/Decoder filter chain. | ||
| * @param filter_chain_factory the factory to create the filter chain. | ||
| * @param only_create_if_configured whether to only create the filter chain if it is configured | ||
| * explicitly. This only makes sense for upstream HTTP filter chain. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooc is it ever not true for upstream filter chain? I'm wondering if we can infer this as we do the upgrade allowed option if they're just the inverse of each other
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah...it will be false when we try to create filters from router and cluster at second time. As I said before, i think we should remove this by providing a default filter chain factory for upstream filter chain.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be worth doing that now? default filter chain is just codec filter right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it deserves. It not just make code simple also reduce memory overhead of cluster because we now need keep a default filter chain for every cluster. |
||
| * | ||
| */ | ||
| bool createFilterChain(const FilterChainFactory& filter_chain_factory, | ||
| bool only_create_if_configured); | ||
|
|
||
| OptRef<const Network::Connection> connection() const { return connection_; } | ||
|
|
||
|
|
@@ -966,6 +974,9 @@ class FilterManager : public ScopeTrackedObject, | |
| // Indicates which filter to start the iteration with. | ||
| enum class FilterIterationStartState { AlwaysStartFromNext, CanStartFromCurrent }; | ||
|
|
||
| bool createUpgradeFilterChain(const FilterChainFactory& filter_chain_factory, | ||
| const FilterChainOptionsImpl& options); | ||
|
|
||
| // Returns the encoder filter to start iteration with. | ||
| std::list<ActiveStreamEncoderFilterPtr>::iterator | ||
| commonEncodePrefix(ActiveStreamEncoderFilter* filter, bool end_stream, | ||
|
|
@@ -1053,7 +1064,6 @@ class FilterManager : public ScopeTrackedObject, | |
| std::make_shared<Network::Socket::Options>(); | ||
| absl::optional<Upstream::LoadBalancerContext::OverrideHost> upstream_override_host_; | ||
|
|
||
| const FilterChainFactory& filter_chain_factory_; | ||
| // TODO(snowp): Once FM has been moved to its own file we'll make these private classes of FM, | ||
| // at which point they no longer need to be friends. | ||
| friend ActiveStreamFilterBase; | ||
|
|
@@ -1108,11 +1118,11 @@ class DownstreamFilterManager : public FilterManager { | |
| StreamInfo::FilterStateSharedPtr parent_filter_state, | ||
| Server::OverloadManager& overload_manager) | ||
| : FilterManager(filter_manager_callbacks, dispatcher, connection, stream_id, account, | ||
| proxy_100_continue, buffer_limit, filter_chain_factory), | ||
| proxy_100_continue, buffer_limit), | ||
| stream_info_(protocol, time_source, connection.connectionInfoProviderSharedPtr(), | ||
| StreamInfo::FilterState::LifeSpan::FilterChain, | ||
| std::move(parent_filter_state)), | ||
| local_reply_(local_reply), | ||
| local_reply_(local_reply), filter_chain_factory_(filter_chain_factory), | ||
| downstream_filter_load_shed_point_(overload_manager.getLoadShedPoint( | ||
| Server::LoadShedPointName::get().HttpDownstreamFilterCheck)), | ||
| use_filter_manager_state_for_downstream_end_stream_(Runtime::runtimeFeatureEnabled( | ||
|
|
@@ -1136,6 +1146,8 @@ class DownstreamFilterManager : public FilterManager { | |
| stream_info_.setDownstreamRemoteAddress(downstream_remote_address); | ||
| } | ||
|
|
||
| bool createDownstreamFilterChain(); | ||
|
|
||
| /** | ||
| * Called before local reply is made by the filter manager. | ||
| * @param data the data associated with the local reply. | ||
|
|
@@ -1212,6 +1224,7 @@ class DownstreamFilterManager : public FilterManager { | |
| private: | ||
| OverridableRemoteConnectionInfoSetterStreamInfo stream_info_; | ||
| const LocalReply::LocalReply& local_reply_; | ||
| const FilterChainFactory& filter_chain_factory_; | ||
| Utility::PreparedLocalReplyPtr prepared_local_reply_{nullptr}; | ||
| Server::LoadShedPoint* downstream_filter_load_shed_point_{nullptr}; | ||
| // Set by the envoy.reloadable_features.use_filter_manager_state_for_downstream_end_stream runtime | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.