MCPcopy
hub / github.com/grafana/tempo / assignExemplarToQuantile

Method assignExemplarToQuantile

pkg/traceql/engine_metrics.go:2013–2031  ·  view source on GitHub ↗

assignExemplarToQuantile determines which quantile (if any) an exemplar should be assigned to. Returns the quantile index, or -1 if the exemplar doesn't fit any quantile reasonably well. This uses a simple closest-match strategy with reasonable bucket validation.

(exemplarValue float64, quantileValues []float64, buckets []HistogramBucket)

Source from the content-addressed store, hash-verified

2011// Returns the quantile index, or -1 if the exemplar doesn't fit any quantile reasonably well.
2012// This uses a simple closest-match strategy with reasonable bucket validation.
2013func (h *HistogramAggregator) assignExemplarToQuantile(exemplarValue float64, quantileValues []float64, buckets []HistogramBucket) int {
2014 if len(quantileValues) == 0 || len(buckets) == 0 {
2015 return -1
2016 }
2017
2018 bestIdx := -1
2019 bestDiff := math.Inf(1)
2020
2021 for i, quantileValue := range quantileValues {
2022 // Find the closest quantile value for better visual alignment
2023 diff := math.Abs(exemplarValue - quantileValue)
2024 if diff < bestDiff {
2025 bestDiff = diff
2026 bestIdx = i
2027 }
2028 }
2029
2030 return bestIdx
2031}
2032
2033func (h *HistogramAggregator) Length() int {
2034 return len(h.ss) * len(h.qs)

Callers 1

ResultsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected