forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistinct_value_collector_test.go
More file actions
74 lines (63 loc) · 1.84 KB
/
distinct_value_collector_test.go
File metadata and controls
74 lines (63 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package collector
import (
"fmt"
"sort"
"strconv"
"testing"
"github.com/grafana/tempo/pkg/tempopb"
"github.com/stretchr/testify/require"
)
func TestDistinctValueCollectorDiff(t *testing.T) {
d := NewDistinctValueWithDiff[string](0, func(s string) int { return len(s) })
d.Collect("123")
d.Collect("4567")
stringsSlicesEqual(t, []string{"123", "4567"}, d.Diff())
stringsSlicesEqual(t, []string{}, d.Diff())
d.Collect("123")
d.Collect("890")
stringsSlicesEqual(t, []string{"890"}, d.Diff())
stringsSlicesEqual(t, []string{}, d.Diff())
}
func stringsSlicesEqual(t *testing.T, a, b []string) {
sort.Strings(a)
sort.Strings(b)
require.Equal(t, a, b)
}
func BenchmarkCollect(b *testing.B) {
// simulate 100 ingesters, each returning 10_000 tag values
numIngesters := 100
numTagValuesPerIngester := 10_000
ingesterTagValues := make([][]tempopb.TagValue, numIngesters)
for i := 0; i < numIngesters; i++ {
tagValues := make([]tempopb.TagValue, numTagValuesPerIngester)
for j := 0; j < numTagValuesPerIngester; j++ {
tagValues[j] = tempopb.TagValue{
Type: "string",
Value: fmt.Sprintf("value_%d_%d", i, j),
}
}
ingesterTagValues[i] = tagValues
}
limits := []int{
0, // no limit
100_000, // 100KB
1_000_000, // 1MB
10_000_000, // 10MB
}
b.ResetTimer() // to exclude the setup time for generating tag values
for _, lim := range limits {
b.Run("limit:"+strconv.Itoa(lim), func(b *testing.B) {
for n := 0; n < b.N; n++ {
// NewDistinctValue is collecting tag values without diff support
distinctValues := NewDistinctValue(lim, func(v tempopb.TagValue) int { return len(v.Type) + len(v.Value) })
for _, tagValues := range ingesterTagValues {
for _, v := range tagValues {
if distinctValues.Collect(v) {
break // stop early if limit is reached
}
}
}
}
})
}
}