pub fn duplicates_canonical_labels(
node: &NativeNode,
source_tags: &[Vec<String>],
source_metrics: &[Option<Arc<str>>],
) -> boolExpand description
Whether this tree can hand over two series that share one canonical label set.
A canonical label set is the identity a NativeExpr::Merge groups by: the metric name plus the
ordinary labels, which is exactly what [SeriesLabels] holds. One scan partition holds one
series per such set - a stored series is one identity, and the scan splits rows by storage key
rather than by label set - so only a computation that writes an existing label, or drops one,
can turn two of those identities into one. A label_replace or a label_join writes one, and it
may name the very label that told its input’s series apart; a range function that drops the
metric name, and timestamp in either of its forms, drop one.
The rewrite is judged by the labels it writes and the ones its input carries, which is why the
caller supplies what it knows about each source’s tags, indexed by the source_index the leaves
were bound to: a destination that names no ordinary label of the input writes a fresh one, and a
fresh ordinary label cannot make two series equal. That is the difference between
label_replace(x, "dst", "$1", "host", "(.*)") - which no merge has to collect - and
label_replace(x, "host", "same", "host", ".*"), which folds every series of x into one label
set.
A source’s entry is its complete runtime label set, so __name__ is one of its labels whenever
its series carry a name - a scan bound to one metric names every series from its binding. That is
what makes label_replace(x, "__name__", "same", "__name__", ".*") a rewrite of an existing
label: two metrics whose ordinary labels are equal can be told apart by name alone, and rewriting
that name folds them into one identity. A name write is collected even when the derived set no
longer carries __name__ - after abs, a timestamp or a range function dropped it - because
the scan below those kernels can still hold several metrics whose ordinary labels are equal, and
writing one name puts them under one identity; the walk has no proof that the input reads a
single metric, so the conservative answer is the one that collects.
Everything else either keeps the set it read or answers a set of its own:
- A map of math drops the metadata labels, and so do a histogram map, a parameterized map, an
arithmetic or
boolscalar broadcast, a range function that computes its result and atimestampin either of its forms. Such a node is judged by the labels it and its input report (metadata_labels_keep_series_apart): a source bound to one metric names every series it hands over, so the name the drop removes told none of them apart, and a source that may hand over several is collected. A key column that holdsNULLin one series and''in another is not part of that proof - see the doc comment of the function - so a drop whose labels prove it is never collected for the storage keys alone. - An
Aggregateanswers its groups, aVectorthat folds series answers its result sets, and aBinarythat reads whole vectors files its rows by the label set a sample ends under and refuses two values of a field at one point. ASetdoes the same, andinfomerges the results that share a label set. Each answers one series per set it names. - A
Windowthat drops the metadata labels, and the two timestamps, claim one of their own: the name is part of the identity a merge groups by, so two series that shared every other label are one label set from there on - unless the labels tell them apart by the same rule the kernels above are judged by. - A
Mergeat or below a drop answers nothing for it (canonical_below): a merge hands over one series per canonical label set, but the labels that tell two of its series apart still have to prove the drop. A chain of drops over one metric is therefore collected once per collision the labels do not prove, and not at all when they do. - A node that hands its input’s series over unchanged - a selection, a name-keeping window,
topkand its ranking siblings - passes the answer on: an alias below it is still an alias above it.
This is the fact merge_label_rewrites
inserts a Merge for: a consumer that reads a whole label set cannot answer from pieces, and this
says where pieces of one set can exist at all. A Merge is the collection itself, so it answers
false - which is what makes the pass idempotent.