getSortValueFromPair gets the float value used for sorting from samples. If float sample, use sample value. If histogram sample, use histogram sum. This is the same behavior as Prometheus https://github.com/prometheus/prometheus/blob/v2.53.0/promql/functions.go#L1595.
(samples []*pair, i int)
| 278 | // If float sample, use sample value. If histogram sample, use histogram sum. |
| 279 | // This is the same behavior as Prometheus https://github.com/prometheus/prometheus/blob/v2.53.0/promql/functions.go#L1595. |
| 280 | func getSortValueFromPair(samples []*pair, i int) float64 { |
| 281 | if samples[i].s.Histogram != nil { |
| 282 | return samples[i].s.Histogram.Histogram.Sum |
| 283 | } |
| 284 | // Impossible to have both histogram and sample nil. |
| 285 | return samples[i].s.Sample.Value |
| 286 | } |
| 287 | |
| 288 | func sortPlanForQuery(q string) (sortPlan, error) { |
| 289 | expr, err := cortexparser.ParseExpr(q) |