Enhance client connect/sync logging and include bytes/zone in logs

refs #5513
This commit is contained in:
Michael Friedrich 2017-08-21 11:08:13 +02:00
parent 522eea1863
commit 873a553a4f
2 changed files with 48 additions and 17 deletions

View File

@ -109,13 +109,7 @@ bool ApiListener::UpdateConfigDir(const ConfigDirInformation& oldConfigInfo, con
return false; return false;
} }
Log(LogInformation, "ApiListener") size_t numBytes = 0;
<< "Applying configuration file update for path '" << configDir << "'. Received timestamp '"
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", newTimestamp) << "' ("
<< std::fixed << std::setprecision(6) << newTimestamp
<< ") is more recent than current timestamp '"
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", oldTimestamp) << "' ("
<< oldTimestamp << ").";
{ {
ObjectLock olock(newConfig); ObjectLock olock(newConfig);
@ -128,15 +122,28 @@ bool ApiListener::UpdateConfigDir(const ConfigDirInformation& oldConfigInfo, con
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Updating configuration file: " << path; << "Updating configuration file: " << path;
//pass the directory and generate a dir tree, if not existing already /* Sync string content only. */
String content = kv.second;
/* Generate a directory tree (zones/1/2/3 might not exist yet). */
Utility::MkDirP(Utility::DirName(path), 0755); Utility::MkDirP(Utility::DirName(path), 0755);
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc); std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
fp << kv.second; fp << content;
fp.close(); fp.close();
numBytes += content.GetLength();
} }
} }
} }
Log(LogInformation, "ApiListener")
<< "Applying configuration file update for path '" << configDir << "' (" << numBytes << " Bytes). Received timestamp '"
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", newTimestamp) << "' ("
<< std::fixed << std::setprecision(6) << newTimestamp
<< "), Current timestamp '"
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", oldTimestamp) << "' ("
<< oldTimestamp << ").";
ObjectLock xlock(oldConfig); ObjectLock xlock(oldConfig);
for (const Dictionary::Pair& kv : oldConfig) { for (const Dictionary::Pair& kv : oldConfig) {
if (!newConfig->Contains(kv.first)) { if (!newConfig->Contains(kv.first)) {

View File

@ -294,7 +294,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
String port = endpoint->GetPort(); String port = endpoint->GetPort();
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Reconnecting to API endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "'"; << "Reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "'";
TcpSocket::Ptr client = new TcpSocket(); TcpSocket::Ptr client = new TcpSocket();
@ -313,6 +313,9 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
Log(LogDebug, "ApiListener") Log(LogDebug, "ApiListener")
<< info.str() << "\n" << DiagnosticInformation(ex); << info.str() << "\n" << DiagnosticInformation(ex);
} }
Log(LogInformation, "ApiListener")
<< "Finished reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "'";
} }
void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role) void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& hostname, ConnectionRole role)
@ -321,6 +324,9 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, const String& host
NewClientHandlerInternal(client, hostname, role); NewClientHandlerInternal(client, hostname, role);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Log(LogCritical, "ApiListener") Log(LogCritical, "ApiListener")
<< "Exception while handling new API client connection: " << DiagnosticInformation(ex, false);
Log(LogDebug, "ApiListener")
<< "Exception while handling new API client connection: " << DiagnosticInformation(ex); << "Exception while handling new API client connection: " << DiagnosticInformation(ex);
} }
} }
@ -463,6 +469,8 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync) void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync)
{ {
Zone::Ptr eZone = endpoint->GetZone();
try { try {
{ {
ObjectLock olock(endpoint); ObjectLock olock(endpoint);
@ -475,15 +483,19 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
*/ */
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Sending config updates for endpoint '" << endpoint->GetName() << "'."; << "Sending config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
/* sync zone file config */ /* sync zone file config */
SendConfigUpdate(aclient); SendConfigUpdate(aclient);
Log(LogInformation, "ApiListener")
<< "Finished sending config file updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
/* sync runtime config */ /* sync runtime config */
SendRuntimeConfigObjects(aclient); SendRuntimeConfigObjects(aclient);
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Finished sending config updates for endpoint '" << endpoint->GetName() << "'."; << "Finished sending runtime config updates for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
if (!needSync) { if (!needSync) {
ObjectLock olock2(endpoint); ObjectLock olock2(endpoint);
@ -492,22 +504,30 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
} }
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Sending replay log for endpoint '" << endpoint->GetName() << "'."; << "Sending replay log for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
ReplayLog(aclient); ReplayLog(aclient);
if (endpoint->GetZone() == Zone::GetLocalZone()) if (eZone == Zone::GetLocalZone())
UpdateObjectAuthority(); UpdateObjectAuthority();
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Finished sending replay log for endpoint '" << endpoint->GetName() << "'."; << "Finished sending replay log for endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
ObjectLock olock2(endpoint); {
endpoint->SetSyncing(false); ObjectLock olock2(endpoint);
endpoint->SetSyncing(false);
}
Log(LogCritical, "ApiListener") Log(LogCritical, "ApiListener")
<< "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex, false);
Log(LogDebug, "ApiListener")
<< "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex); << "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
} }
Log(LogInformation, "ApiListener")
<< "Finished syncing endpoint '" << endpoint->GetName() << "' in zone '" << eZone->GetName() << "'.";
} }
void ApiListener::ApiTimerHandler(void) void ApiListener::ApiTimerHandler(void)
@ -1011,7 +1031,11 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
count++; count++;
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Log(LogWarning, "ApiListener") Log(LogWarning, "ApiListener")
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex, false);
Log(LogDebug, "ApiListener")
<< "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex); << "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
break; break;
} }