newBucketSet creates a new bucket set for the given time range start and end are in nanoseconds
(exemplars uint32, start, end uint64)
| 83 | // newBucketSet creates a new bucket set for the given time range |
| 84 | // start and end are in nanoseconds |
| 85 | func 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 | |
| 109 | func (b *limitedBucketSet) len() int { |
| 110 | return b.buckets[b.sz] |
no outgoing calls