Unify Application::GetStartTime() and drop GetMainTime()

This essentially moves the start time into the scope when main
starts to "do something", after the reload and configuration handling
is done.
This commit is contained in:
Michael Friedrich 2020-02-11 12:49:40 +01:00 committed by Alexander A. Klimov
parent 4878daff44
commit 18fdc1457a
6 changed files with 10 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

@ -51,7 +51,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;
@ -965,7 +964,7 @@ int Application::Run()
} }
#endif /* _WIN32 */ #endif /* _WIN32 */
SetMainTime(Utility::GetTime()); SetStartTime(Utility::GetTime());
return Main(); return Main();
} }
@ -1152,16 +1151,6 @@ void Application::SetStartTime(double ts)
m_StartTime = ts; m_StartTime = ts;
} }
double Application::GetMainTime()
{
return m_MainTime;
}
void Application::SetMainTime(double ts)
{
m_MainTime = ts;
}
double Application::GetUptime() double Application::GetUptime()
{ {
return Utility::GetTime() - m_StartTime; return Utility::GetTime() - m_StartTime;

View File

@ -95,9 +95,6 @@ public:
static double GetStartTime(); static double GetStartTime();
static void SetStartTime(double ts); static void SetStartTime(double ts);
static double GetMainTime();
static void SetMainTime(double ts);
static double GetUptime(); static double GetUptime();
static bool GetScriptDebuggerEnabled(); static bool GetScriptDebuggerEnabled();

View File

@ -563,6 +563,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

@ -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

@ -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(),