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

Function newCardinality

modules/generator/registry/cardinality.go:57–87  ·  view source on GitHub ↗
(precision uint8, staleTime, sketchDuration time.Duration)

Source from the content-addressed store, hash-verified

55}
56
57func newCardinality(precision uint8, staleTime, sketchDuration time.Duration) *Cardinality {
58 // If parameters are out of bounds, set defaults.
59 if precision < 4 || precision > 18 {
60 precision = 14
61 }
62 if staleTime <= 1*time.Minute || sketchDuration < 1*time.Minute || staleTime < sketchDuration {
63 staleTime = 15 * time.Minute
64 sketchDuration = 5 * time.Minute
65 }
66
67 sketchesLength := int((staleTime + sketchDuration) / sketchDuration) // ceil
68 if sketchesLength < 2 {
69 sketchesLength = 2
70 }
71
72 sketches := make([]*hll.Sketch, sketchesLength)
73 for i := range sketches {
74 sketches[i], _ = hll.NewSketch(precision, true)
75 }
76
77 cachedMerge, _ := hll.NewSketch(precision, true)
78 return &Cardinality{
79 sketchDuration: sketchDuration,
80 sketchesLength: sketchesLength,
81 current: 0,
82 sketches: sketches,
83 cachedMerge: cachedMerge,
84 lastAdvance: time.Now(),
85 precision: precision,
86 }
87}
88
89func (c *Cardinality) Insert(hash uint64) {
90 c.mu.Lock()

Callers 1

NewCardinalityFunction · 0.85

Calls 1

NowMethod · 0.65

Tested by

no test coverage detected