feat(metrics-registry): add core registration API#229
Merged
TheJokr merged 4 commits intoJul 10, 2026
Conversation
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`.
TheJokr
reviewed
Jul 10, 2026
Co-authored-by: Leo Blöcher <leo@bloecher.dev>
TheJokr
approved these changes
Jul 10, 2026
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.
Introduce the registration layer on top of the protobuf data model:
EncodeMetric: trait for metrics that encode themselves intoMetricFamilymessages (best-effort; an emptyVecis valid).register/iter: append-only global registry behind aparking_lot::RwLock<Vec<Arc<Entry>>>.iter()clones anArcsnapshot 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 aVecof them.MetricsIter/MetricRegistration: point-in-time snapshot iterator pairing each metric with itsRegistrationMetadatavia accessors, keeping the internalEntrystorage type private.RegistrationMetadata:#[non_exhaustive]builder for theoptionalandunprefixedflags.Add the
parking_lotdependency and re-export the new public API fromlib.rs.