feat(foundations): use foundations-metrics as the macro backend + expose a foundations-metrics facade - #240
Draft
ethanolchik wants to merge 44 commits into
Draft
feat(foundations): use foundations-metrics as the macro backend + expose a foundations-metrics facade#240ethanolchik wants to merge 44 commits into
ethanolchik wants to merge 44 commits into
Conversation
Add owned fixed-bucket storage, direct protobuf encoding, and support for the legacy HistogramBuilder API (only classic histograms in this commit).
Choose to pre-sort histogram buckets over a sorted boolean variable. Also satisfies cargo clippy & cargo fmt
…omplete, non-empty names
… names Legacy metric and label names must match Prometheus' name grammars. Names outside these grammars cause Prometheus to reject the scrape, and the grammars exclude non-ASCII characters. Foundations now quotes label names and uses OpenMetrics' quoted metric-name syntax when required. This allows UTF-8 and other nonstandard names without affecting legacy compatibility.
Add registerable counter, classic histogram, and native histogram types that retain exemplars alongside observations. Support typed and legacy label sets, Family usage, OpenMetrics text, and Prometheus protobuf encoding. Validate exemplars during collection and report serialisation failures as non-fatal diagnostics.
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.
PR Description: metrics/runtime
Overview
This PR completes the
foundations-metricscrate and integrates it into thefoundationstelemetry facade. It adds histograms, exemplars, collection, encoding, validation, info metrics, and custom metrics support. Thefoundationscrate gains a newfoundations-metrics-backendfeature flag (enabled by default) that swaps the legacyprometheus-client/prometoolsstack for the new implementation while keeping existing call sites source-compatible.New Metric Types
Histogram(classic buckets),TimeHistogram(seconds-scaled), andNativeHistogram(zero-threshold / bucket-factor configuration).CounterWithExemplar,HistogramWithExemplars, andNativeHistogramWithExemplarsfor trace-context exemplars.InfoMetrictrait andreport_info()for persistent build/process metadata.EncodeMetricandEncodeMetricValueso users can define their own metric types and register them viaNamedMetricandFamily.Collection & Encoding
collect()andCollectionOptionsto walk the global registry and emitMetricFamilyprotobuf messages.encode_to_text(OpenMetrics) andencode_to_protobuf(length-delimited Prometheus protobuf).Accept-header content negotiation in the telemetry server (see Behaviour Changes).qweight are now dropped rather than treated asq=1.0.Behaviour Changes
/metricspreviously ignoredAcceptentirely and always returnedapplication/openmetrics-text; version=1.0.0; charset=utf-8. That is still what everyscraper that sends no
Accept, or that accepts text, receives — so the common path isunchanged. Two cases now behave differently:
Acceptreturns406 Not Acceptableinstead of text. For exampleAccept: application/json,text/html, or a malformedqon the only supplied range.OpenMetrics text is always servable, so a 406 can only mean the client refused text;
serving text to a client that said it cannot parse text hides a misconfiguration
instead of surfacing it.
ExtraProduceris a text-only extension point, so while any extra producer is registered the server
withholds protobuf and serves text. This is all-or-nothing: one registered producer
disables protobuf for the whole process. A protobuf-only client in that state gets a
406 rather than a silently truncated exposition.
Protobuf availability is a runtime capability evaluated per scrape, not a setting; no
MetricsSettingsfield was added. Note that native histograms are not representable inOpenMetrics text, so a process with both native histograms and an extra producer cannot
export the full set in either format.
Validation & UTF-8
Foundations Integration
foundations-macrosto register metrics through a backend-agnostic shim, so#[metrics]and#[info_metric]work with either backend.add_extra_producer/ExtraProducerin favor of structuredEncodeMetricregistration.foundations-metrics-backendfeature.Crate Readiness
descriptionfields tofoundations-metricsandfoundations-metrics-registryso they are publishable on crates.io.README.mdwith migration guide off the telemetry facade.