diff options
| author | Stefan Boberg <[email protected]> | 2026-03-23 14:19:57 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-23 14:19:57 +0100 |
| commit | 2a445406e09328cb4cf320300f2678997d6775b7 (patch) | |
| tree | a92f02d94c92144cb6ae32160397298533e4c822 /src/zenserver/storage/zenstorageserver.cpp | |
| parent | add hub instance crash recovery (#885) (diff) | |
| download | zen-2a445406e09328cb4cf320300f2678997d6775b7.tar.xz zen-2a445406e09328cb4cf320300f2678997d6775b7.zip | |
Dashboard refresh (logs, storage, network, object store, docs) (#835)
## Summary
This PR adds a session management service, several new dashboard pages, and a number of infrastructure improvements.
### Sessions Service
- `SessionsServiceClient` in `zenutil` announces sessions to a remote zenserver with a 15s heartbeat (POST/PUT/DELETE lifecycle)
- Storage server registers itself with its own local sessions service on startup
- Session mode attribute coupled to server mode (Compute, Proxy, Hub, etc.)
- Ended sessions tracked with `ended_at` timestamp; status filtering (Active/Ended/All)
- `--sessions-url` config option for remote session announcement
- In-process log sink (`InProcSessionLogSink`) forwards server log output to the server's own session, visible in the dashboard
### Session Log Viewer
- POST/GET endpoints for session logs (`/sessions/{id}/log`) supporting raw text and structured JSON/CbObject with batch `entries` array
- In-memory log storage per session (capped at 10k entries) with cursor-based pagination for efficient incremental fetching
- Log panel in the sessions dashboard with incremental DOM updates, auto-scroll (Follow toggle), newest-first toggle, text filter, and log-level coloring
- Auto-selects the server's own session on page load
### TCP Log Streaming
- `LogStreamListener` and `TcpLogStreamSink` for log delivery over TCP
- Sequence numbers on each message with drop detection and synthetic "dropped" notice on gaps
- Gathered buffer writes to reduce syscall overhead when flushing batches
- Tests covering basic delivery, multi-line splitting, drop detection, and sequencing
### New Dashboard Pages
- **Sessions**: master-detail layout with selectable rows, metadata panel, live WebSocket updates, paging, abbreviated date formatting, and "this" pill for the local session
- **Object Store**: summary stats tiles and bucket table with click-to-expand inline object listing (`GET /obj/`)
- **Storage**: per-volume disk usage breakdown (`GET /admin/storage`), Garbage Collection status section (next-run countdown, last-run stats), and GC History table with paginated rows and expandable detail panels
- **Network**: overview tiles, per-service request table, proxy connections, and live WebSocket updates; distinct client IPs and session counts via HyperLogLog
### Documentation Page
- In-dashboard Docs page with sidebar navigation, markdown rendering (via `marked`), Mermaid diagram support (theme-aware), collapsible sections, text filtering with highlighting, and cross-document linking
- New user-facing docs: `overview.md` (with architecture and per-mode diagrams), `sessions.md`, `cache.md`, `projects.md`; updated `compute.md`
- Dev docs moved to `docs/dev/`
### Infrastructure & Bug Fixes
- **Deflate compression** for the embedded frontend zip (~3.4MB → ~950KB); zlib inflate support added to `ZipFs` with cached decompressed buffers
- **Local IP addresses**: `GetLocalIpAddresses()` (Windows via `GetAdaptersAddresses`, Linux/Mac via `getifaddrs`); surfaced in `/status/status`, `/health/info`, and the dashboard banner
- **Dashboard nav**: unified into `zen-nav` web component with `MutationObserver` for dynamically added links, CSS `::part()` to merge banner/nav border radii, and prefix-based active link detection
- Stats broadcast refactored from manual JSON string concatenation to `CbObjectWriter`; `CbObject`-to-JS conversion improved for `TimeSpan`, `DateTime`, and large integers
- Stats WebSocket boilerplate consolidated into `ZenPage.connect_stats_ws()`
Diffstat (limited to 'src/zenserver/storage/zenstorageserver.cpp')
| -rw-r--r-- | src/zenserver/storage/zenstorageserver.cpp | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/src/zenserver/storage/zenstorageserver.cpp b/src/zenserver/storage/zenstorageserver.cpp index 68d722f60..de00eb1c2 100644 --- a/src/zenserver/storage/zenstorageserver.cpp +++ b/src/zenserver/storage/zenstorageserver.cpp @@ -34,9 +34,11 @@ #include <zentelemetry/otlptrace.h> #include <zenutil/logging.h> #include <zenutil/service.h> +#include <zenutil/sessionsclient.h> #include <zenutil/workerpools.h> #include <zenutil/zenserverprocess.h> -#include "../sessions/sessions.h" +#include "sessions/inprocsessionlogsink.h" +#include "sessions/sessions.h" #if ZEN_PLATFORM_WINDOWS # include <zencore/windows.h> @@ -251,7 +253,22 @@ ZenStorageServer::InitializeServices(const ZenStorageServerConfig& ServerOptions { m_SessionsService = std::make_unique<SessionsService>(); - m_HttpSessionsService = std::make_unique<HttpSessionsService>(m_StatusService, m_StatsService, *m_SessionsService); + 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 (!ServerOptions.SessionsTargetUrl.empty()) + { + m_SessionsClient = std::make_unique<SessionsServiceClient>(SessionsServiceClient::Options{ + .TargetUrl = ServerOptions.SessionsTargetUrl, + .AppName = "zenserver", + .Mode = GetServerMode(), + .SessionId = GetSessionId(), + }); } if (ServerOptions.BuildStoreConfig.Enabled) @@ -821,6 +838,17 @@ ZenStorageServer::Run() OnReady(); + m_SessionsService->RegisterSession(GetSessionId(), "zenserver", GetServerMode(), Oid::Zero, {}); + + if (m_SessionsClient) + { + (void)m_SessionsClient->Announce(); + EnqueueSessionAnnounceTimer(); + + m_SessionLogSink = m_SessionsClient->CreateLogSink(); + GetDefaultBroadcastSink()->AddSink(m_SessionLogSink); + } + if (m_IsPowerCycle) { ZEN_INFO("Power cycle mode enabled -- shutting down"); @@ -841,19 +869,48 @@ ZenStorageServer::Cleanup() ZEN_INFO(ZEN_APP_NAME " cleaning up"); try { + m_SessionAnnounceTimer.cancel(); + + // Stop the IO context and join its thread first, before removing sinks. + // This ensures no async operations are trying to log through the + // broadcast sink while we modify its sink list. m_IoContext.stop(); if (m_IoRunner.joinable()) { m_IoRunner.join(); } - ShutdownServices(); - + // Close the HTTP server before removing sinks. HTTP worker threads + // continuously log messages and hold the BroadcastSink shared lock, + // which would starve the exclusive lock needed by RemoveSink(). if (m_Http) { m_Http->Close(); } + if (m_InProcSessionLogSink) + { + GetDefaultBroadcastSink()->RemoveSink(m_InProcSessionLogSink); + m_InProcSessionLogSink = {}; + } + if (m_SessionLogSink) + { + GetDefaultBroadcastSink()->RemoveSink(m_SessionLogSink); + m_SessionLogSink = {}; + } + if (m_SessionsClient) + { + (void)m_SessionsClient->Remove(); + m_SessionsClient.reset(); + } + + if (m_SessionsService) + { + m_SessionsService->RemoveSession(GetSessionId()); + } + + ShutdownServices(); + if (m_JobQueue) { m_JobQueue->Stop(); @@ -938,6 +995,20 @@ ZenStorageServer::CheckStateMarker() } void +ZenStorageServer::EnqueueSessionAnnounceTimer() +{ + m_SessionAnnounceTimer.expires_after(std::chrono::seconds(15)); + m_SessionAnnounceTimer.async_wait([this](const asio::error_code& Ec) { + if (!Ec && m_SessionsClient) + { + (void)m_SessionsClient->Announce(); + EnqueueSessionAnnounceTimer(); + } + }); + EnsureIoRunner(); +} + +void ZenStorageServer::Flush() { ZEN_TRACE_CPU("ZenStorageServer::Flush"); |