Debian Codegraph @

zpages/boundaries.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package zpages // import "go.opentelemetry.io/contrib/zpages"
5
6 import (
7 "slices"
8 "time"
9 )
10
11 const (
12 zeroDuration = time.Duration(0)
13 maxDuration = time.Duration(1<<63 - 1)
14 )
15
16 var defaultBoundaries = newBoundaries([]time.Duration{
17 10 * time.Microsecond,
18 100 * time.Microsecond,
19 time.Millisecond,
20 10 * time.Millisecond,
21 100 * time.Millisecond,
22 time.Second,
23 10 * time.Second,
24 100 * time.Second,
25 })
26
27 // boundaries represents the interval bounds for the latency based samples.
28 type boundaries struct {
29 durations []time.Duration
30 }
31
32 // newBoundaries returns a new boundaries.
33 func newBoundaries(durations []time.Duration) *boundaries {
34 slices.Sort(durations)
35 return &boundaries{durations: durations}
36 }
37
38 // numBuckets returns the number of buckets needed for these boundaries.
39 func (lb boundaries) numBuckets() int {
40 return len(lb.durations) + 1
41 }
42
43 // getBucketIndex returns the appropriate bucket index for a given latency.
44 func (lb boundaries) getBucketIndex(latency time.Duration) int {
45 i := 0
46 for i < len(lb.durations) && latency >= lb.durations[i] {
47 i++
48 }
49 return i
50 }