-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
config: refactor filter registration #1083
Conversation
Seems reasonable at design level. To simplify review, could you split out the mechanical rename of scope/stats and any other trivials into a separate PR? |
Yes I will split it. Right now I'm just trying to clean up some stuff and see a coverage report. |
e37f4db
to
01c5941
Compare
For LDS, we need to plumb a stats scope through to all of the filter factory creation functions. This commit takes the opportunity to no longer pass the full server and instead passes a new FactoryContext interface which will allow us to more easily alter what is seen by filters in the future. Though this is a breaking change, since we are still in the 1.4.0 release cycle I will not be deprecating the new network/http filter registration functions that were added during this cycle.
01c5941
to
d5508d9
Compare
Sorry it's ready to go modulo fixing the example config repo. Will do that in the morning. The rest is ready to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
envoy_cc_library( | ||
name = "filter_config_interface", | ||
hdrs = ["filter_config.h"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have deps for all the included header interfaces.
/** | ||
* @return Upstream::ClusterManager& singleton for use by the entire server. | ||
*/ | ||
virtual Upstream::ClusterManager& clusterManager() PURE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume all of these are needed for existing filter and there is no further way to minimize the exposed surface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, minimized as much as possible.
include/envoy/server/filter_config.h
Outdated
/** | ||
* This lambda is used to wrap the creation of a network filter chain for new connections as they | ||
* come in. Filter factories create the lambda at configuration initialization time, and then they | ||
* are used at runtime. This maps JSON -> runtime configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit unclear from this type signature that this is what is happening. All you get is a Network::FilterManager
, whereas when I look at how this is used later, it's capturing JSON config in the lambda in some examples. I think maybe this should be made clearer.
include/envoy/server/filter_config.h
Outdated
enum class NetworkFilterType { Read, Write, Both }; | ||
|
||
/** | ||
* This lambda is used to wrap the creation of a network filter chain for new connections as they |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since this is std::function
, it's not necessarily a lambda.
* of general error or a Json::Exception if the json configuration is erroneous. The returned | ||
* callback should always be initialized. | ||
* @param config supplies the general json configuration for the filter | ||
* @param context supplies the filter's context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: @return
include/envoy/server/filter_config.h
Outdated
|
||
/** | ||
* Returns the identifying name for a particular implementation of a network filter produced by | ||
* the factory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: @return
/** | ||
* Create a particular network filter factory implementation. If the implementation is unable to | ||
* produce a factory with the provided parameters, it should throw an EnvoyException in the case | ||
* of general error or a Json::Exception if the json configuration is erroneous. The returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the factory lambda captures some JSON config and then finds an issue at runtime instantiation?
include/envoy/server/filter_config.h
Outdated
* Create a particular http filter factory implementation. If the implementation is unable to | ||
* produce a factory with the provided parameters, it should throw an EnvoyException in the case of | ||
* general error or a Json::Exception if the json configuration is erroneous. The returned | ||
* callback should always be initialized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as for the network filters above.
@@ -158,17 +152,17 @@ HttpConnectionManagerConfig::HttpConnectionManagerConfig(const Json::Object& con | |||
|
|||
// Now see if there is a factory that will accept the config. | |||
auto search_it = namedFilterConfigFactories().find(string_name); | |||
if (search_it != namedFilterConfigFactories().end()) { | |||
if (search_it != namedFilterConfigFactories().end() && search_it->second->type() == type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there tests covering a found filter with wrong type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not. Will add.
Note that re: the comments about the function documentation, I just copied that, but will go ahead and clean up the text to make it more clear. |
@htuch updated per comments |
include/envoy/server/filter_config.h
Outdated
* callback should always be initialized. | ||
* @param config supplies the general json configuration for the filter | ||
* @param context supplies the filter's context. | ||
* @return NetworkFilterFactoryCb fixfix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixfix :-)
include/envoy/server/filter_config.h
Outdated
* @param config supplies the general json configuration for the filter | ||
* @param stat_prefix prefix for stat logging | ||
* @param context supplies the filter's context. | ||
* @return HttpFilterFactoryCb fixfix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here as well, fixfix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* updates required for envoyproxy/envoy#1083 * update envoy
Cleanups from #1083. Rename some variables and repoint to filter example master. No logic changes.
Cleanups from #1083. Rename some variables and repoint to filter example master. No logic changes.
Regression from #1083. The listener config needs two scopes. One for listener named stats, and one for global named stats that need to be reaped during LDS processing.
Regression from #1083. The listener config needs two scopes. One for listener named stats, and one for global named stats that need to be reaped during LDS processing.
Signed-off-by: Jose Nino <[email protected]> Signed-off-by: JP Simard <[email protected]>
Signed-off-by: Jose Nino <[email protected]> Signed-off-by: JP Simard <[email protected]>
For LDS, we need to plumb a stats scope through to all of the filter
factory creation functions. This commit takes the opportunity to no
longer pass the full server and instead passes a new FactoryContext
interface which will allow us to more easily alter what is seen by
filters in the future. While making the same breaking change, I
took the opportunity to encode the type of filter into the registration
which removes a ton of boilerplate from various places. (We have
decided to remove the ability to explicitly configure filter type in the
v2 API).
Though this is a breaking change, since we
are still in the 1.4.0 release cycle I will not be deprecating
the new network/http filter registration functions that were
added during this cycle.
This commit also improves some related coverage and gets us up to
around 98.2%. I will do a follow up change with some other easy
coverage wins that I notice.