-
Notifications
You must be signed in to change notification settings - Fork 980
rec: handle applicable dynamic parts of YAML only config when reloading Lua config #16709
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
Open
omoerbeek
wants to merge
5
commits into
PowerDNS:master
Choose a base branch
from
omoerbeek:rec-lua-yaml-conf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2fc454f
rec: handle applicable dynamic parts of YAML only config when reloadi…
omoerbeek 961024a
Refactor common part
omoerbeek a147af6
Refactor tests to use available recControl() method
omoerbeek 532eb5e
Test with reloading forward and TLS config
omoerbeek 1580eb6
Fix rebase conflict and a case where we don't have a Lua config at all
omoerbeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2075,32 +2075,69 @@ static RecursorControlChannel::Answer help(ArgIterator /* begin */, ArgIterator | |||||
| return {0, str.str()}; | ||||||
| } | ||||||
|
|
||||||
| // The common part of activating the newly read config | ||||||
| static void activateLua(LuaConfigItems& lci, bool broadcast, ProxyMapping&& proxyMapping, OpenTelemetryTraceConditions&& conditions) | ||||||
| { | ||||||
| extern std::unique_ptr<ProxyMapping> g_proxyMapping; | ||||||
|
|
||||||
| activateLuaConfig(lci); | ||||||
| lci = g_luaconfs.getCopy(); | ||||||
| if (broadcast) { | ||||||
| startLuaConfigDelayedThreads(lci, lci.generation); | ||||||
| broadcastFunction([pmap = std::move(proxyMapping)] { return pleaseSupplantProxyMapping(pmap); }); | ||||||
| broadcastFunction([conds = std::move(conditions)] { return pleaseSupplantOTConditions(conds); }); | ||||||
| } | ||||||
| else { | ||||||
| // Initial proxy mapping and OT conditions | ||||||
| g_proxyMapping = proxyMapping.empty() ? nullptr : std::make_unique<ProxyMapping>(proxyMapping); | ||||||
| *g_initialOpenTelemetryConditions.lock() = conditions.empty() ? nullptr : std::make_unique<OpenTelemetryTraceConditions>(conditions); | ||||||
| } | ||||||
| if (broadcast) { | ||||||
| g_slog->withName("config")->info(Logr::Info, "Reloaded"); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| RecursorControlChannel::Answer luaconfig(bool broadcast) | ||||||
| { | ||||||
| ProxyMapping proxyMapping; | ||||||
| LuaConfigItems lci; | ||||||
| lci.d_slog = g_slog; | ||||||
| extern std::unique_ptr<ProxyMapping> g_proxyMapping; | ||||||
| pdns::rust::settings::rec::Recursorsettings settings; | ||||||
| OpenTelemetryTraceConditions conditions; | ||||||
| pdns::settings::rec::YamlSettingsStatus yamlstat = pdns::settings::rec::YamlSettingsStatus::CannotOpen; | ||||||
|
|
||||||
| // If we have a YAML file read it to be able to use (parts of it) later | ||||||
| if (g_yamlSettings) { | ||||||
| string configname = ::arg()["config-dir"] + "/recursor"; | ||||||
| if (!::arg()["config-name"].empty()) { | ||||||
| configname = ::arg()["config-dir"] + "/recursor-" + ::arg()["config-name"]; | ||||||
| } | ||||||
| bool dummy1{}; | ||||||
| bool dummy2{}; | ||||||
| yamlstat = pdns::settings::rec::tryReadYAML(configname + g_yamlSettingsSuffix, false, dummy1, dummy2, settings, g_slog, Logr::Error); | ||||||
| } | ||||||
|
|
||||||
| if (!g_luaSettingsInYAML) { | ||||||
| // We might have a lua config file, but also process dynamic YAML parts if applicable, currently those are: | ||||||
| // - the OT trace conditions | ||||||
| // - the outgoing TLS config | ||||||
| try { | ||||||
| if (::arg()["lua-config-file"].empty()) { | ||||||
| return {0, "No Lua or corresponding YAML configuration active\n"}; | ||||||
| if (yamlstat == pdns::settings::rec::YamlSettingsStatus::OK) { | ||||||
| // YAML read above succeeded | ||||||
| ProxyMapping dummyProxyMapping; // taken from lua, so ignore YAML | ||||||
| LuaConfigItems dummyLuaConfig; // we do not use the converted orm YAML LuaConfigItems, but the "real thing" | ||||||
| pdns::settings::rec::fromBridgeStructToLuaConfig(settings, dummyLuaConfig, dummyProxyMapping, conditions); | ||||||
| TCPOutConnectionManager::setupOutgoingTLSConfigTables(settings); | ||||||
| } | ||||||
| loadRecursorLuaConfig(::arg()["lua-config-file"], proxyMapping, lci); | ||||||
| activateLuaConfig(lci); | ||||||
| lci = g_luaconfs.getCopy(); | ||||||
| if (broadcast) { | ||||||
| startLuaConfigDelayedThreads(lci, lci.generation); | ||||||
| broadcastFunction([pmap = std::move(proxyMapping)] { return pleaseSupplantProxyMapping(pmap); }); | ||||||
| if (!::arg()["lua-config-file"].empty()) { | ||||||
| loadRecursorLuaConfig(::arg()["lua-config-file"], proxyMapping, lci); // will bump generation | ||||||
| } | ||||||
| else { | ||||||
| // Initial proxy mapping | ||||||
| g_proxyMapping = proxyMapping.empty() ? nullptr : std::make_unique<ProxyMapping>(proxyMapping); | ||||||
| } | ||||||
| if (broadcast) { | ||||||
| g_slog->withName("config")->info(Logr::Info, "Reloaded"); | ||||||
| activateLua(lci, broadcast, std::move(proxyMapping), std::move(conditions)); | ||||||
| string msg = "Reloaded dynamic parts of YAML config"; | ||||||
|
Member
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.
Suggested change
for consistency. |
||||||
| if (!::arg()["lua-config-file"].empty()) { | ||||||
| msg += " and Lua configuration file '" + ::arg()["lua-config-file"] + "'"; | ||||||
| } | ||||||
| return {0, "Reloaded Lua configuration file '" + ::arg()["lua-config-file"] + "'\n"}; | ||||||
| return {0, msg + "\n"}; | ||||||
| } | ||||||
| catch (std::exception& e) { | ||||||
| return {1, "Unable to load Lua script from '" + ::arg()["lua-config-file"] + "': " + e.what() + "\n"}; | ||||||
|
|
@@ -2109,36 +2146,15 @@ RecursorControlChannel::Answer luaconfig(bool broadcast) | |||||
| return {1, "Unable to load Lua script from '" + ::arg()["lua-config-file"] + "': " + e.reason + "\n"}; | ||||||
| } | ||||||
| } | ||||||
| // More simple case: we don't have any Lua config | ||||||
| try { | ||||||
| string configname = ::arg()["config-dir"] + "/recursor"; | ||||||
| if (!::arg()["config-name"].empty()) { | ||||||
| configname = ::arg()["config-dir"] + "/recursor-" + ::arg()["config-name"]; | ||||||
| } | ||||||
| bool dummy1{}; | ||||||
| bool dummy2{}; | ||||||
| pdns::rust::settings::rec::Recursorsettings settings; | ||||||
| auto yamlstat = pdns::settings::rec::tryReadYAML(configname + g_yamlSettingsSuffix, false, dummy1, dummy2, settings, g_slog, Logr::Error); | ||||||
| if (yamlstat != pdns::settings::rec::YamlSettingsStatus::OK) { | ||||||
| return {1, "Reloading dynamic part of YAML configuration failed\n"}; | ||||||
| } | ||||||
| auto generation = g_luaconfs.getLocal()->generation; | ||||||
| lci.generation = generation + 1; | ||||||
| OpenTelemetryTraceConditions conditions; | ||||||
| pdns::settings::rec::fromBridgeStructToLuaConfig(settings, lci, proxyMapping, conditions); | ||||||
| activateLuaConfig(lci); | ||||||
| lci = g_luaconfs.getCopy(); | ||||||
| if (broadcast) { | ||||||
| startLuaConfigDelayedThreads(lci, lci.generation); | ||||||
|
|
||||||
| *g_initialOpenTelemetryConditions.lock() = conditions.empty() ? nullptr : std::make_unique<OpenTelemetryTraceConditions>(conditions); | ||||||
| broadcastFunction([pmap = std::move(proxyMapping)] { return pleaseSupplantProxyMapping(pmap); }); | ||||||
| broadcastFunction([conds = std::move(conditions)] { return pleaseSupplantOTConditions(conds); }); | ||||||
| } | ||||||
| else { | ||||||
| // Initial proxy mapping | ||||||
| g_proxyMapping = proxyMapping.empty() ? nullptr : std::make_unique<ProxyMapping>(proxyMapping); | ||||||
| *g_initialOpenTelemetryConditions.lock() = conditions.empty() ? nullptr : std::make_unique<OpenTelemetryTraceConditions>(conditions); | ||||||
| } | ||||||
| activateLua(lci, broadcast, std::move(proxyMapping), std::move(conditions)); | ||||||
| TCPOutConnectionManager::setupOutgoingTLSConfigTables(settings); | ||||||
|
|
||||||
| return {0, "Reloaded dynamic part of YAML configuration\n"}; | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.