cleanup common factory context using#31072
Conversation
|
Note: The target of this patch is not to remove all Then, we can break the inheritance relationship between Based on above target, this cleanup did different things for different scenarios.
|
Signed-off-by: wbpcode <wbphub@live.com>
4a5af94 to
67c3c79
Compare
| /** | ||
| * Factory context for configuration parsing and initiation. This context contains server factory | ||
| * context reference and a validation visitor from uncertain context (server, listener, cluster or | ||
| * others). | ||
| */ | ||
| class ConfigFactoryContext { | ||
| public: | ||
| virtual ~ConfigFactoryContext() = default; | ||
|
|
||
| /** | ||
| * @return ServerFactoryContext which lifetime is no shorter than the server and provides | ||
| * access to the server's resources. | ||
| */ | ||
| virtual ServerFactoryContext& getServerFactoryContext() const PURE; | ||
|
|
||
| /** | ||
| * @return ProtobufMessage::ValidationVisitor& validation visitor for configuration messages. | ||
| */ | ||
| virtual ProtobufMessage::ValidationVisitor& messageValidationVisitor() const PURE; | ||
| }; |
There was a problem hiding this comment.
Formatter extensions maybe used in both server scope and listener scope. We should use different for message validation visitors in different scopes.
See #31073 for more context.
| virtual Http::RequestIDExtensionSharedPtr | ||
| createExtensionInstance(const Protobuf::Message& config, CommonFactoryContext& context) PURE; | ||
| virtual Http::RequestIDExtensionSharedPtr createExtensionInstance(const Protobuf::Message& config, | ||
| FactoryContext& context) PURE; |
There was a problem hiding this comment.
This change is complete safe because the request id extension is only used in the listener scope. We change the CommonFactoryContext here to FactoryContext directly.
| auto connectivity_manager = Network::ConnectivityManagerFactory{context}.get(); | ||
| auto connectivity_manager = | ||
| Network::ConnectivityManagerFactory{context.getServerFactoryContext()}.get(); |
There was a problem hiding this comment.
This bring a possible logic change. The messageValidationVistior() of server factory context will be used always by the DnsCacheImpl. This is wrong, see See #31073 for more detail.
I will revise this.
| auto typed_config = Envoy::Config::Utility::translateAnyToFactoryConfig( | ||
| formatter.typed_config(), context.messageValidationVisitor(), *factory); | ||
| auto parser = factory->createCommandParserFromProto(*typed_config, context); | ||
| auto parser = | ||
| factory->createCommandParserFromProto(*typed_config, context.getServerFactoryContext()); |
There was a problem hiding this comment.
This bring potential logic change to third party forks (with very low possibility). Because scope(), initManager(), etc methods are different in the FactoryContext and ServerFactoryContext.
But lucky we never use it in our current formatter extensions. (metadata and req_without_query formatters didn't use any context and cel formatter use singleton context only.)
|
|
||
| BodyFormatter(const envoy::config::core::v3::SubstitutionFormatString& config, | ||
| Server::Configuration::CommonFactoryContext& context) | ||
| Server::Configuration::FactoryContext& context) |
There was a problem hiding this comment.
Safe because the BodyFormatter only be used in the listener scope.
There was a problem hiding this comment.
sorry shouldn't thinks in the listener scope have a genericfactorycontext with stats and init manager scoped to the listener?
There was a problem hiding this comment.
Yeah, generic factory context is enough for this scenario. I use FactoryContext just for convenience. I will update it.
| std::vector<Value> | ||
| Config::parse(const Protobuf::RepeatedPtrField<FilterStateValueProto>& proto_values, | ||
| Server::Configuration::CommonFactoryContext& context) const { | ||
| Server::Configuration::ConfigFactoryContext& context) const { |
There was a problem hiding this comment.
The dependency to the Formatter result in this change.
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
|
hm, regarding (3) I thought the plan long term was to have a FactoryContext class which had as the latter two are the only things overridden. For (3) I wonder if we should create that class now, and have a simple wrapper converter so folks can still use those? Want to get thoughts before digging in. |
|
/retest |
|
/wait on CI |
In fact,
I hesitate now. I cannot image in which case the developers may use |
|
Ok, let's create a |
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
…lean-common-factory-context
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
|
|
||
| BodyFormatter(const envoy::config::core::v3::SubstitutionFormatString& config, | ||
| Server::Configuration::CommonFactoryContext& context) | ||
| Server::Configuration::FactoryContext& context) |
There was a problem hiding this comment.
sorry shouldn't thinks in the listener scope have a genericfactorycontext with stats and init manager scoped to the listener?
| // TODO(wbpcode): these is a potential bug of message validation. The validation visitor | ||
| // of server context should not be used here directly. But this is bug is not introduced | ||
| // by this PR and will be fixed in the future. | ||
| Server::GenericFactoryContextImpl generic_context(context, context.messageValidationVisitor()); |
There was a problem hiding this comment.
mm, if this may be a problem shouldn't we not switch to server factory context here? I'd think if we wanted to inherit validation we'd need to keep this a generic.
| LocalResponsePolicy(const envoy::extensions::http::custom_response::local_response_policy::v3:: | ||
| LocalResponsePolicy& config, | ||
| Server::Configuration::CommonFactoryContext& context); | ||
| Server::Configuration::ServerFactoryContext& context); |
There was a problem hiding this comment.
In general passing Generic makes more sense than server in case folks want (properly scoped) stats down the road WDYT?
There was a problem hiding this comment.
Actually, in previous implementation, the backend of CommonFactoryContext here will always be a ServerFactoryContext.
As I said in the TODO, this potential bug is not introduced by this patch. The LocalResponsePolicy will be created in the createPolicy method which will always take a ServerFactoryContext.
This patch just wrappered the ServerFactoryContext to a GenericFactoryContext (for Formatter usage) and doesn't change any logic or behavior here.
See:
Extensions::HttpFilters::CustomResponse::PolicySharedPtr
LocalResponseFactory::createPolicy(const Protobuf::Message& config,
Envoy::Server::Configuration::ServerFactoryContext& context,
Stats::StatName) {
const auto& local_response_config =
MessageUtil::downcastAndValidate<const LocalResponsePolicyProto&>(
config, context.messageValidationVisitor());
return std::make_shared<LocalResponsePolicy>(local_response_config, context);
}
There was a problem hiding this comment.
Although I think we should fix this bug (this is why I left a TODO and #31073), but the fix also a behavior change. I don't want introduce any additional behavior changes (except we have no choice) in this big PR.
But if you still think to fix it here make sense, I also can update it. :)
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
| "//source/extensions/clusters/strict_dns:strict_dns_cluster_lib", | ||
| "//source/extensions/load_balancing_policies/cluster_provided:config", | ||
| "//source/extensions/load_balancing_policies/least_request:config", | ||
| "//source/extensions/load_balancing_policies/maglev:config", | ||
| "//source/extensions/load_balancing_policies/random:config", | ||
| "//source/extensions/load_balancing_policies/ring_hash:config", | ||
| "//source/extensions/load_balancing_policies/round_robin:config", | ||
| "//source/extensions/load_balancing_policies/subset:config", |
There was a problem hiding this comment.
Seems this patch add some more symbols and result in coverage linking failure. I removed some unnecessary extensions here to make the CI green. orz.
|
Coverage.... But at least I know how to fix it... let me do it tomorrow. |
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
Signed-off-by: wbpcode <wbphub@live.com>
|
finally...... |
Commit Message: cleanup common factory context using
Additional Description:
Part of factory context refactoring and clean up. This PR clean up all remaining
CommonFactoryContextusing.Risk Level: mid.
Testing: n/a.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.