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

Method Collect

pkg/collector/scoped_distinct_string.go:55–93  ·  view source on GitHub ↗

Collect adds a new value to the distinct string collector. returns true when it reaches the limits and can't fit more values. can be used to stop early during Collect without calling Exceeded.

(scope string, val string)

Source from the content-addressed store, hash-verified

53// returns true when it reaches the limits and can't fit more values.
54// can be used to stop early during Collect without calling Exceeded.
55func (d *ScopedDistinctString) Collect(scope string, val string) (exceeded bool) {
56 d.mtx.Lock()
57 defer d.mtx.Unlock()
58
59 if d.limExceeded {
60 return true
61 }
62
63 valueLen := len(val)
64 // can it fit?
65 if d.maxDataSize > 0 && d.currDataSize+valueLen > d.maxDataSize {
66 // No
67 d.limExceeded = true
68 return true
69 }
70
71 // get or create collector
72 col, ok := d.cols[scope]
73 if !ok {
74 if scope == IntrinsicScope {
75 col = d.newCol(0, 0, 0)
76 } else {
77 col = d.newCol(0, d.maxTagsPerScope, d.maxCacheHits)
78 }
79 d.cols[scope] = col
80 }
81
82 // add valueLen if we successfully added the value
83 if col.Collect(val) {
84 d.currDataSize += valueLen
85 }
86 if col.Exceeded() {
87 // we stop if one of the scopes exceed the limit
88 d.limExceeded = true
89 d.stopReason = col.stopReason
90 return true
91 }
92 return false
93}
94
95// Strings returns the final list of distinct values collected and sorted.
96func (d *ScopedDistinctString) Strings() map[string][]string {

Callers 15

SearchTagsMethod · 0.95
tagNamesRunnerFunction · 0.95
TestFetchTagNamesFunction · 0.95
BenchmarkFetchTagsFunction · 0.95
TestFetchTagNamesFunction · 0.95
BenchmarkFetchTagsFunction · 0.95
TestFetchTagNamesFunction · 0.95
BenchmarkFetchTagsFunction · 0.95
naiveTagsV2CombineFunction · 0.95

Calls 2

CollectMethod · 0.65
ExceededMethod · 0.45

Tested by 15

tagNamesRunnerFunction · 0.76
TestFetchTagNamesFunction · 0.76
BenchmarkFetchTagsFunction · 0.76
TestFetchTagNamesFunction · 0.76
BenchmarkFetchTagsFunction · 0.76
TestFetchTagNamesFunction · 0.76
BenchmarkFetchTagsFunction · 0.76
naiveTagsV2CombineFunction · 0.76
TestScopedDistinctFunction · 0.76