aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/zenserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/zenserver.cpp')
-rw-r--r--src/zenserver/zenserver.cpp69
1 files changed, 57 insertions, 12 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 6bf22eef8..44fa01ea4 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -15,6 +15,7 @@
#include <zencore/logging.h>
#include <zencore/logging/broadcastsink.h>
#include <zencore/memory/fmalloc.h>
+#include <zencore/process.h>
#include <zencore/scopeguard.h>
#include <zencore/sentryintegration.h>
#include <zencore/session.h>
@@ -190,10 +191,10 @@ ZenServerBase::Initialize(const ZenServerConfig& ServerOptions, ZenServerState::
m_Http->RegisterService(m_StatsService);
m_StatsReporter.Initialize(ServerOptions.StatsConfig);
- if (ServerOptions.StatsConfig.Enabled)
- {
- EnqueueStatsReportingTimer();
- }
+ // Run the reporting timer unconditionally: even when statsd is disabled
+ // the StatsReporter still fans out to providers so counter trace points
+ // fire into the active .utrace stream (see TracingStatsMetrics).
+ EnqueueStatsReportingTimer();
// clang-format off
HealthServiceInfo HealthInfo {
@@ -232,7 +233,7 @@ ZenServerBase::Initialize(const ZenServerConfig& ServerOptions, ZenServerState::
LogSettingsSummary(ServerOptions);
- InitializeSessions();
+ InitializeSessions(ServerOptions.UseInProcSessionLogging);
return EffectiveBasePort;
}
@@ -265,7 +266,7 @@ ZenServerBase::ShutdownServices()
if (m_SessionsService)
{
- m_SessionsService->RemoveSession(GetSessionId());
+ m_SessionsService->RemoveSession(GetSessionId(), "server shutdown");
}
m_HttpSessionsService.reset();
@@ -279,15 +280,31 @@ ZenServerBase::ShutdownServices()
}
void
-ZenServerBase::InitializeSessions()
+ZenServerBase::InitializeSessions(bool UseInProcSessionLogging)
{
- m_SessionsService = std::make_unique<SessionsService>();
+ // Persist session metadata and logs under <DataRoot>/sessions. If no data
+ // root is configured (e.g. some test contexts) fall back to in-memory only.
+ std::filesystem::path SessionsRoot;
+ if (!m_DataRoot.empty())
+ {
+ SessionsRoot = m_DataRoot / "sessions";
+ }
+
+ m_SessionsService = std::make_unique<SessionsService>(std::move(SessionsRoot));
m_HttpSessionsService = std::make_unique<HttpSessionsService>(m_StatusService, m_StatsService, *m_SessionsService, m_IoContext);
m_HttpSessionsService->SetSelfSessionId(GetSessionId());
- m_InProcSessionLogSink = logging::SinkPtr(new InProcSessionLogSink(*m_SessionsService));
- m_InProcSessionLogSink->SetLevel(logging::Info);
- GetDefaultBroadcastSink()->AddSink(m_InProcSessionLogSink);
+ if (UseInProcSessionLogging)
+ {
+ // Create the sink up front but don't attach it to the broadcast
+ // yet — the self-session isn't registered with the service until
+ // StartSelfSession runs, and a sink that fires Log() before then
+ // silently drops every line because Service.AppendLog can't
+ // resolve the session id. The attach (with backlog replay) is
+ // performed once StartSelfSession has registered.
+ m_InProcSessionLogSink = logging::SinkPtr(new InProcSessionLogSink(*m_SessionsService));
+ m_InProcSessionLogSink->SetLevel(logging::Info);
+ }
}
void
@@ -295,7 +312,29 @@ ZenServerBase::StartSelfSession(std::string_view AppName)
{
if (m_SessionsService)
{
- m_SessionsService->RegisterSession(GetSessionId(), std::string(AppName), GetServerMode(), Oid::Zero, {});
+ m_SessionsService->RegisterSession(GetSessionId(),
+ std::string(AppName),
+ GetServerMode(),
+ std::string(GetRuntimePlatformName()),
+ // Report our own pid so it's visible in `zen sessions
+ // ls` and the dashboard. The liveness sweep will probe
+ // this entry and always find it alive — that's
+ // consistent (we're running iff the sweep is running)
+ // and the extra IsRunning check is cheap.
+ static_cast<uint32_t>(GetCurrentProcessId()),
+ GetParentSessionId(),
+ Oid::Zero,
+ {});
+
+ // Now that the self-session exists in the service, attach the
+ // in-proc sink and replay everything that was buffered into the
+ // log backlog up to this point. This brings every line emitted
+ // since process start into the self-session's persisted log,
+ // even though the session itself was only registered just now.
+ if (m_InProcSessionLogSink)
+ {
+ AttachSinkWithBacklogReplay(m_InProcSessionLogSink);
+ }
}
}
@@ -345,6 +384,12 @@ ZenServerBase::EnsureIoRunner()
void
ZenServerBase::OnReady()
{
+ // Bootstrap window is closed: every sink that's going to attach has
+ // attached, the run loop is up. Drop the captured early-startup
+ // backlog so it doesn't pin ~256KB of memory for the rest of the
+ // process. Subsequent log calls bypass the backlog cheaply.
+ DisableLogBacklog();
+
if (m_ServerEntry)
{
m_ServerEntry->SignalReady();