Skip to content

docs: warn that Prometheus /metrics must be scraped when enabled#4660

Merged
robacourt merged 1 commit into
mainfrom
rob/docs-prometheus-scraping
Jun 30, 2026
Merged

docs: warn that Prometheus /metrics must be scraped when enabled#4660
robacourt merged 1 commit into
mainfrom
rob/docs-prometheus-scraping

Conversation

@robacourt

@robacourt robacourt commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

If ELECTRIC_PROMETHEUS_PORT is set but nothing ever scrapes the /metrics endpoint, Electric's memory grows without bound and can eventually OOM-kill the service. This came out of debugging a customer whose prometheus_metrics_dist ETS table had grown to ~8 GB on an OTel-only deployment that had the Prometheus port enabled but unscraped.

Why it happens

telemetry_metrics_prometheus_core stores distribution (histogram) metrics in a :duplicate_bag and appends one row per observation (distribution.ex :ets.insert), only aggregating into buckets — and draining the bag via :ets.takeat scrape time (documented in the library's moduledoc: "aggregations for distributions (histogram) only occur at scrape time"). So if the endpoint is never scraped, the bag is never drained.

Electric's default Prometheus metric set includes electric.postgres.replication.transaction_received.receive_lag, a distribution emitted roughly once per replication transaction, so the table accretes continuously under load (~0.55 GB/day in the customer's case). Counters/sums/last-values are unaffected — they use bounded :set storage.

This is purely a docs change to make the "must be scraped" requirement explicit everywhere we mention Prometheus.

Changes

  • Telemetry reference (website/docs/sync/reference/telemetry.md) — warning callout in the Metrics section.
  • Config reference (website/docs/sync/api/config.md) — note on ELECTRIC_PROMETHEUS_PORT.
  • Deployment guide (website/docs/sync/guides/deployment.md) — warning in the Observability section.
  • prometheus_port docstring (packages/sync-service/lib/electric.ex).

Follow-up (not in this PR)

Worth considering a code-level guard so an enabled-but-unscraped endpoint can't OOM the service (e.g. move high-frequency distributions like receive_lag out of the default Prometheus set, or run an internal periodic drain).

I have raised a PR with the library maintainer for a potential fix: beam-telemetry/telemetry_metrics_prometheus_core#77

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.01%. Comparing base (b66ebf7) to head (612eafe).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4660      +/-   ##
==========================================
- Coverage   60.03%   60.01%   -0.03%     
==========================================
  Files         395      395              
  Lines       43747    43747              
  Branches    12579    12578       -1     
==========================================
- Hits        26262    26253       -9     
- Misses      17407    17415       +8     
- Partials       78       79       +1     
Flag Coverage Δ
packages/agents 72.64% <ø> (ø)
packages/agents-mcp 77.70% <ø> (ø)
packages/agents-mobile 80.67% <ø> (ø)
packages/agents-runtime 83.76% <ø> (+0.03%) ⬆️
packages/agents-server 75.45% <ø> (-0.21%) ⬇️
packages/agents-server-ui 8.32% <ø> (ø)
packages/electric-ax 51.06% <ø> (ø)
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 82.83% <ø> (ø)
packages/typescript-client 91.71% <ø> (-0.12%) ⬇️
packages/y-electric 56.05% <ø> (ø)
typescript 60.01% <ø> (-0.03%) ⬇️
unit-tests 60.01% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@netlify

netlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit 4e80483
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/6a425a65a8e0e100084a147b
😎 Deploy Preview https://deploy-preview-4660--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Distribution metrics in telemetry_metrics_prometheus_core buffer raw
observations in a :duplicate_bag and only aggregate at scrape time. When
ELECTRIC_PROMETHEUS_PORT is set but the /metrics endpoint is never
scraped, that buffer grows unbounded (notably the per-transaction
receive_lag distribution) and can exhaust memory and crash the service.

Add this warning to the telemetry reference, config reference, deployment
guide, and the prometheus_port config docstring.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YW7Njz5ZpBDaoGviW1eVR8
@robacourt robacourt force-pushed the rob/docs-prometheus-scraping branch from 4e80483 to 612eafe Compare June 29, 2026 11:58
@robacourt robacourt requested a review from alco June 29, 2026 14:57
@robacourt robacourt self-assigned this Jun 29, 2026

@alco alco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find!

@robacourt robacourt merged commit 0130c4a into main Jun 30, 2026
75 of 77 checks passed
@robacourt robacourt deleted the rob/docs-prometheus-scraping branch June 30, 2026 10:09
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.

2 participants