feat(metrics): add protobuf and OpenMetrics text encoders, collection, and info metrics.#237
Draft
ethanolchik wants to merge 16 commits into
Draft
feat(metrics): add protobuf and OpenMetrics text encoders, collection, and info metrics.#237ethanolchik wants to merge 16 commits into
ethanolchik wants to merge 16 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
ethanolchik
force-pushed
the
encoders-and-collect
branch
from
July 24, 2026 11:51
8e54c49 to
1a7e8f5
Compare
ethanolchik
force-pushed
the
encoders-and-collect
branch
from
July 24, 2026 12:07
1a7e8f5 to
b420c26
Compare
ethanolchik
force-pushed
the
encoders-and-collect
branch
from
July 24, 2026 14:43
b420c26 to
6a04141
Compare
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 PR completes the path from registered metrics to Prometheus-compatible wire output:
MetricFamilymodel.The public API now exposes
collect,CollectionOptions,ServiceNameFormat,encode_to_protobuf, andencode_to_text.Collection
collectiterates over the global registry and encodes each registered metric into one or moreMetricFamilyvalues.CollectionOptionscontrols whether optional metrics are included and how a service name is represented:MetricPrefixprefixes metric family names, except metrics registered as unprefixed.LabelWithNameadds the service name as a label to every row.The resulting
Vec<MetricFamily>provides a common boundary between metric implementations and wire encoders.Encoding
encode_to_protobufserialises metric families as concatenated, length-delimited Prometheus protobuf messages. This preserves fields that OpenMetrics text cannot fully represent, including native histogram data.encode_to_textsupports:1with their fields as labelsLegacy info metrics preserve their existing wire representation in both formats: the family name remains unchanged (for example,
build_info), the protobuf type is gauge, and text output emits# TYPE build_info gauge.The text encoder emits
# HELP,# TYPE, and# UNITmetadata and terminates output with# EOF.Histogram encoding:
f64::MAXbucket to+Inf.+Infbucket when missing.The encoder also handles metric and exemplar timestamps, escapes help text and label values, and emits
NaN,+Inf, and-Infusing OpenMetrics syntax.SummaryandGaugeHistogramfamilies are fully supported. Protobuf passes them through unchanged. In text, summaries emit theirquantilerows plus_sumand_count; gauge histograms emit_bucketrows plus_gsumand_gcount.For text output, families without a non-empty name or recognised type, and rows missing data for their declared type, are skipped and reported through the non-fatal collection error hook.