Enhace logging when config change yes/no will trigger further reload actions

This commit is contained in:
Michael Friedrich 2018-10-26 14:20:27 +02:00
parent c230e503e6
commit a6ddef17d9

View File

@ -257,7 +257,9 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
<< "Applying config update from endpoint '" << fromEndpointName << "Applying config update from endpoint '" << fromEndpointName
<< "' of zone '" << fromZoneName << "'."; << "' of zone '" << fromZoneName << "'.";
/* Config files. */
Dictionary::Ptr updateV1 = params->Get("update"); Dictionary::Ptr updateV1 = params->Get("update");
/* Meta data files: .timestamp, etc. */
Dictionary::Ptr updateV2 = params->Get("update_v2"); Dictionary::Ptr updateV2 = params->Get("update_v2");
/* New since 2.11.0. */ /* New since 2.11.0. */
@ -267,11 +269,15 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
checksums = params->Get("checksums"); checksums = params->Get("checksums");
bool configChange = false; bool configChange = false;
/* Keep track of the relative config paths for later validation and copying. */
std::vector<String> relativePaths; std::vector<String> relativePaths;
/* /*
* We can and must safely purge the staging directory, as the difference is taken between * We can and must safely purge the staging directory, as the difference is taken between
* runtime production config and newly received configuration. * runtime production config and newly received configuration.
* This is needed to not mix deleted/changed content between received and stage
* config.
*/ */
if (Utility::PathExists(apiZonesStageDir)) if (Utility::PathExists(apiZonesStageDir))
Utility::RemoveDirRecursive(apiZonesStageDir); Utility::RemoveDirRecursive(apiZonesStageDir);
@ -316,7 +322,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
if (updateV2) if (updateV2)
newConfigInfo.UpdateV2 = updateV2->Get(kv.first); newConfigInfo.UpdateV2 = updateV2->Get(kv.first);
/* Load checksums. */ /* Load checksums. New since 2.11. */
if (checksums) if (checksums)
newConfigInfo.Checksums = checksums->Get(kv.first); newConfigInfo.Checksums = checksums->Get(kv.first);
@ -327,14 +333,14 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
Dictionary::Ptr newConfig = MergeConfigUpdate(newConfigInfo); Dictionary::Ptr newConfig = MergeConfigUpdate(newConfigInfo);
/* If we have received 'checksums' via cluster message, go for it. /* If we have received 'checksums' via cluster message, go for it.
* Otherwise do the old timestamp dance. * Otherwise do the old timestamp dance for versions < 2.11.
*/ */
if (checksums) { if (checksums) {
/* Calculate and compare the checksums. */ /* Calculate and compare the checksums. */
String productionConfigChecksum = GetGlobalChecksum(productionConfigInfo); String productionConfigChecksum = GetGlobalChecksum(productionConfigInfo);
String newConfigChecksum = GetGlobalChecksum(newConfigInfo); String newConfigChecksum = GetGlobalChecksum(newConfigInfo);
Log(LogWarning, "ApiListener") Log(LogInformation, "ApiListener")
<< "Received configuration for zone '" << zoneName << "' from endpoint '" << "Received configuration for zone '" << zoneName << "' from endpoint '"
<< fromEndpointName << "' with checksum '" << newConfigChecksum << "'." << fromEndpointName << "' with checksum '" << newConfigChecksum << "'."
<< " Our production configuration has checksum '" << productionConfigChecksum << "'."; << " Our production configuration has checksum '" << productionConfigChecksum << "'.";
@ -343,7 +349,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
if (newConfigChecksum != productionConfigChecksum) if (newConfigChecksum != productionConfigChecksum)
configChange = true; configChange = true;
} else { } else {
/* TODO: Figure out whether we always need to rely on the timestamp flags. */ /* TODO: Figure out whether we always need to rely on the timestamp flags when there are checksums involved. */
double productionTimestamp; double productionTimestamp;
if (!productionConfig->Contains("/.timestamp")) if (!productionConfig->Contains("/.timestamp"))
@ -440,11 +446,22 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
} }
} }
if (configChange) { /*
/* Spawn a validation process. On success, move the staged configuration * We have processed all configuration files and stored them in the staging directory.
* into production and restart. * We need to store them locally for later analysis. A config change means
* that we will validate the configuration in a separate process sandbox,
* and only copy the configuration to production when everything is ok.
* A successful validation also triggers the final restart.
*/ */
if (configChange) {
Log(LogInformation, "ApiListener")
<< "Received configuration from endpoint '" << fromEndpointName
<< "' is different to production, triggering validation and reload.";
AsyncTryActivateZonesStage(relativePaths); AsyncTryActivateZonesStage(relativePaths);
} else {
Log(LogInformation, "ApiListener")
<< "Received configuration from endpoint '" << fromEndpointName
<< "' is equal to production, not triggering reload.";
} }
return Empty; return Empty;