Skip to content

Commit 36dbfe6

Browse files
committed
Add Benchmark for multiple sources
Signed-off-by: Coleen Iona Quadros <[email protected]>
1 parent 4d97c9a commit 36dbfe6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

inhibit/inhibit_bench_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ func BenchmarkMutes(b *testing.B) {
7676
b.Run("10000 inhibition rules, last rule matches", func(b *testing.B) {
7777
benchmarkMutes(b, lastRuleMatchesBenchmark(b, 10000))
7878
})
79+
b.Run("10 inhibition rules, 5 sources, 100 inhibiting alerts", func(b *testing.B) {
80+
benchmarkMutes(b, manySourcesBenchMark(b, 5, 10, 100))
81+
})
82+
b.Run("100 inhibition rules, 10 sources, 1000 inhibiting alerts", func(b *testing.B) {
83+
benchmarkMutes(b, manySourcesBenchMark(b, 10, 100, 1000))
84+
})
85+
b.Run("1000 inhibition rules, 20 sources, 100 inhibiting alerts", func(b *testing.B) {
86+
benchmarkMutes(b, manySourcesBenchMark(b, 20, 1000, 1000))
87+
})
7988
}
8089

8190
// benchmarkOptions allows the declaration of a wide range of benchmarks.
@@ -189,6 +198,47 @@ func lastRuleMatchesBenchmark(b *testing.B, n int) benchmarkOptions {
189198
}
190199
}
191200

201+
func manySourcesBenchMark(b *testing.B, numSources, numInhibitionRules, numInhibitingAlerts int) benchmarkOptions {
202+
return benchmarkOptions{
203+
n: numInhibitionRules,
204+
newRuleFunc: func(idx int) config.InhibitRule {
205+
sources := []config.Source{}
206+
for i := 0; i < numSources; i++ {
207+
sources = append(sources, config.Source{
208+
SrcMatchers: config.Matchers{
209+
mustNewMatcher(b, labels.MatchEqual, "src", strconv.Itoa(i)),
210+
},
211+
})
212+
}
213+
return config.InhibitRule{
214+
Sources: sources,
215+
TargetMatchers: config.Matchers{
216+
mustNewMatcher(b, labels.MatchEqual, "dst", "0"),
217+
},
218+
}
219+
},
220+
newAlertsFunc: func(idx int, _ config.InhibitRule) []types.Alert {
221+
var alerts []types.Alert
222+
for i := 0; i < numInhibitingAlerts; i++ {
223+
alerts = append(alerts, types.Alert{
224+
Alert: model.Alert{
225+
Labels: model.LabelSet{
226+
"src": model.LabelValue(strconv.Itoa(idx)),
227+
"idx": model.LabelValue(strconv.Itoa(i)),
228+
},
229+
},
230+
})
231+
}
232+
return alerts
233+
}, benchFunc: func(mutesFunc func(set model.LabelSet) bool) error {
234+
if ok := mutesFunc(model.LabelSet{"dst": "0"}); !ok {
235+
return errors.New("expected dst=0 to be muted")
236+
}
237+
return nil
238+
},
239+
}
240+
}
241+
192242
func benchmarkMutes(b *testing.B, opts benchmarkOptions) {
193243
r := prometheus.NewRegistry()
194244
m := types.NewMarker(r)

0 commit comments

Comments
 (0)