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/frontend/zipfs.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/frontend/zipfs.cpp')
| -rw-r--r-- | src/zenserver/frontend/zipfs.cpp | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/zenserver/frontend/zipfs.cpp b/src/zenserver/frontend/zipfs.cpp index 42df0520f..c7c8687ca 100644 --- a/src/zenserver/frontend/zipfs.cpp +++ b/src/zenserver/frontend/zipfs.cpp @@ -2,6 +2,12 @@ #include "zipfs.h" +#include <zencore/logging.h> + +ZEN_THIRD_PARTY_INCLUDES_START +#include <zlib.h> +ZEN_THIRD_PARTY_INCLUDES_END + namespace zen { ////////////////////////////////////////////////////////////////////////// @@ -126,15 +132,20 @@ ZipFs::ZipFs(IoBuffer&& Buffer) const CentralDirectoryRecord& Cd = *CdCursor; bool Acceptable = true; - Acceptable &= (Cd.OriginalSize > 0); // has some content - Acceptable &= (Cd.CompressionMethod == 0); // is stored uncomrpessed + Acceptable &= (Cd.OriginalSize > 0); // has some content + Acceptable &= (Cd.CompressionMethod == 0 || Cd.CompressionMethod == 8); // stored or deflate if (Acceptable) { const uint8_t* Lfh = Cursor + Cd.Offset; if (uintptr_t(Lfh - Cursor) < View.GetSize()) { std::string_view FileName(Cd.FileName, Cd.FileNameLength); - m_Files.insert(std::make_pair(FileName, FileItem{Lfh, size_t(0)})); + FileItem Item; + Item.View = MemoryView{Lfh, size_t(0)}; + Item.CompressionMethod = Cd.CompressionMethod; + Item.CompressedSize = Cd.CompressedSize; + Item.UncompressedSize = Cd.OriginalSize; + m_Files.insert(std::make_pair(FileName, std::move(Item))); } } @@ -159,23 +170,59 @@ ZipFs::GetFile(const std::string_view& FileName) const } const FileItem& Item = Iter->second; - if (Item.GetSize() > 0) + if (Item.View.GetSize() > 0) { - return IoBuffer(IoBuffer::Wrap, Item.GetData(), Item.GetSize()); + return IoBuffer(IoBuffer::Wrap, Item.View.GetData(), Item.View.GetSize()); } } RwLock::ExclusiveLockScope _(m_FilesLock); FileItem& Item = m_Files.find(FileName)->second; - if (Item.GetSize() > 0) + if (Item.View.GetSize() > 0) + { + return IoBuffer(IoBuffer::Wrap, Item.View.GetData(), Item.View.GetSize()); + } + + const auto* Lfh = (LocalFileHeader*)(Item.View.GetData()); + const uint8_t* FileData = (const uint8_t*)(Lfh->FileName + Lfh->FileNameLength + Lfh->ExtraFieldLength); + + if (Item.CompressionMethod == 0) + { + // Stored — point directly into the buffer + Item.View = MemoryView(FileData, Item.UncompressedSize); + } + else { - return IoBuffer(IoBuffer::Wrap, Item.GetData(), Item.GetSize()); + // Deflate — decompress using zlib + Item.DecompressedData = IoBuffer(Item.UncompressedSize); + + z_stream Stream = {}; + Stream.next_in = const_cast<Bytef*>(FileData); + Stream.avail_in = Item.CompressedSize; + Stream.next_out = (Bytef*)Item.DecompressedData.GetMutableView().GetData(); + Stream.avail_out = Item.UncompressedSize; + + // Use raw inflate (-MAX_WBITS) since zip stores raw deflate streams + if (inflateInit2(&Stream, -MAX_WBITS) != Z_OK) + { + ZEN_WARN("failed to initialize inflate for '{}'", FileName); + return {}; + } + + int Result = inflate(&Stream, Z_FINISH); + inflateEnd(&Stream); + + if (Result != Z_STREAM_END) + { + ZEN_WARN("failed to decompress '{}' (zlib error {})", FileName, Result); + return {}; + } + + Item.View = Item.DecompressedData.GetView(); } - const auto* Lfh = (LocalFileHeader*)(Item.GetData()); - Item = MemoryView(Lfh->FileName + Lfh->FileNameLength + Lfh->ExtraFieldLength, Lfh->OriginalSize); - return IoBuffer(IoBuffer::Wrap, Item.GetData(), Item.GetSize()); + return IoBuffer(IoBuffer::Wrap, Item.View.GetData(), Item.View.GetSize()); } } // namespace zen |