@@ -35,34 +35,46 @@ import (
35
35
// for different numbers of inhibition rules.
36
36
func BenchmarkMutes (b * testing.B ) {
37
37
b .Run ("1 inhibition rule, 1 inhibiting alert" , func (b * testing.B ) {
38
- benchmarkMutes (b , defaultBenchmark (b , 1 , 1 ))
38
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 1 , 1 ))
39
39
})
40
40
b .Run ("10 inhibition rules, 1 inhibiting alert" , func (b * testing.B ) {
41
- benchmarkMutes (b , defaultBenchmark (b , 10 , 1 ))
41
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 10 , 1 ))
42
42
})
43
43
b .Run ("100 inhibition rules, 1 inhibiting alert" , func (b * testing.B ) {
44
- benchmarkMutes (b , defaultBenchmark (b , 100 , 1 ))
44
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 100 , 1 ))
45
45
})
46
46
b .Run ("1000 inhibition rules, 1 inhibiting alert" , func (b * testing.B ) {
47
- benchmarkMutes (b , defaultBenchmark (b , 1000 , 1 ))
47
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 1000 , 1 ))
48
48
})
49
49
b .Run ("10000 inhibition rules, 1 inhibiting alert" , func (b * testing.B ) {
50
- benchmarkMutes (b , defaultBenchmark (b , 10000 , 1 ))
50
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 10000 , 1 ))
51
51
})
52
52
b .Run ("1 inhibition rule, 10 inhibiting alerts" , func (b * testing.B ) {
53
- benchmarkMutes (b , defaultBenchmark (b , 1 , 10 ))
53
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 1 , 10 ))
54
54
})
55
55
b .Run ("1 inhibition rule, 100 inhibiting alerts" , func (b * testing.B ) {
56
- benchmarkMutes (b , defaultBenchmark (b , 1 , 100 ))
56
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 1 , 100 ))
57
57
})
58
58
b .Run ("1 inhibition rule, 1000 inhibiting alerts" , func (b * testing.B ) {
59
- benchmarkMutes (b , defaultBenchmark (b , 1 , 1000 ))
59
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 1 , 1000 ))
60
60
})
61
61
b .Run ("1 inhibition rule, 10000 inhibiting alerts" , func (b * testing.B ) {
62
- benchmarkMutes (b , defaultBenchmark (b , 1 , 10000 ))
62
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 1 , 10000 ))
63
63
})
64
64
b .Run ("100 inhibition rules, 1000 inhibiting alerts" , func (b * testing.B ) {
65
- benchmarkMutes (b , defaultBenchmark (b , 100 , 1000 ))
65
+ benchmarkMutes (b , allRulesMatchBenchmark (b , 100 , 1000 ))
66
+ })
67
+ b .Run ("10 inhibition rules, last rule matches" , func (b * testing.B ) {
68
+ benchmarkMutes (b , lastRuleMatchesBenchmark (b , 10 ))
69
+ })
70
+ b .Run ("100 inhibition rules, last rule matches" , func (b * testing.B ) {
71
+ benchmarkMutes (b , lastRuleMatchesBenchmark (b , 100 ))
72
+ })
73
+ b .Run ("1000 inhibition rules, last rule matches" , func (b * testing.B ) {
74
+ benchmarkMutes (b , lastRuleMatchesBenchmark (b , 1000 ))
75
+ })
76
+ b .Run ("10000 inhibition rules, last rule matches" , func (b * testing.B ) {
77
+ benchmarkMutes (b , lastRuleMatchesBenchmark (b , 10000 ))
66
78
})
67
79
}
68
80
@@ -79,19 +91,20 @@ type benchmarkOptions struct {
79
91
benchFunc func (mutesFunc func (model.LabelSet ) bool ) error
80
92
}
81
93
82
- // defaultBenchmark returns the default benchmark. It supports a number of
83
- // variations, including customization of the number of inhibition rules,
84
- // and the number of inhibiting alerts per inhibition rule.
94
+ // allRulesMatchBenchmark returns a new benchmark where all inhibition rules
95
+ // inhibit the label dst=0. It supports a number of variations, including
96
+ // customization of the number of inhibition rules, and the number of
97
+ // inhibiting alerts per inhibition rule.
85
98
//
86
99
// The source matchers are suffixed with the position of the inhibition rule
87
- // in the list. For example, src=1, src=2, etc. The target matchers are
88
- // the same across all inhibition rules (dst=0).
100
+ // in the list (e.g. src=1, src=2, etc...). The target matchers are the same
101
+ // across all inhibition rules (dst=0).
89
102
//
90
103
// Each inhibition rule can have zero or more alerts that match the source
91
104
// matchers, and is determined with numInhibitingAlerts.
92
105
//
93
- // The default benchmark expects dst=0 to be muted and will fail if not.
94
- func defaultBenchmark (b * testing.B , numInhibitionRules , numInhibitingAlerts int ) benchmarkOptions {
106
+ // It expects dst=0 to be muted and will fail if not.
107
+ func allRulesMatchBenchmark (b * testing.B , numInhibitionRules , numInhibitingAlerts int ) benchmarkOptions {
95
108
return benchmarkOptions {
96
109
n : numInhibitionRules ,
97
110
newRuleFunc : func (idx int ) config.InhibitRule {
@@ -126,6 +139,48 @@ func defaultBenchmark(b *testing.B, numInhibitionRules, numInhibitingAlerts int)
126
139
}
127
140
}
128
141
142
+ // lastRuleMatchesBenchmark returns a new benchmark where the last inhibition
143
+ // rule inhibits the label dst=0. All other inhibition rules are no-ops.
144
+ //
145
+ // The source matchers are suffixed with the position of the inhibition rule
146
+ // in the list (e.g. src=1, src=2, etc...). The target matchers are the same
147
+ // across all inhibition rules (dst=0).
148
+ //
149
+ // It expects dst=0 to be muted and will fail if not.
150
+ func lastRuleMatchesBenchmark (b * testing.B , n int ) benchmarkOptions {
151
+ return benchmarkOptions {
152
+ n : n ,
153
+ newRuleFunc : func (idx int ) config.InhibitRule {
154
+ return config.InhibitRule {
155
+ SourceMatchers : config.Matchers {
156
+ mustNewMatcher (b , labels .MatchEqual , "src" , strconv .Itoa (idx )),
157
+ },
158
+ TargetMatchers : config.Matchers {
159
+ mustNewMatcher (b , labels .MatchEqual , "dst" , "0" ),
160
+ },
161
+ }
162
+ },
163
+ newAlertsFunc : func (idx int , _ config.InhibitRule ) []types.Alert {
164
+ // Do not create an alert unless it is the last inhibition rule.
165
+ if idx < n - 1 {
166
+ return nil
167
+ }
168
+ return []types.Alert {{
169
+ Alert : model.Alert {
170
+ Labels : model.LabelSet {
171
+ "src" : model .LabelValue (strconv .Itoa (idx )),
172
+ },
173
+ },
174
+ }}
175
+ }, benchFunc : func (mutesFunc func (set model.LabelSet ) bool ) error {
176
+ if ok := mutesFunc (model.LabelSet {"dst" : "0" }); ! ok {
177
+ return errors .New ("expected dst=0 to be muted" )
178
+ }
179
+ return nil
180
+ },
181
+ }
182
+ }
183
+
129
184
func benchmarkMutes (b * testing.B , opts benchmarkOptions ) {
130
185
r := prometheus .NewRegistry ()
131
186
m := types .NewMarker (r )
@@ -148,11 +203,7 @@ func benchmarkMutes(b *testing.B, opts benchmarkOptions) {
148
203
go ih .Run ()
149
204
150
205
// Wait some time for the inhibitor to seed its cache.
151
- waitDuration := time .Millisecond * time .Duration (len (alerts ))
152
- if waitDuration > time .Second {
153
- waitDuration = time .Second
154
- }
155
- <- time .After (waitDuration )
206
+ <- time .After (time .Second )
156
207
b .ResetTimer ()
157
208
158
209
for i := 0 ; i < b .N ; i ++ {
0 commit comments