Commit 0130c4a
docs: warn that Prometheus /metrics must be scraped when enabled (#4660)
## 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.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
`: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](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 86bb70f commit 0130c4a
4 files changed
Lines changed: 11 additions & 1 deletion
File tree
- packages/sync-service/lib
- website/docs/sync
- api
- guides
- reference
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
| 618 | + | |
| 619 | + | |
618 | 620 | | |
619 | 621 | | |
620 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
232 | 235 | | |
233 | 236 | | |
234 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
| |||
0 commit comments