Merge pull request #7823 from Icinga/bugfix/unify-application-start-times

Fix timing point for Application::GetStartTime() (related to command endpoint grace period)
This commit is contained in:
Noah Hilverling 2020-03-09 09:45:57 +01:00 committed by GitHub
commit 4c9e4959f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 18 additions and 20 deletions

View File

@ -166,8 +166,6 @@ static int Main()
argv += 3; argv += 3;
} }
Application::SetStartTime(Utility::GetTime());
/* Set thread title. */ /* Set thread title. */
Utility::SetThreadName("Main Thread", false); Utility::SetThreadName("Main Thread", false);

View File

@ -52,7 +52,6 @@ static bool l_InExceptionHandler = false;
int Application::m_ArgC; int Application::m_ArgC;
char **Application::m_ArgV; char **Application::m_ArgV;
double Application::m_StartTime; double Application::m_StartTime;
double Application::m_MainTime;
bool Application::m_ScriptDebuggerEnabled = false; bool Application::m_ScriptDebuggerEnabled = false;
double Application::m_LastReloadFailed; double Application::m_LastReloadFailed;
@ -967,7 +966,7 @@ int Application::Run()
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
SetMainTime(Utility::GetTime()); SetStartTime(Utility::GetTime());
return Main(); return Main();
} }
@ -1154,14 +1153,9 @@ void Application::SetStartTime(double ts)
m_StartTime = ts; m_StartTime = ts;
} }
double Application::GetMainTime() double Application::GetUptime()
{ {
return m_MainTime; return Utility::GetTime() - m_StartTime;
}
void Application::SetMainTime(double ts)
{
m_MainTime = ts;
} }
bool Application::GetScriptDebuggerEnabled() bool Application::GetScriptDebuggerEnabled()

View File

@ -95,8 +95,7 @@ public:
static double GetStartTime(); static double GetStartTime();
static void SetStartTime(double ts); static void SetStartTime(double ts);
static double GetMainTime(); static double GetUptime();
static void SetMainTime(double ts);
static bool GetScriptDebuggerEnabled(); static bool GetScriptDebuggerEnabled();
static void SetScriptDebuggerEnabled(bool enabled); static void SetScriptDebuggerEnabled(bool enabled);

View File

@ -588,6 +588,12 @@ void Checkable::ExecuteCheck()
* using the proper check interval once we've received a check result. * using the proper check interval once we've received a check result.
*/ */
SetNextCheck(Utility::GetTime() + GetCheckCommand()->GetTimeout() + 30); SetNextCheck(Utility::GetTime() + GetCheckCommand()->GetTimeout() + 30);
/*
* Let the user know that there was a problem with the check if
* 1) The endpoint is not syncing (replay log, etc.)
* 2) Outside of the cold startup window (5min)
*/
} else if (!endpoint->GetSyncing() && Application::GetInstance()->GetStartTime() < Utility::GetTime() - 300) { } else if (!endpoint->GetSyncing() && Application::GetInstance()->GetStartTime() < Utility::GetTime() - 300) {
/* fail to perform check on unconnected endpoint */ /* fail to perform check on unconnected endpoint */
cr->SetState(ServiceUnknown); cr->SetState(ServiceUnknown);

View File

@ -194,6 +194,7 @@ Timestamp Checkable::GetNextUpdate() const
auto cr (GetLastCheckResult()); auto cr (GetLastCheckResult());
double interval, latency; double interval, latency;
// TODO: Document this behavior.
if (cr) { if (cr) {
interval = GetEnableActiveChecks() && GetProblem() && GetStateType() == StateTypeSoft ? GetRetryInterval() : GetCheckInterval(); interval = GetEnableActiveChecks() && GetProblem() && GetStateType() == StateTypeSoft ? GetRetryInterval() : GetCheckInterval();
latency = cr->GetExecutionEnd() - cr->GetScheduleStart(); latency = cr->GetExecutionEnd() - cr->GetScheduleStart();
@ -202,7 +203,7 @@ Timestamp Checkable::GetNextUpdate() const
latency = 0.0; latency = 0.0;
} }
return (GetEnableActiveChecks() ? GetNextCheck() : (cr ? cr->GetExecutionEnd() : Application::GetMainTime()) + interval) + interval + 2 * latency; return (GetEnableActiveChecks() ? GetNextCheck() : (cr ? cr->GetExecutionEnd() : Application::GetStartTime()) + interval) + interval + 2 * latency;
} }
void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime) void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime)

View File

@ -329,7 +329,7 @@ void CIB::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) {
status->Set("num_services_handled", ss.services_handled); status->Set("num_services_handled", ss.services_handled);
status->Set("num_services_problem", ss.services_problem); status->Set("num_services_problem", ss.services_problem);
double uptime = Utility::GetTime() - Application::GetStartTime(); double uptime = Application::GetUptime();
status->Set("uptime", uptime); status->Set("uptime", uptime);
HostStatistics hs = CalculateHostStats(); HostStatistics hs = CalculateHostStats();

View File

@ -206,7 +206,7 @@ bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr
*result = Utility::FormatDateTime("%H:%M:%S %z", now); *result = Utility::FormatDateTime("%H:%M:%S %z", now);
return true; return true;
} else if (macro == "uptime") { } else if (macro == "uptime") {
*result = Utility::FormatDuration(Utility::GetTime() - Application::GetStartTime()); *result = Utility::FormatDuration(Application::GetUptime());
return true; return true;
} }

View File

@ -102,7 +102,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
perfdata->Add(new PerfdataValue("num_services_handled", ss.services_handled)); perfdata->Add(new PerfdataValue("num_services_handled", ss.services_handled));
perfdata->Add(new PerfdataValue("num_services_problem", ss.services_problem)); perfdata->Add(new PerfdataValue("num_services_problem", ss.services_problem));
double uptime = Utility::GetTime() - Application::GetStartTime(); double uptime = Application::GetUptime();
perfdata->Add(new PerfdataValue("uptime", uptime)); perfdata->Add(new PerfdataValue("uptime", uptime));
HostStatistics hs = CIB::CalculateHostStats(); HostStatistics hs = CIB::CalculateHostStats();

View File

@ -25,7 +25,7 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
return; return;
double now = Utility::GetTime(); double now = Utility::GetTime();
double uptime = now - Application::GetStartTime(); double uptime = Application::GetUptime();
String output = "Hello from " + IcingaApplication::GetInstance()->GetNodeName() String output = "Hello from " + IcingaApplication::GetInstance()->GetNodeName()
+ ". Icinga 2 has been running for " + Utility::FormatDuration(uptime) + ". Icinga 2 has been running for " + Utility::FormatDuration(uptime)

View File

@ -40,10 +40,10 @@ void ApiListener::UpdateObjectAuthority()
endpoints.push_back(endpoint); endpoints.push_back(endpoint);
} }
double mainTime = Application::GetMainTime(); double startTime = Application::GetStartTime();
/* 30 seconds cold startup, don't update any authority to give the secondary endpoint time to reconnect. */ /* 30 seconds cold startup, don't update any authority to give the secondary endpoint time to reconnect. */
if (num_total > 1 && endpoints.size() <= 1 && (mainTime == 0 || Utility::GetTime() - mainTime < 30)) if (num_total > 1 && endpoints.size() <= 1 && (startTime == 0 || Utility::GetTime() - startTime < 30))
return; return;
std::sort(endpoints.begin(), endpoints.end(), std::sort(endpoints.begin(), endpoints.end(),