Skip to main content

Module metric_sink

Module metric_sink 

Source
Expand description

Render arm for MetricSinkConnection.

A metric sink funnels every row of its source collection to one worker, folds it into a SinkState, and exposes that state to the processโ€™s Prometheus registry through a SinkCollector. SinkState is shared between the timely operator (the sole writer) and SinkCollector::collect (the reader, invoked from whatever thread scrapes the registry) via Arc<Mutex<_>>. Both sides only ever hold the lock across a short, synchronous section: the operator has no await points (it is a synchronous builder_rc operator), and the collector only clones out the data it needs to build MetricFamily protos before releasing the lock.

The planner (optimize::metric_sink::shape_metric_sink_source) does the row-wise shaping: it coalesces labels/help to their identity element and computes the metric_kind and name_valid columns extract_row reads below, so this module no longer parses metric_type strings or validates metric_name itself. Dedup, collision detection, and family-conflict counting stay here because they need the cross-row state of the fold.

Structsยง

ColumnIndices ๐Ÿ”’
Column indices resolved once from the sinkโ€™s source relation.
PendingRegistration ๐Ÿ”’
Active-worker collector registration that tolerates a transient descriptor-id collision with an incarnation of this sink that has not been torn down yet.
SinkCollector ๐Ÿ”’
A prometheus::core::Collector that exposes a metric sinkโ€™s SinkState.
SinkState ๐Ÿ”’
Working and published metric state for one metric sink.

Enumsยง

MetricKind ๐Ÿ”’
Retry ๐Ÿ”’
Whether a registration attempt left a collision the caller must arm a retry for.

Constantsยง

REGISTRATION_ESCALATE_AFTER ๐Ÿ”’
How long a collision may persist before it soft-panics.
REGISTRATION_RETRY_INTERVAL ๐Ÿ”’
How long to wait before retrying a collector registration that collided.

Functionsยง

build_families ๐Ÿ”’
Groups published by metric name into one MetricFamily per name, since Prometheus requires a single type and help string per family. Within a group, the entry with the lexicographically smallest label vector wins the familyโ€™s type and help string; BTreeMapโ€™s (name, labels) key ordering already sorts each group that way, so the first entry seen for a given name is that winner.
count_conflicts ๐Ÿ”’
Counts published series whose own metric_type/help disagree with their familyโ€™s winning type/help. See build_families for how the winner is chosen.
count_skipped ๐Ÿ”’
Counts live working rows dropped for an unsupported metric_type, an invalid Prometheus metric or label name, or a null or empty label value.
extract_row ๐Ÿ”’
Extracts (metric_name, metric_kind, name_valid, sorted labels, value, help) from one shaped source row.
is_publishable_label_value ๐Ÿ”’
Whether a label value can be published as-is. A null (None) has no value to encode, and an empty string reads as absent to Prometheus, so {a => ''} would fold into {}. Both make the row that carries them unpublishable.
is_valid_label_name ๐Ÿ”’
Matches Prometheusโ€™s label name grammar: [a-zA-Z_][a-zA-Z0-9_]*.
rebuild_published ๐Ÿ”’
Collapses the live, representable rows of working into one published entry per (metric_name, labels) series and counts colliding and null-suppressed series.

Type Aliasesยง

PublishedKey ๐Ÿ”’
Key into SinkState::published: a metric name paired with its sorted label vector.
PublishedValue ๐Ÿ”’
Value in SinkState::published: the seriesโ€™ value, kind, and help string.
RowKey ๐Ÿ”’
Full identity of one source row: metric name, sorted labels, value, metric kind, name validity, and help.