Repository navigation
Conversation
…es (failing first)
The series key writes each label as `name=value;` without escaping, so
`{a="b", c="d"}` and `{a="b;c=d"}` both read `a=b;c=d;` and the view
executor merges them into one series. These tests pin the fix: the key
is Prometheus' `Labels.String()` text, checked against golden vectors
printed by Go's `strconv.Quote` (tests/golden/series-keys.json).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
`write_series_key` / `attributes_key` wrote labels as `name=value;`
unescaped, so `{a="b", c="d"}` and `{a="b;c=d"}` had one key and the
view executor, the asap_sketches windows and the CMS / CountSketch
label-set items merged them. Each label set is now written as
Prometheus' `model/labels` `Labels.String()` writes it: `{` names sorted,
`, `-joined, `name="value"`, `}`; values quoted as Go's `strconv.Quote`
quotes them; a name that is not a legacy label name quoted too, as
Prometheus 3 does. A value with nothing to escape is copied as is, so
the hot path stays one byte scan.
The executor's identity map (bytes -> series id) is unchanged: the key
is still built only on a point's first sight.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
zzylol
force-pushed
the
fix/series-key-escaping
branch
from
December 2, 2026 15:32
22cf5b6 to
e8b6e15
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.
Summary
name=value;and did not escape values. So{a="b", c="d"}and{a="b;c=d"}both became0||a=b;c=d;, and the view executor merged two series into one: one state, one sketch, with the samples of both. Theasap_sketcheswindows (window.rs,kll_windows.rs) and the CMS / CMS-heap / CountSketch label-set items had the same flaw.Labels.String()writes it:{a="b", c="d"}and{a="b;c=d"}. Names are sorted, values are quoted as Go'sstrconv.Quotequotes them, and names that are not legacy label names are quoted too ({"http.method"="GET"}). Golden vectors printed by Go pin the format.different_attributes_never_share_a_series, 11 attribute sets gave 9 series before and give 11 after. CPU is unchanged within noise:asap-views-benchon q01 with 10,000 series × 10/s × 30 s, pinned to one core, builds the key on every sample in both modes. Median of 3 interleaved rounds: executor 740.1 → 740.3 ns/sample,asap_sketches688.8 → 688.4 ns/sample.Review guide
perf/collector-views-series-intern(collector_views: find a point's series by its attribute bytes (1.27 → 1.11 µs/sample) #62,df6ba01). Stack: Load collector-views.json and write the view identity into OTLP metric metadata #55 → raw_forward: drop the raw samples of metrics only collector views read #56 → Build collector views on ASAPPlanner's executor (collector_views processor) #57 → Collector views: read OTLP in place, filter raw metrics on the bytes, export view counters #59 → collector_views: send late samples within retention as correction states #60 → collector_views: find a point's series by its attribute bytes (1.27 → 1.11 µs/sample) #62 → this PR. The key code (matchers::write_series_key) is onmain, but its main user,SourceMetric::intern_labelsinview_executor.rs, comes in Build collector views on ASAPPlanner's executor (collector_views processor) #57, and collector_views: find a point's series by its attribute bytes (1.27 → 1.11 µs/sample) #62 changed it to run only on a point's first sight. Basing on collector_views: find a point's series by its attribute bytes (1.27 → 1.11 µs/sample) #62 lets the collision test run through the real OTLP decode → identity map → key path. The diff touches no lineage or envelope code, so it does not conflict with collector_views: sequence numbers and delta emission (full, then deltas per window) #61.src/matchers.rs:write_attributes_key,write_label,is_legacy_label_name,write_quoted.tests/runtime.rs,sketches/cms.rsandsketches/countsketch.rs, plus doc comments.CountSketchObservernow checksobs.labels.is_empty()instead of an empty key, because an empty label set is now{}, not"".f91817dadds the failing tests (6 lib tests failed, the executor test gave 9 series for 11 sets).e8b6e15is the fix.Behavior: before → after
The collector runs
collector-views.json= q01 (DDSketch per series, 5 s windows) on metricdata. One OTLP request carries two gauge points in the same window: point 1 has attributesa="b",c="d"; point 2 hasa="b;c=d".0||a=b;c=d;0|{}|{a="b", c="d"}0||a=b;c=d;(same)0|{}|{a="b;c=d"}a="b", c="d"asap.topkkeylabel of a label-set itemhost=h1;{host="h1"}This serves correctness of every collector view and hand-configured sketch: a series' state must hold only that series' samples.
Interfaces
matchers.rs: the signatures are unchanged and the returned text changes. The file format of the key is the interface:tests/golden/series-keys.jsonis new: 18{labels, key}vectors printed by Go 1.25 using Prometheus'stringImpllogic,strconv.QuoteandLegacyValidation.IsValidLabelName.Usage (condensed from
different_attributes_never_share_a_series, which runs it ate8b6e15with 11 sets):Algorithm changes
Series key text
{a="b", c="d"}and{a="b;c=d"}had one key, so their samples were merged into one sketch.aggregate_byorder), pushname,=,value,;.{. For each label, push,if it is not the first, thenname(or"name"quoted when it is not[a-zA-Z_][a-zA-Z0-9_]*), then=, then"value"quoted. Then push}.write_quotedscans the bytes once. If none is a C0 control,",\, DEL or 0xC2 (the lead byte of a C1 control), it copies the text in onepush_str. Otherwise it escapes rune by rune likestrconv.Quote:\" \\ \a \b \f \n \r \t \v,\xNNfor other C0 controls and DEL,\u00NNfor C1 controls.Labels.String()for the 18 golden vectors (attributes_key_is_prometheus_labels_string). It is unambiguous: inside quotes only\escapes and"ends a value, and a label set is braced, so the text parses back to exactly one label list.values_holding_separators_are_different_keysand the executor test check the old collisions.http.method, and the backend translates names when it ingests.strconv.Quote: non-ASCII runes other than C1 controls are written as they are. Go also escapes other non-printable runes such as U+00A0 and U+200B, which needs Unicode tables. This affects only how the key reads, not its uniqueness (non_ascii_runes_other_than_controls_are_written_as_is).Decisions and open questions
Labels.String(), not a byte-separated form. Sources:model/labels/labels_common.gostringImpl(prometheus/prometheus@abe91c0c) writes{, sorted labels joined by,, names quoted when!model.LegacyValidation.IsValidLabelName(name), values viastrconv.AppendQuote, then}.Hash(labels_slicelabels.go) separates names and values with0xff, a byte that cannot occur in UTF-8.lib/storage/metric_name.go(VictoriaMetrics@aaf9fc1f)marshalTagValueescapes bytes 0/1/2 as0 '0',0 '1',0 '2'and ends each tag with byte 1, with a fast path that copies when none occurs.Stringand is shown to users (as theasap.topkkeylabel of a label-set item, and in debugging), so the readable Prometheus text wins. A0xff- or VM-style key would need aVec<u8>key type and would print as control bytes.view_executor,window.rs,kll_windows.rs). Sketch payloads carry item hashes, and CMS-heap payloads carry the item text, but they are rebuilt every window and not stored across restarts. The emitted golden states (tests/golden/collector-views-states.bin,q01/otlp-body.pb) are unchanged: the e2e and golden tests pass with no update. One visible change: a CMS-heap top-kkeylabel built from a label set changes fromhost=h1;to{host="h1"}. The demos' top-k keys are per-attribute values (/new/hot-route), not label sets, so they are unaffected.Verification
Run on a separate build host (Rust 1.100,
--features otap-engine). The rows below are from before the restack. After the restack ontodf6ba01(no conflicts, patch identical),cargo fmt --checkand the changed-part tests were rerun:--libfiltered to matchers/sketches/view_executor gave 61 passed, and--test runtimefiltered to the key tests gave 6 passed.cargo test --libf91817d, 6 lib tests failed anddifferent_attributes_never_share_a_seriesgave 9 of 11 seriescargo test --test runtimecargo test --test kll_windowscargo test --test collector_views_e2e --test otap_pipeline_e2e --test print_capabilitiescargo fmt --check,cargo clippy --features otap-engine --all-targets -- -D warningsunused_dependencieswarning, not from this PRNew tests:
attributes_key_is_prometheus_labels_string: each of the 18 Go-printed vectors, with and withoutaggregate_by. They cover;,=,",\, newline, other controls, the empty value, CJK and emoji, U+0085, dotted, empty and digit-led names, and a value forging"}, b=".values_holding_separators_are_different_keys: 7 sets that collided or could forge quotes give 7 keys, and a label does not move across the resource boundary.non_ascii_runes_other_than_controls_are_written_as_is: pins the one documented difference fromstrconv.Quote.different_attributes_never_share_a_series(extended): 5 more sets through real OTLP decode and the identity map, with every identity hashing alike.Measurement:
asap-views-bench …/q01/collector-views.json MODE 10000 10 30 3,taskset -c 3, 3 interleaved rounds. Measured before the restack onto #62df6ba01: before =13a29d4, after =22cf5b6. The restack left this diff unchanged.observe, key built every sample)asap_sketches, key built every sample)On the e2e
collector_viewspath, #62's identity map means the key is built only once per series, so its cost there is smaller still.Follow-ups
Debugtext (answer_nodes::series_key,window_merge::series_key,baseline_nodes).Debugescapes quotes, so those keys are unambiguous. They are left alone to keep this diff to key construction.seriesattribute joinsk=vwith,. It is display only, not a key.🤖 Generated with Claude Code
https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf