tempo/pkg/traceql/enum_hints.go
Joe Elliott 6c07024064 Add TraceQL query hint to retrieve most recent results ordered by trace start time (#4238)
* Added ordered results

Signed-off-by: Joe Elliott <number101010@gmail.com>

* add most_recent query hint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* changelog, docs and lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* e2e tests - fixed tag search

Signed-off-by: Joe Elliott <number101010@gmail.com>

* lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* remove clone changes

Signed-off-by: Joe Elliott <number101010@gmail.com>

* review

Signed-off-by: Joe Elliott <number101010@gmail.com>

* make shards configurable

Signed-off-by: Joe Elliott <number101010@gmail.com>

* dont mess with me lint. i will uninstall you

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Make all endpoints search backwards in time

Signed-off-by: Joe Elliott <number101010@gmail.com>

* nice work on this one carles

Signed-off-by: Joe Elliott <number101010@gmail.com>

* consolidate block meta functions

Signed-off-by: Joe Elliott <number101010@gmail.com>

* fix merge :P

Signed-off-by: Joe Elliott <number101010@gmail.com>

* remove tests

Signed-off-by: Joe Elliott <number101010@gmail.com>

* don't bother tracking normal searches

Signed-off-by: Joe Elliott <number101010@gmail.com>

---------

Signed-off-by: Joe Elliott <number101010@gmail.com>
2025-02-12 16:33:10 -05:00

104 lines
2.0 KiB
Go

package traceql
import (
"time"
)
// The list of all traceql query hints. Although most of these are implementation-specific
// and not part of the language or engine, we organize them here in one place.
const (
HintSample = "sample"
HintJobSize = "job_size"
HintTimeOverlapCutoff = "time_overlap_cutoff"
HintConcurrentBlocks = "concurrent_blocks"
HintExemplars = "exemplars"
HintMostRecent = "most_recent" // traceql search hint to return most recent results ordered by time
)
func isUnsafe(h string) bool {
switch h {
case HintSample, HintExemplars, HintMostRecent:
return false
default:
return true
}
}
type Hint struct {
Name string
Value Static
}
func newHint(k string, v Static) *Hint {
return &Hint{k, v}
}
type Hints struct {
Hints []*Hint
}
func newHints(h []*Hint) *Hints {
return &Hints{h}
}
func (h *Hints) GetFloat(k string, allowUnsafe bool) (v float64, ok bool) {
if v, ok := h.Get(k, TypeFloat, allowUnsafe); ok {
return v.Float(), ok
}
// If float not found, then try integer.
if v, ok := h.Get(k, TypeInt, allowUnsafe); ok {
n, _ := v.Int()
return float64(n), ok
}
return
}
func (h *Hints) GetInt(k string, allowUnsafe bool) (v int, ok bool) {
if v, ok := h.Get(k, TypeInt, allowUnsafe); ok {
n, _ := v.Int()
return n, ok
}
return
}
func (h *Hints) GetDuration(k string, allowUnsafe bool) (v time.Duration, ok bool) {
if v, ok := h.Get(k, TypeDuration, allowUnsafe); ok {
d, _ := v.Duration()
return d, ok
}
return
}
func (h *Hints) GetBool(k string, allowUnsafe bool) (v, ok bool) {
if v, ok := h.Get(k, TypeBoolean, allowUnsafe); ok {
b, _ := v.Bool()
return b, ok
}
return
}
func (h *Hints) Get(k string, t StaticType, allowUnsafe bool) (v Static, ok bool) {
if h == nil {
return
}
if isUnsafe(k) && !allowUnsafe {
return
}
for _, hh := range h.Hints {
if hh.Name == k && hh.Value.Type == t {
return hh.Value, true
}
}
return
}
var _ Element = (*Hints)(nil)