@@ -28,65 +28,70 @@ import (
28
28
"github.com/open-telemetry/opentelemetry-operator/cmd/otel-allocator/internal/target"
29
29
)
30
30
31
+ var targetCounts = []int {1000 , 10000 , 100000 , 800000 }
32
+
31
33
// BenchmarkProcessTargets benchmarks the whole target allocation pipeline. It starts with data the prometheus
32
34
// discovery manager would normally output, and pushes it all the way into the allocator. It notably doe *not* check
33
35
// the HTTP server afterward. Test data is chosen to be reasonably representative of what the Prometheus service discovery
34
36
// outputs in the real world.
35
37
func BenchmarkProcessTargets (b * testing.B ) {
36
- numTargets := 800000
37
38
targetsPerGroup := 5
38
39
groupsPerJob := 20
39
- tsets := prepareBenchmarkData (numTargets , targetsPerGroup , groupsPerJob )
40
- for _ , strategy := range allocation .GetRegisteredAllocatorNames () {
41
- b .Run (strategy , func (b * testing.B ) {
42
- targetDiscoverer := createTestDiscoverer (strategy , map [string ][]* relabel.Config {})
43
- targetDiscoverer .UpdateTsets (tsets )
44
- b .ResetTimer ()
45
- for i := 0 ; i < b .N ; i ++ {
46
- targetDiscoverer .Reload ()
47
- }
48
- })
40
+ for _ , numTargets := range targetCounts {
41
+ tsets := prepareBenchmarkData (numTargets , targetsPerGroup , groupsPerJob )
42
+ for _ , strategy := range allocation .GetRegisteredAllocatorNames () {
43
+ b .Run (fmt .Sprintf ("%s/%d" , strategy , numTargets ), func (b * testing.B ) {
44
+ targetDiscoverer := createTestDiscoverer (strategy , map [string ][]* relabel.Config {})
45
+ targetDiscoverer .UpdateTsets (tsets )
46
+ b .ResetTimer ()
47
+ for i := 0 ; i < b .N ; i ++ {
48
+ targetDiscoverer .Reload ()
49
+ }
50
+ })
51
+ }
49
52
}
50
53
}
51
54
52
55
// BenchmarkProcessTargetsWithRelabelConfig is BenchmarkProcessTargets with a relabel config set. The relabel config
53
56
// does not actually modify any records, but does force the prehook to perform any necessary conversions along the way.
54
57
func BenchmarkProcessTargetsWithRelabelConfig (b * testing.B ) {
55
- numTargets := 800000
56
58
targetsPerGroup := 5
57
59
groupsPerJob := 20
58
- tsets := prepareBenchmarkData (numTargets , targetsPerGroup , groupsPerJob )
59
- prehookConfig := make (map [string ][]* relabel.Config , len (tsets ))
60
- for jobName := range tsets {
61
- // keep all targets in half the jobs, drop the rest
62
- jobNrStr := strings .Split (jobName , "-" )[1 ]
63
- jobNr , err := strconv .Atoi (jobNrStr )
64
- require .NoError (b , err )
65
- var action relabel.Action
66
- if jobNr % 2 == 0 {
67
- action = "keep"
68
- } else {
69
- action = "drop"
60
+ for _ , numTargets := range targetCounts {
61
+ tsets := prepareBenchmarkData (numTargets , targetsPerGroup , groupsPerJob )
62
+ prehookConfig := make (map [string ][]* relabel.Config , len (tsets ))
63
+ for jobName := range tsets {
64
+ // keep all targets in half the jobs, drop the rest
65
+ jobNrStr := strings .Split (jobName , "-" )[1 ]
66
+ jobNr , err := strconv .Atoi (jobNrStr )
67
+ require .NoError (b , err )
68
+ var action relabel.Action
69
+ if jobNr % 2 == 0 {
70
+ action = "keep"
71
+ } else {
72
+ action = "drop"
73
+ }
74
+ prehookConfig [jobName ] = []* relabel.Config {
75
+ {
76
+ Action : action ,
77
+ Regex : relabel .MustNewRegexp (".*" ),
78
+ SourceLabels : model.LabelNames {"__address__" },
79
+ },
80
+ }
70
81
}
71
- prehookConfig [jobName ] = []* relabel.Config {
72
- {
73
- Action : action ,
74
- Regex : relabel .MustNewRegexp (".*" ),
75
- SourceLabels : model.LabelNames {"__address__" },
76
- },
82
+
83
+ for _ , strategy := range allocation .GetRegisteredAllocatorNames () {
84
+ b .Run (fmt .Sprintf ("%s/%d" , strategy , numTargets ), func (b * testing.B ) {
85
+ targetDiscoverer := createTestDiscoverer (strategy , prehookConfig )
86
+ targetDiscoverer .UpdateTsets (tsets )
87
+ b .ResetTimer ()
88
+ for i := 0 ; i < b .N ; i ++ {
89
+ targetDiscoverer .Reload ()
90
+ }
91
+ })
77
92
}
78
93
}
79
94
80
- for _ , strategy := range allocation .GetRegisteredAllocatorNames () {
81
- b .Run (strategy , func (b * testing.B ) {
82
- targetDiscoverer := createTestDiscoverer (strategy , prehookConfig )
83
- targetDiscoverer .UpdateTsets (tsets )
84
- b .ResetTimer ()
85
- for i := 0 ; i < b .N ; i ++ {
86
- targetDiscoverer .Reload ()
87
- }
88
- })
89
- }
90
95
}
91
96
92
97
func prepareBenchmarkData (numTargets , targetsPerGroup , groupsPerJob int ) map [string ][]* targetgroup.Group {
@@ -140,7 +145,10 @@ func prepareBenchmarkData(numTargets, targetsPerGroup, groupsPerJob int) map[str
140
145
}
141
146
targets := []model.LabelSet {}
142
147
for i := 0 ; i < numTargets ; i ++ {
143
- targets = append (targets , exampleTarget .Clone ())
148
+ newTarget := exampleTarget .Clone ()
149
+ // ensure each target has a unique label to avoid deduplication
150
+ newTarget ["target_id" ] = model .LabelValue (strconv .Itoa (i ))
151
+ targets = append (targets , newTarget )
144
152
}
145
153
groups := make ([]* targetgroup.Group , numGroups )
146
154
for i := 0 ; i < numGroups ; i ++ {
0 commit comments