forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum_hints.go
More file actions
99 lines (78 loc) · 1.79 KB
/
enum_hints.go
File metadata and controls
99 lines (78 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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"
HintDedupe = "dedupe"
HintJobInterval = "job_interval"
HintJobSize = "job_size"
HintTimeOverlapCutoff = "time_overlap_cutoff"
HintConcurrentBlocks = "concurrent_blocks"
)
func isUnsafe(h string) bool {
switch h {
case HintSample:
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.F, ok
}
// If float not found, then try integer.
if v, ok := h.Get(k, TypeInt, allowUnsafe); ok {
return float64(v.N), ok
}
return
}
func (h *Hints) GetInt(k string, allowUnsafe bool) (v int, ok bool) {
if v, ok := h.Get(k, TypeInt, allowUnsafe); ok {
return v.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 {
return v.D, ok
}
return
}
func (h *Hints) GetBool(k string, allowUnsafe bool) (v, ok bool) {
if v, ok := h.Get(k, TypeBoolean, allowUnsafe); ok {
return v.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)