docs: warn that Prometheus /metrics must be scraped when enabled#4660
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ Deploy Preview for electric-next ready!
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
4e80483 to
612eafe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
If
ELECTRIC_PROMETHEUS_PORTis set but nothing ever scrapes the/metricsendpoint, Electric's memory grows without bound and can eventually OOM-kill the service. This came out of debugging a customer whoseprometheus_metrics_distETS 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_corestores distribution (histogram) metrics in a:duplicate_bagand appends one row per observation (distribution.ex:ets.insert), only aggregating into buckets — and draining the bag via:ets.take— at 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:setstorage.This is purely a docs change to make the "must be scraped" requirement explicit everywhere we mention Prometheus.
Changes
website/docs/sync/reference/telemetry.md) — warning callout in the Metrics section.website/docs/sync/api/config.md) — note onELECTRIC_PROMETHEUS_PORT.website/docs/sync/guides/deployment.md) — warning in the Observability section.prometheus_portdocstring (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_lagout 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