Skip to content
Open
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
4 changes: 4 additions & 0 deletions source/extensions/filters/http/lua/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Http::FilterFactoryCb LuaFilterConfig::createFilterFactoryFromProtoTyped(
Server::Configuration::FactoryContext& context) {
FilterConfigConstSharedPtr filter_config(new FilterConfig{
proto_config, context.threadLocal(), context.clusterManager(), context.api()});

// Setting up a watcher for LUA_PATHs
filter_config->addLuaPathWatchers(context);

return [filter_config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamFilter(std::make_shared<Filter>(filter_config));
};
Expand Down
22 changes: 21 additions & 1 deletion source/extensions/filters/http/lua/lua_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,30 @@ int StreamHandleWrapper::luaBase64Escape(lua_State* state) {
return 1;
}

void FilterConfig::addLuaPathWatchers(Server::Configuration::FactoryContext& context) {
// hardcoding path for the moment
std::string path = "/usr/local/share/lua/5.1/lib/";
watcher_ = context.dispatcher().createFilesystemWatcher();
watcher_->addWatch(path,
Filesystem::Watcher::Events::MovedTo |
Filesystem::Watcher::Events::Modified,
[path, &context, this](uint32_t) {
ENVOY_LOG(debug, "LUA path: {} is updated. Updating PerLuaCodeSetup", path);
if (per_lua_code_setups_map_[GLOBAL_SCRIPT_NAME]) {
auto global_setup_ptr = std::make_unique<PerLuaCodeSetup>(
proto_config_.inline_code(), context.threadLocal());
if (global_setup_ptr) {
per_lua_code_setups_map_[GLOBAL_SCRIPT_NAME].reset();
per_lua_code_setups_map_[GLOBAL_SCRIPT_NAME] = std::move(global_setup_ptr);
}
}
});
}

FilterConfig::FilterConfig(const envoy::extensions::filters::http::lua::v3::Lua& proto_config,
ThreadLocal::SlotAllocator& tls,
Upstream::ClusterManager& cluster_manager, Api::Api& api)
: cluster_manager_(cluster_manager) {
: cluster_manager_(cluster_manager), proto_config_(proto_config) {
auto global_setup_ptr = std::make_unique<PerLuaCodeSetup>(proto_config.inline_code(), tls);
if (global_setup_ptr) {
per_lua_code_setups_map_[GLOBAL_SCRIPT_NAME] = std::move(global_setup_ptr);
Expand Down
5 changes: 5 additions & 0 deletions source/extensions/filters/http/lua/lua_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,13 @@ class FilterConfig : Logger::Loggable<Logger::Id::lua> {

Upstream::ClusterManager& cluster_manager_;

// Adds filesystem watchers for LUA paths such as /usr/local/share/lua/5.1/
void addLuaPathWatchers(Server::Configuration::FactoryContext& context);

private:
absl::flat_hash_map<std::string, PerLuaCodeSetupPtr> per_lua_code_setups_map_;
std::unique_ptr<Filesystem::Watcher> watcher_;
const envoy::extensions::filters::http::lua::v3::Lua proto_config_;
};

using FilterConfigConstSharedPtr = std::shared_ptr<FilterConfig>;
Expand Down