Skip to content

Metrics: per-repository instruments have room for 1,000 repositories, and an overflow is warned about - #904

Open
schmitch wants to merge 2 commits into
mainfrom
claude/580-metric-cardinality-limit
Open

schmitch wants to merge 2 commits into
mainfrom
claude/580-metric-cardinality-limit

Conversation

@schmitch

Copy link
Copy Markdown
Member

Fixes #580

The OpenTelemetry SDK keeps at most 2,000 attribute sets per instrument; past that, new ones land in one otel.metric.overflow=true series without repository or status, and nothing is logged. http.client.request.duration and forge.proxy.lookups reached it with a few dozen to about a hundred proxies, so alerts and panels by forge_repository missed what overflowed.

What changes

  • Views. With telemetry.per_repository on, a view gives every instrument that carries forge.repository a cardinality_limit of (sets one repository gives it) × 1,000 repositories, never below the SDK's 2,000: 32,000 for http.client.request.duration, 18,000 for forge.proxy.lookups, 3,000 for forge.proxy.upstream.documents; the retention and inventory instruments stay at 2,000. The sets per repository are a table beside the instruments (forge_telemetry::PER_REPOSITORY_INSTRUMENTS), and the existing attribute test fails when an instrument with forge.repository is missing from it. The view sets the limit alone: name, unit, description and histogram buckets stay the instrument's.
  • Warning. The metric exporter is wrapped: an export that holds the overflow series logs a warning once per instrument, with the instrument, its limit and what to do (restart to drop deleted repositories' series, or turn per_repository off). It covers every instrument, not only the per-repository ones.
  • Guide. docs/deployment.md (Telemetry) names the threshold, 1,000 repositories, shows the warning and says when to turn telemetry.per_repository off; forge.toml.example and the config's doc comment say the same.

How the limit follows the repositories

A fixed budget, not the live count. The limit is fixed when an instrument is built, and main builds the instruments before it connects the database, so the count is not known then; repositories are also created while Forge runs, and a limit cannot be changed afterwards. 1,000 is far more than the "about a hundred" of the issue. The cost is memory the SDK allocates up front (HashMap::with_capacity(1 + limit)): by my arithmetic about 3 MB for the three raised instruments (not measured). http.client.request.duration assumes at most 32 method × status combinations per proxy (the issue says 20–30); an upstream that answers with more reaches the limit earlier, and the warning says so.

Checked against opentelemetry_sdk 0.33.1 (the version in Cargo.lock), in its source: Stream::builder().with_cardinality_limit(n) and MeterProviderBuilder::with_view are stable API there (no spec_unstable_metrics_views feature needed), a view without an aggregation keeps the instrument's with_boundaries, the limit applies to observable instruments too, and the overflow path logs nothing.

Verification

  • cargo test -p forge-server --test telemetry_cardinality (new, no Docker): 3,000 attribute sets on http.client.request.duration through Forge's own instruments are all exported with their repository, with the instrument's buckets; forge.proxy.upstream.documents at exactly its limit warns of nothing, one repository more gives the overflow series and exactly one warning, not repeated on the next export. With the view switched off locally, both tests fail (2,001 points instead of 3,000).
  • cargo test -p forge-telemetry; cargo test -p forge-server --lib --test telemetry --test otlp_export (Postgres and versitygw in Docker, through mirror.gcr.io): all pass.
  • cargo xtask check (fmt, clippy -D warnings), cargo xtask unused, cargo xtask doc-check, cargo xtask changelog --check: all pass.

Not run locally: the rest of the workspace's suites (cargo xtask test, cargo xtask e2e), left to CI. Not verified: the warning against a real Collector and backend, and the memory figure above.

No web UI screen: the change adds no admin API.


Generated by Claude Code

… and an overflow is warned about

The OpenTelemetry SDK keeps at most 2,000 attribute sets per instrument
and counts what is recorded with a further one in a single
otel.metric.overflow=true series, without repository or status, and logs
nothing. http.client.request.duration and forge.proxy.lookups reached
that with a few dozen to about a hundred proxies, so alerts and panels
by forge_repository missed what overflowed.

With telemetry.per_repository on, a view now gives every instrument that
carries forge.repository a cardinality limit sized for 1,000
repositories (forge_telemetry::PER_REPOSITORY_INSTRUMENTS holds the sets
one repository gives each; never below the SDK's default). The limits
are fixed when the instruments are built, before the database is
connected, so they follow a budget, not the repositories there are.

The metric exporter is wrapped: an export that holds the overflow series
logs a warning, once per instrument, with the limit and what to do. The
deployment guide names the threshold.

Fixes #580

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012e6DJZQLYNg6tPPU1395q8
@schmitch
schmitch added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 17, 2026
…provider's views

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012e6DJZQLYNg6tPPU1395q8

This branch has not been deployed

No deployments
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.

Metrics: per-repository instruments overflow the SDK's 2,000-series limit without a word

2 participants