feat(metrics): add support for metric families and label serialisation#234
Open
ethanolchik wants to merge 4 commits into
Open
feat(metrics): add support for metric families and label serialisation#234ethanolchik wants to merge 4 commits into
ethanolchik wants to merge 4 commits into
Conversation
Add a serde serialiser that converts metric label structs into Prometheus protobuf LabelPair values. Preserve the legacy backend's scalar formatting behaviour, including ryu-based float formatting, serde renames, enum variants, optional values, and display adapters. Validate label names and reject unsupported compound values. Store label values without OpenMetrics escaping so the protobuf model remains format-independent and text escaping can be applied later by the text encoder.
Add shared labeled metric storage with custom constructors and lifecycle operations. Group encoded metrics by suffix and skip invalid label sets or inconsistent metadata without failing collection.
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 builds on the already-merged scalar metrics #232 (
Counter,Gauge) to add labelled metrics. It introduces a serde-based system for serialising metric label sets into the Prometheus protobuf data model, and adds aFamilyabstraction for grouping metrics by their label values.Label serialisation and error handling
labelsmodule with:to_label_pairs: serialises anyserde::Serializelabel set into protobufLabelPairvalues.Serializerimplementation that flattens a label struct into name/value pairs, rejecting unsupported compound types (sequences, maps, nested structs, byte arrays) with clear errors.LabelError: a dedicated error type implementingserde::ser::Error.ryu-based float formatting, serde renames, enum variants, optional values, andDisplayadapters.[a-zA-Z_:][a-zA-Z0-9_:]*.serde(withderive),ryu, andparking_lotdependencies to support label serialisation and efficient concurrent metric storage.Metrics API enhancements
Family<S, M, C>: shared, labelled metric storage with:get_or_create,remove, andclearlifecycle operations; clones share the same underlying metrics.MetricConstructortrait (with a blanketFn() -> Mimpl) for metrics that need configuration at creation time.RangeGauge) are grouped correctly by suffix.Family,MetricConstructor,LabelError,to_label_pairs, andset_collect_error_hookfrom the crate root for downstream use.Decoupling logging from metrics
set_collect_error_hook) rather than a hard-coded logger, defaulting to stderr when none is set.foundationsadopts this crate): install a collect_error hook that forwards these diagnostics to the telemetry logging pipeline (at warning level), matching the legacy backend's behaviour.Protobuf model adjustments
LabelPairfrom the registryprotomodule so downstream code can construct/consume label pairs.Attribution
Familyare adapted fromprometools(MIT OR Apache-2.0); per-definition// Adapted from ...notes were added, per the discussion with @TheJokr. (prometheus-client-derived code remains covered by the existing module-level# Licensedisclaimer.)