Skip to content

feat(traceql): scale sampled metrics by 1/f - #1088

Open
44YHC wants to merge 2 commits into
feat/traceql-structural-opsfrom
feat/traceql-sample-scaling
Open

44YHC wants to merge 2 commits into
feat/traceql-structural-opsfrom
feat/traceql-sample-scaling

Conversation

@44YHC

@44YHC 44YHC commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #1034's open question on sampled metrics. Based on feat/traceql-structural-ops; merges into it as a merge commit.

Summary

  • Factor 1/f from the with(sample=f) hint, not an observed ratio, the same under span and trace hashing.
  • Scaled: rate, count_over_time, sum_over_time, histogram_over_time heights (not bounds), and compare() selection and baseline counts.
  • Not scaled: min_over_time, max_over_time, avg_over_time, quantile_over_time.
  • In SQL. Scale float64 (1 without a hint) on the metrics and compare requests, set from SampleFraction() beside the sample filter. Scaled functions are wrapped as (expr) * k, rate folds the scale into its divisor, and the histogram scales only its count. compare() counts become Float64. Scale 1 renders byte-identical SQL. A hint so small that its hash threshold is 0 renders unsampled SQL.
  • Exemplars. An exemplar on rate and count_over_time has as its value the series point of its step, which is scaled, so it sits on the plotted line. Exemplars of the other functions keep their unscaled values.
  • README: the Differences from Tempo entry says sampled metrics scale by 1/f.

Breaking changes

None: the sample hint is new in #1034.

Upgrade notes

None.

Evidence

  • Plan tests pin the scaled and unscaled shapes and byte-identical SQL at scale 1. TestExemplarValueUnderScaling pins the exemplar rule.
  • go test ./... passes. The full e2e suite and grid.traceql pass on the full stack tip, against tests Is /loki/api/v1/push Schema different from Loki on purpose? #24, whose grid oracle scales by 1/f.

Merge Danger

Door: two-way.

Blast Radius: metrics and compare() with a sample hint.

44YHC added 2 commits November 6, 2026 04:52
with(sample=f) volume metrics are comparable with unsampled ones: rate
folds the factor into its divisor, count_over_time and sum_over_time
multiply, the histogram scales its heights and not its bounds, and
compare() scales both counts. min_over_time, max_over_time, avg_over_time,
quantile_over_time and exemplars stay as they are.

The factor comes from the hint, so it is the same under span and trace
hashing. Scale 1 renders byte-identical SQL. Histogram heights and
compare() counts are read as Float64, since a scale that is not a whole
number gives non-integer values.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant