Skip to content

feat: forward network_events to Daydream /v1/metrics via reliable client reporter#1041

Closed
seanhanca wants to merge 1 commit into
mainfrom
feat/metrics-reporter
Closed

feat: forward network_events to Daydream /v1/metrics via reliable client reporter#1041
seanhanca wants to merge 1 commit into
mainfrom
feat/metrics-reporter

Conversation

@seanhanca

Copy link
Copy Markdown
Collaborator

Summary

  • Add a MetricsReporter client that reliably forwards stream_trace lifecycle events (the same network_events envelope) to Daydream's POST /v1/metrics endpoint, implementing the fail-loud / no-loss client contract (batched HTTP POST, exponential backoff on 5xx, pause on 401, rate-limit awareness on 429, optional disk-backed crash-safe buffer).
  • In local mode, events are fed in-process via a new event-sink hook in kafka_publisher.py. In cloud/livepeer mode, the runner writes network_event messages onto the trickle events channel and LivepeerClient routes them into the reporter on the Scope client side.
  • Existing direct-to-Kafka publishing is kept intact (augment, not replace). No new dependencies — uses httpx (already a dep).

Architecture

Runner (publish_event → Kafka + trickle sink)
  ↓ trickle events channel: {type: "network_event", event: <envelope>}
Scope client (LivepeerClient._events_loop → MetricsReporter)
  ↓ batched POST /v1/metrics with Bearer key
Daydream API → Kafka network_events topic

Files changed

File Change
src/scope/server/metrics_reporter.py NewMetricsReporter with thread-safe enqueue, async flush loop, fail-loud response handling, disk buffer, global accessors
src/scope/server/kafka_publisher.py Event-sink hook: set_event_sink() + _dispatch_to_sink() called after envelope build
src/scope/cloud/livepeer_app.py Register trickle sink in _subscribe_control to forward envelopes over events channel
src/scope/server/livepeer_client.py Route network_event messages from events loop into report_event()
src/scope/server/app.py Wire MetricsReporter start/stop into lifespan; register in-process event sink
tests/test_metrics_reporter.py New — 33 tests covering mapping, batching, all response codes, backoff, disk resume, sink hook

Config (env vars)

  • DAYDREAM_METRICS_URL — endpoint (default: https://api.daydream.monster/v1/metrics)
  • SCOPE_CLOUD_API_KEY — Bearer token (required to enable; already used for cloud connect)
  • SCOPE_METRICS_ENABLED — explicit enable/disable (default: on when key present)
  • SCOPE_METRICS_FLUSH_INTERVAL_MS, SCOPE_METRICS_MAX_BATCH, SCOPE_METRICS_MAX_BUFFER, SCOPE_METRICS_BUFFER_PATH

Test plan

  • uv run ruff check src/ — all checks passed
  • uv run ruff format --check src/ — all formatted
  • uv run pytest tests/test_metrics_reporter.py -v — 33/33 passed
  • Server imports cleanly (from scope.server.app import app)
  • CI passes
  • Manual E2E: set SCOPE_CLOUD_API_KEY, start Scope, verify events appear in Kafka network_events topic

Made with Cursor

…ent reporter

Add a MetricsReporter that buffers stream_trace lifecycle events and
forwards them in batches to the Daydream POST /v1/metrics endpoint.
Implements the fail-loud / no-loss client contract: exponential backoff
on 5xx/network errors, pause on 401, rate-limit awareness on 429, and
optional disk-backed resume buffer for crash-safe delivery.

In local mode the reporter is fed in-process via an event-sink hook in
kafka_publisher.py. In cloud/livepeer mode the runner writes
network_events onto the trickle events channel and LivepeerClient routes
them into the reporter on the client side. Existing direct-to-Kafka
publishing is kept intact (augment, not replace).

Signed-off-by: qianghan <qiang@livepeer.org>
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19de75e4-a750-486b-b010-58d86e70631a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/metrics-reporter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

🚀 fal.ai Preview Deployment

Commit 78cc0b6
App ID daydream/scope-livepeer-pr-1041--preview
WebSocket wss://fal.run/daydream/scope-livepeer-pr-1041--preview/ws

Testing on Cloud

SCOPE_CLOUD_APP_ID="daydream/scope-livepeer-pr-1041--preview/ws" uv run daydream-scope

@seanhanca

Copy link
Copy Markdown
Collaborator Author

Superseded by adding MetricsReporter directly to PR #1040 (feat/telemetry-over-trickle)

@seanhanca seanhanca closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant