Skip to content

feat(metrics-registry): add core registration API#229

Merged
TheJokr merged 4 commits into
cloudflare:mainfrom
ethanolchik:metrics/create-registry-core
Jul 10, 2026
Merged

feat(metrics-registry): add core registration API#229
TheJokr merged 4 commits into
cloudflare:mainfrom
ethanolchik:metrics/create-registry-core

Conversation

@ethanolchik

Copy link
Copy Markdown
Contributor

Introduce the registration layer on top of the protobuf data model:

  • EncodeMetric: trait for metrics that encode themselves into MetricFamily messages (best-effort; an empty Vec is valid).
  • register/iter: append-only global registry behind a parking_lot::RwLock<Vec<Arc<Entry>>>. iter() clones an Arc snapshot so iteration never holds the lock. Service-name handling is deferred to encode time so metrics can be registered before the service name is known.
  • IntoMetrics: sealed conversion trait accepting a single boxed metric or a Vec of them.
  • MetricsIter/MetricRegistration: point-in-time snapshot iterator pairing each metric with its RegistrationMetadata via accessors, keeping the internal Entry storage type private.
  • RegistrationMetadata: #[non_exhaustive] builder for the optional and unprefixed flags.

Add the parking_lot dependency and re-export the new public API from lib.rs.

Introduce the registration layer on top of the protobuf data model:

- `EncodeMetric`: trait for metrics that encode themselves into
  `MetricFamily` messages (best-effort; an empty `Vec` is valid).
- `register`/`iter`: append-only global registry behind a
  `parking_lot::RwLock<Vec<Arc<Entry>>>`. `iter()` clones an `Arc`
  snapshot so iteration never holds the lock. Service-name handling is
  deferred to encode time so metrics can be registered before the
  service name is known.
- `IntoMetrics`: sealed conversion trait accepting a single boxed metric
  or a `Vec` of them.
- `MetricsIter`/`MetricRegistration`: point-in-time snapshot iterator
  pairing each metric with its `RegistrationMetadata` via accessors,
  keeping the internal `Entry` storage type private.
- `RegistrationMetadata`: `#[non_exhaustive]` builder for the `optional`
  and `unprefixed` flags.

Add the `parking_lot` dependency and re-export the new public API from
`lib.rs`.
Comment thread foundations-metrics-registry/src/metadata.rs Outdated
Comment thread foundations-metrics-registry/src/metadata.rs Outdated
Comment thread foundations-metrics-registry/src/registry.rs
Comment thread foundations-metrics-registry/src/registry.rs
Comment thread foundations-metrics-registry/src/iter.rs Outdated
@TheJokr TheJokr merged commit b12e900 into cloudflare:main Jul 10, 2026
18 checks passed
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