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

Function newBucketSet

pkg/traceql/util.go:85–107  ·  view source on GitHub ↗

newBucketSet creates a new bucket set for the given time range start and end are in nanoseconds

(exemplars uint32, start, end uint64)

Source from the content-addressed store, hash-verified

83// newBucketSet creates a new bucket set for the given time range
84// start and end are in nanoseconds
85func newBucketSet(exemplars uint32, start, end uint64) *limitedBucketSet {
86 buckets := exemplars / maxExemplarsPerBucket
87 if buckets == 0 { // edge case for few exemplars
88 buckets = 1
89 }
90
91 // convert nanoseconds to milliseconds
92 start /= uint64(time.Millisecond.Nanoseconds()) //nolint: gosec // G115
93 end /= uint64(time.Millisecond.Nanoseconds()) //nolint: gosec // G115
94
95 interval := end - start
96 bucketWidth := max(interval/uint64(buckets), 1)
97
98 return &limitedBucketSet{
99 sz: int(buckets),
100 maxTotal: int(exemplars),
101 maxBucket: maxExemplarsPerBucket,
102 buckets: make([]int, buckets+1), // +1 for total count
103 start: start,
104 end: end,
105 bucketWidth: bucketWidth,
106 }
107}
108
109func (b *limitedBucketSet) len() int {
110 return b.buckets[b.sz]

Callers 6

TestBucketSet_BucketFunction · 0.85
TestBucketSetFunction · 0.85
newExemplarBucketSetFunction · 0.85

Calls

no outgoing calls

Tested by 5

TestBucketSet_BucketFunction · 0.68
TestBucketSetFunction · 0.68