From: Michael Friedrich Date: Fri, 28 Sep 2018 09:26:47 +0000 (+0200) Subject: Improve logging and code quality X-Git-Tag: v2.11.0-rc1~59^2~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86108e6a1e74c0caca43587a4df818db23839912;p=icinga2 Improve logging and code quality --- diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp index 5508b1488..d5bb2cf1e 100644 --- a/lib/cli/daemonutility.cpp +++ b/lib/cli/daemonutility.cpp @@ -145,14 +145,14 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector& configs, if (!success) return false; - /* Load cluster synchronized configuration files. This can be disabled for staged sync validations. */ + /* Load cluster synchronized configuration files. This can be overridden for staged sync validations. */ String zonesVarDir = Configuration::DataDir + "/api/zones"; /* Cluster config sync stage validation needs this. */ if (systemNS->Contains("ZonesStageVarDir")) { zonesVarDir = systemNS->Get("ZonesStageVarDir"); - Log(LogInformation, "DaemonUtility") + Log(LogNotice, "DaemonUtility") << "Overriding zones var directory with '" << zonesVarDir << "' for cluster config sync staging."; } diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index f851153fe..4d8351572 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -342,7 +342,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D /* Spawn a validation process. On success, move the staged configuration * into production and restart. */ - AsyncTryActivateZonesStage(GetApiZonesStageDir(), GetApiZonesDir(), relativePaths, true); + AsyncTryActivateZonesStage(GetApiZonesStageDir(), GetApiZonesDir(), relativePaths); } return Empty; @@ -350,7 +350,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, const String& stageConfigDir, const String& currentConfigDir, - const std::vector& relativePaths, bool reload) + const std::vector& relativePaths) { String logFile = GetApiZonesStageDir() + "/startup.log"; std::ofstream fpLog(logFile.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc); @@ -365,12 +365,11 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, /* validation went fine, copy stage and reload */ if (pr.ExitStatus == 0) { Log(LogInformation, "ApiListener") - << "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, triggering reload."; + << "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, copying into '" << GetApiZonesDir() << "' and triggering reload."; for (const String& path : relativePaths) { - /* TODO: Better error handling with existing files. */ - Log(LogCritical, "ApiListener") - << "Copying file '" << path << "' from config sync staging to production directory."; + Log(LogNotice, "ApiListener") + << "Copying file '" << path << "' from config sync staging to production zones directory."; String stagePath = GetApiZonesStageDir() + path; String currentPath = GetApiZonesDir() + path; @@ -380,12 +379,11 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, Utility::CopyFile(stagePath, currentPath); } - if (reload) - Application::RequestRestart(); + Application::RequestRestart(); } else { Log(LogCritical, "ApiListener") - << "Config validation failed for staged cluster config sync. Aborting. Logs: '" - << logFile << "'"; + << "Config validation failed for staged cluster config sync in '" << GetApiZonesStageDir() + << "'. Aborting. Logs: '" << logFile << "'"; ApiListener::Ptr listener = ApiListener::GetInstance(); @@ -395,7 +393,7 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr, } void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir, - const std::vector& relativePaths, bool reload) + const std::vector& relativePaths) { VERIFY(Application::GetArgC() >= 1); @@ -419,7 +417,7 @@ void ApiListener::AsyncTryActivateZonesStage(const String& stageConfigDir, const Process::Ptr process = new Process(Process::PrepareCommand(args)); process->SetTimeout(300); - process->Run(std::bind(&TryActivateZonesStageCallback, _1, stageConfigDir, currentConfigDir, relativePaths, reload)); + process->Run(std::bind(&TryActivateZonesStageCallback, _1, stageConfigDir, currentConfigDir, relativePaths)); } void ApiListener::UpdateLastFailedZonesStageValidation(const String& log) diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index 757de7e87..3be03f96d 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -183,9 +183,9 @@ private: static void TryActivateZonesStageCallback(const ProcessResult& pr, const String& stageConfigDir, const String& currentConfigDir, - const std::vector& relativePaths, bool reload); + const std::vector& relativePaths); static void AsyncTryActivateZonesStage(const String& stageConfigDir, const String& currentConfigDir, - const std::vector& relativePaths, bool reload); + const std::vector& relativePaths); void UpdateLastFailedZonesStageValidation(const String& log);