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

ecds: rationalize ownership #19630

Merged
merged 9 commits into from
Feb 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
14 changes: 14 additions & 0 deletions envoy/thread_local/thread_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class Slot {
// Callers must use the TypedSlot API, below.
virtual void runOnAllThreads(const UpdateCb& update_cb) PURE;
virtual void runOnAllThreads(const UpdateCb& update_cb, const Event::PostCb& complete_cb) PURE;

/**
* Returns whether or not global threading has been shutdown.
*
* @return true if global threading has been shutdown or false if not.
*/
virtual bool isShutdown() const PURE;
};

using SlotPtr = std::unique_ptr<Slot>;
Expand Down Expand Up @@ -177,6 +184,13 @@ template <class T> class TypedSlot {
slot_->runOnAllThreads(makeSlotUpdateCb(cb), complete_cb);
}

/**
* Returns whether or not global threading has been shutdown.
*
* @return true if global threading has been shutdown or false if not.
*/
bool isShutdown() const { return slot_->isShutdown(); };

private:
static OptRef<T> getOpt(ThreadLocalObjectSharedPtr obj) {
if (obj) {
Expand Down
46 changes: 14 additions & 32 deletions source/common/filter/config_discovery_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "source/common/common/containers.h"
#include "source/common/common/thread.h"
#include "source/common/config/utility.h"
#include "source/common/grpc/common.h"
#include "source/common/protobuf/utility.h"

Expand Down Expand Up @@ -57,17 +56,10 @@ void DynamicFilterConfigProviderImplBase::validateTypeUrl(const std::string& typ

const std::string& DynamicFilterConfigProviderImplBase::name() { return subscription_->name(); }

void DynamicFilterConfigProviderImplBase::validateTerminalFilter(const std::string& name,
const std::string& filter_type,
bool is_terminal_filter) {
Config::Utility::validateTerminalFilters(name, filter_type, filter_chain_type_,
is_terminal_filter, last_filter_in_filter_chain_);
}

FilterConfigSubscription::FilterConfigSubscription(
const envoy::config::core::v3::ConfigSource& config_source,
const std::string& filter_config_name, Server::Configuration::FactoryContext& factory_context,
const std::string& stat_prefix,
const std::string& filter_config_name,
Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix,
FilterConfigProviderManagerImplBase& filter_config_provider_manager,
const std::string& subscription_id)
: Config::SubscriptionBase<envoy::config::core::v3::TypedExtensionConfig>(
Expand Down Expand Up @@ -122,10 +114,10 @@ void FilterConfigSubscription::onConfigUpdate(
for (auto* provider : filter_config_providers_) {
provider->validateTypeUrl(type_url);
}
auto [message, factory_name, is_terminal_filter] =
auto [message, factory_name] =
filter_config_provider_manager_.getMessage(filter_config, factory_context_);
for (auto* provider : filter_config_providers_) {
provider->validateTerminalFilter(filter_config_name_, factory_name, is_terminal_filter);
provider->validateMessage(filter_config_name_, *message, factory_name);
}
ENVOY_LOG(debug, "Updating filter config {}", filter_config_name_);

Expand All @@ -140,8 +132,7 @@ void FilterConfigSubscription::onConfigUpdate(
last_config_ = std::move(message);
last_type_url_ = type_url;
last_version_info_ = version_info;
last_filter_name_ = factory_name;
last_filter_is_terminal_ = is_terminal_filter;
last_factory_name_ = factory_name;
}

void FilterConfigSubscription::onConfigUpdate(
Expand All @@ -160,8 +151,8 @@ void FilterConfigSubscription::onConfigUpdate(
last_config_hash_ = 0;
last_config_ = nullptr;
last_type_url_ = "";
last_filter_is_terminal_ = false;
last_filter_name_ = "";
last_version_info_ = "";
last_factory_name_ = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add last_version_info_ = "";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

} else if (!added_resources.empty()) {
onConfigUpdate(added_resources, added_resources[0].get().version());
}
Expand Down Expand Up @@ -195,7 +186,8 @@ std::shared_ptr<FilterConfigSubscription> FilterConfigProviderManagerImplBase::g
auto it = subscriptions_.find(subscription_id);
if (it == subscriptions_.end()) {
auto subscription = std::make_shared<FilterConfigSubscription>(
config_source, name, factory_context, stat_prefix, *this, subscription_id);
config_source, name, factory_context.getServerFactoryContext(), stat_prefix, *this,
subscription_id);
subscriptions_.insert({subscription_id, std::weak_ptr<FilterConfigSubscription>(subscription)});
return subscription;
} else {
Expand All @@ -218,8 +210,8 @@ void FilterConfigProviderManagerImplBase::applyLastOrDefaultConfig(
if (subscription->lastConfig()) {
TRY_ASSERT_MAIN_THREAD {
provider.validateTypeUrl(subscription->lastTypeUrl());
provider.validateTerminalFilter(filter_config_name, subscription->lastFilterName(),
subscription->isLastFilterTerminal());
provider.validateMessage(filter_config_name, *subscription->lastConfig(),
subscription->lastFactoryName());
last_config_valid = true;
}
END_TRY catch (const EnvoyException& e) {
Expand All @@ -239,18 +231,16 @@ void FilterConfigProviderManagerImplBase::applyLastOrDefaultConfig(
}
}

std::tuple<ProtobufTypes::MessagePtr, std::string, bool>
HttpFilterConfigProviderManagerImpl::getMessage(
std::tuple<ProtobufTypes::MessagePtr, std::string> HttpFilterConfigProviderManagerImpl::getMessage(
const envoy::config::core::v3::TypedExtensionConfig& filter_config,
Server::Configuration::FactoryContext& factory_context) const {
Server::Configuration::ServerFactoryContext& factory_context) const {
auto& factory =
Config::Utility::getAndCheckFactory<Server::Configuration::NamedHttpFilterConfigFactory>(
filter_config);
ProtobufTypes::MessagePtr message = Config::Utility::translateAnyToFactoryConfig(
filter_config.typed_config(),
factory_context.messageValidationContext().dynamicValidationVisitor(), factory);
bool is_terminal_filter = factory.isTerminalFilterByProto(*message, factory_context);
return {std::move(message), factory.name(), is_terminal_filter};
return {std::move(message), factory.name()};
}

ProtobufTypes::MessagePtr HttpFilterConfigProviderManagerImpl::getDefaultConfig(
Expand All @@ -276,13 +266,5 @@ ProtobufTypes::MessagePtr HttpFilterConfigProviderManagerImpl::getDefaultConfig(
return message;
}

Http::FilterFactoryCb HttpFilterConfigProviderManagerImpl::instantiateFilterFactory(
const Protobuf::Message& message, const std::string& stat_prefix,
Server::Configuration::FactoryContext& factory_context) const {
auto* factory = Registry::FactoryRegistry<
Server::Configuration::NamedHttpFilterConfigFactory>::getFactoryByType(message.GetTypeName());
return factory->createFilterFactoryFromProto(message, stat_prefix, factory_context);
}

} // namespace Filter
} // namespace Envoy
Loading