← Back to Pull requests

[History server] Implement disk-first event storage pipeline to reduce collector memory #4874

Closed
unknown closed this pull request without merging on Aug 04, 2026 22:28 UTC
View on GitHub
unknown unknown commented on May 25, 2026 12:56 UTC
Author

Why are these changes needed?

The event collector buffered all incoming events in memory (map[string][]Event) and flushed them periodically as a JSON array. This has two problems:
1. memory grows unbounded with event volume
2. a collector crash loses everything not yet flushed

This PR replaces the in-memory buffer with a disk-first pipeline:

POST /v1/events -> append to local JSONL -> rotate -> (optional gzip) -> upload -> delete local

To store events in disk rather than memory before uploading to object store. On startup, leftover .jsonl/.jsonl.gz files from a previous run are re-uploaded. Failed uploads are retried with backoff; files are only deleted locally after a successful upload.

Behavior details

- Durability: 200 OK means the events are on local disk. Disk usage above 80% of --event-max-disk-mb returns 503 + Retry-After so the dashboard agent retries instead of dropping events.

  • Rotation triggers on: file age (--event-rotation-interval), file size (--event-max-file-size-mb), session change, node ID change, and shutdown.

  • Shutdown follows the [golang pipeline pattern](go.dev/blog/pipelines): all senders stop before the queue closes, the upload worker drains it giving each remaining file one final attempt; anything still failing stays on disk for the next start's resume.

  • Storage layout: rotated files upload as JSONL under the clusterlogs layout (#4918): .../{session}/{nodeID}/node_events/... and .../{session}/{nodeID}/job_events/{jobID}/...
  • Flags update

  • --event-flush-interval is removed (no in-memory buffer to flush).

  • --event-compression-enabled is retained but now only controls whether rotated files are gzipped before upload.
  • New flags (all with env-var overrides): --event-data-dir, --event-rotation-interval, --event-max-file-size-mb, --event-max-disk-mb

    Extra fix

    GetContent in the Aliyun OSS backend was missing the OssRootDir/clusterId prefix, so GetObject 404'd on paths that ListFiles had returned successfully.

    Related issue number

    Part of #4706

    Checks

  • I've made sure the tests are passing.

  • Testing Strategy

  • - [x] Unit tests
    - [x] Manual tests
    - [ ] This PR is not tested :(

    Diff: 285 lines (+213 / -72) across 3 files Reviewer: KunWuLuan Review duration: 102811m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 285 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.338
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4874"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.7% · Safe to merge
    15.7%