diff options
| author | Stefan Boberg <[email protected]> | 2026-03-09 17:43:08 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-09 17:43:08 +0100 |
| commit | b37b34ea6ad906f54e8104526e77ba66aed997da (patch) | |
| tree | e80ce17d666aff6d2f0d73d4977128ffb4055476 /src/zenserver/sessions/sessions.cpp | |
| parent | add fallback for zencache multirange (#816) (diff) | |
| download | zen-b37b34ea6ad906f54e8104526e77ba66aed997da.tar.xz zen-b37b34ea6ad906f54e8104526e77ba66aed997da.zip | |
Dashboard overhaul, compute integration (#814)
- **Frontend dashboard overhaul**: Unified compute/main dashboards into a single shared UI. Added new pages for cache, projects, metrics, sessions, info (build/runtime config, system stats). Added live-update via WebSockets with pause control, sortable detail tables, themed styling. Refactored compute/hub/orchestrator pages into modular JS.
- **HTTP server fixes and stats**: Fixed http.sys local-only fallback when default port is in use, implemented root endpoint redirect for http.sys, fixed Linux/Mac port reuse. Added /stats endpoint exposing HTTP server metrics (bytes transferred, request rates). Added WebSocket stats tracking.
- **OTEL/diagnostics hardening**: Improved OTLP HTTP exporter with better error handling and resilience. Extended diagnostics services configuration.
- **Session management**: Added new sessions service with HTTP endpoints for registering, updating, querying, and removing sessions. Includes session log file support. This is still WIP.
- **CLI subcommand support**: Added support for commands with subcommands in the zen CLI tool, with improved command dispatch.
- **Misc**: Exposed CPU usage/hostname to frontend, fixed JS compact binary float32/float64 decoding, limited projects displayed on front page to 25 sorted by last access, added vscode:// link support.
Also contains some fixes from TSAN analysis.
Diffstat (limited to 'src/zenserver/sessions/sessions.cpp')
| -rw-r--r-- | src/zenserver/sessions/sessions.cpp | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/src/zenserver/sessions/sessions.cpp b/src/zenserver/sessions/sessions.cpp new file mode 100644 index 000000000..f73aa40ff --- /dev/null +++ b/src/zenserver/sessions/sessions.cpp @@ -0,0 +1,150 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "sessions.h" + +#include <zencore/basicfile.h> +#include <zencore/fmtutils.h> +#include <zencore/logging.h> + +namespace zen { +using namespace std::literals; + +class SessionLog : public TRefCounted<SessionLog> +{ +public: + SessionLog(std::filesystem::path LogFilePath) { m_LogFile.Open(LogFilePath, BasicFile::Mode::kWrite); } + +private: + BasicFile m_LogFile; +}; + +class SessionLogStore +{ +public: + SessionLogStore(std::filesystem::path StoragePath) : m_StoragePath(std::move(StoragePath)) {} + + ~SessionLogStore() = default; + + Ref<SessionLog> GetLogForSession(const Oid& SessionId) + { + // For now, just return a new log for each session. We can implement actual log storage and retrieval later. + return Ref(new SessionLog(m_StoragePath / (SessionId.ToString() + ".log"))); + } + + Ref<SessionLog> CreateLogForSession(const Oid& SessionId) + { + // For now, just return a new log for each session. We can implement actual log storage and retrieval later. + return Ref(new SessionLog(m_StoragePath / (SessionId.ToString() + ".log"))); + } + +private: + std::filesystem::path m_StoragePath; +}; + +SessionsService::Session::Session(const SessionInfo& Info) : m_Info(Info) +{ +} +SessionsService::Session::~Session() = default; + +////////////////////////////////////////////////////////////////////////// + +SessionsService::SessionsService() : m_Log(logging::Get("sessions")) +{ +} + +SessionsService::~SessionsService() = default; + +bool +SessionsService::RegisterSession(const Oid& SessionId, std::string AppName, const Oid& JobId, CbObjectView Metadata) +{ + RwLock::ExclusiveLockScope Lock(m_Lock); + + if (m_Sessions.contains(SessionId)) + { + return false; + } + + const DateTime Now = DateTime::Now(); + m_Sessions.emplace(SessionId, + Ref(new Session(SessionInfo{.Id = SessionId, + .AppName = std::move(AppName), + .JobId = JobId, + .Metadata = CbObject::Clone(Metadata), + .CreatedAt = Now, + .UpdatedAt = Now}))); + + ZEN_INFO("Session {} registered (AppName: {}, JobId: {})", SessionId, AppName, JobId); + return true; +} + +bool +SessionsService::UpdateSession(const Oid& SessionId, CbObjectView Metadata) +{ + RwLock::ExclusiveLockScope Lock(m_Lock); + + auto It = m_Sessions.find(SessionId); + if (It == m_Sessions.end()) + { + return false; + } + + It.value()->UpdateMetadata(Metadata); + + const SessionInfo& Info = It.value()->Info(); + ZEN_DEBUG("Session {} updated (AppName: {}, JobId: {})", SessionId, Info.AppName, Info.JobId); + return true; +} + +Ref<SessionsService::Session> +SessionsService::GetSession(const Oid& SessionId) const +{ + RwLock::SharedLockScope Lock(m_Lock); + + auto It = m_Sessions.find(SessionId); + if (It == m_Sessions.end()) + { + return {}; + } + + return It->second; +} + +std::vector<Ref<SessionsService::Session>> +SessionsService::GetSessions() const +{ + RwLock::SharedLockScope Lock(m_Lock); + + std::vector<Ref<Session>> Result; + Result.reserve(m_Sessions.size()); + for (const auto& [Id, SessionRef] : m_Sessions) + { + Result.push_back(SessionRef); + } + return Result; +} + +bool +SessionsService::RemoveSession(const Oid& SessionId) +{ + RwLock::ExclusiveLockScope Lock(m_Lock); + + auto It = m_Sessions.find(SessionId); + if (It == m_Sessions.end()) + { + return false; + } + + ZEN_INFO("Session {} removed (AppName: {}, JobId: {})", SessionId, It.value()->Info().AppName, It.value()->Info().JobId); + + m_Sessions.erase(It); + return true; +} + +uint64_t +SessionsService::GetSessionCount() const +{ + RwLock::SharedLockScope Lock(m_Lock); + return m_Sessions.size(); +} + +} // namespace zen |