feat(metrics): introduce foundations-metrics with scalar metrics#232
Open
ethanolchik wants to merge 8 commits into
Open
feat(metrics): introduce foundations-metrics with scalar metrics#232ethanolchik wants to merge 8 commits into
ethanolchik wants to merge 8 commits into
Conversation
Add shared atomic Counter storage with u64 and f64 support. - Introduce EncodeMetricValue for storage encoding - Add NamedMetric for registered names and help text
Expose the underlying atomic storage to preserve compatibility with the legacy Counter API.
- Replace the prometheus-client gauge wrapper with Foundations-owned storage and atomic traits. - Share floating-point atomic updates between counters and gauges.
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.
Overview
This pull request introduces the new
foundations-metricscrate, which provides the initial scalar metric types and converts their values into the Prometheus protobuf data model.It builds on
foundations-metrics-registry, which continues to own the stable process-global registry and protobuf types. This separation allows metric implementations to evolve without destabilising the registry shared across Foundations versions.New Crate: foundations-metrics
register,EncodeMetric,IntoMetrics,MetricFamily, andRegistrationMetadata, allowing callers to use the higher-level crate without importing registry APIs separately.Scalar Metrics
Counterwithu64andf64support.Gaugewithi64(sinceprometheus_clientv0.19.0),u64, andf64support.RangeGauge, which exports the current, minimum, and maximum values observed since the previous collection.GaugeGuard, which increments a gauge when created and decrements it when dropped.prometheus-client. The spec allowed either approach; owned storage keeps the scalar API independent of upstream implementation details and defers the dependency until it is needed for native histograms, though it is still included infoundations-metrics/Cargo.toml.Arc, preserving inexpensive handle semantics.CounterAtomicandGaugeAtomictraits allow additional storage implementations to be added without changing the metric API.Registration and Encoding
NamedMetric, which associates metric storage with its exported name and help text. Metric handles intentionally contain only state because the metrics macro already owns registration metadata.EncodeMetricValuetrait. Storage types encode protobuf families with relative names, whileNamedMetricapplies the registered base name and help text.RangeGaugeemits"",_min, and_max, allowing it to compose withNamedMetricand future labelled families without special handling._total, preserving existing Foundations output behaviour.Workspace Updates
foundations-metricsas a workspace member and workspace dependency.foundations-metrics-registryto export the protobufCounterandGaugemessage types.