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)
| 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. |
| 55 | func (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. |
| 96 | func (d *ScopedDistinctString) Strings() map[string][]string { |