Skip to content

Commit 1a37070

Browse files
committed
refactor test
Signed-off-by: Coleen Iona Quadros <coleen.quadros27@gmail.com>
1 parent 5f58001 commit 1a37070

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,9 @@ type InhibitRule struct {
978978
SourceMatchRE MatchRegexps `yaml:"source_match_re,omitempty" json:"source_match_re,omitempty"`
979979
// SourceMatchers defines a set of label matchers that have to be fulfilled for source alerts.
980980
SourceMatchers Matchers `yaml:"source_matchers,omitempty" json:"source_matchers,omitempty"`
981-
// Sources defines a set of source matchers and equal labels.
982-
Sources []Source `yaml:"source,omitempty" json:"source,omitempty"`
981+
// Sources defines a set of source matchers and equal labels for source alerts.
982+
// All Source entries have to match for the inhibition to take effect.
983+
Sources []Source `yaml:"sources,omitempty" json:"sources,omitempty"`
983984
// TargetMatch defines a set of labels that have to equal the given
984985
// value for target alerts. Deprecated. Remove before v1.0 release.
985986
TargetMatch map[string]string `yaml:"target_match,omitempty" json:"target_match,omitempty"`

inhibit/inhibit_bench_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ func BenchmarkMutes(b *testing.B) {
7777
benchmarkMutes(b, lastRuleMatchesBenchmark(b, 10000))
7878
})
7979
b.Run("10 inhibition rules, 5 sources, 100 inhibiting alerts", func(b *testing.B) {
80-
benchmarkMutes(b, manySourcesBenchMark(b, 5, 10, 100))
80+
benchmarkMutes(b, multipleSourcesBenchMark(b, 5, 10, 100))
8181
})
8282
b.Run("100 inhibition rules, 10 sources, 1000 inhibiting alerts", func(b *testing.B) {
83-
benchmarkMutes(b, manySourcesBenchMark(b, 10, 100, 1000))
83+
benchmarkMutes(b, multipleSourcesBenchMark(b, 10, 100, 1000))
8484
})
8585
b.Run("1000 inhibition rules, 20 sources, 100 inhibiting alerts", func(b *testing.B) {
86-
benchmarkMutes(b, manySourcesBenchMark(b, 20, 1000, 1000))
86+
benchmarkMutes(b, multipleSourcesBenchMark(b, 20, 1000, 1000))
8787
})
8888
}
8989

@@ -198,7 +198,7 @@ func lastRuleMatchesBenchmark(b *testing.B, n int) benchmarkOptions {
198198
}
199199
}
200200

201-
func manySourcesBenchMark(b *testing.B, numSources, numInhibitionRules, numInhibitingAlerts int) benchmarkOptions {
201+
func multipleSourcesBenchMark(b *testing.B, numSources, numInhibitionRules, numInhibitingAlerts int) benchmarkOptions {
202202
return benchmarkOptions{
203203
n: numInhibitionRules,
204204
newRuleFunc: func(idx int) config.InhibitRule {
@@ -219,15 +219,17 @@ func manySourcesBenchMark(b *testing.B, numSources, numInhibitionRules, numInhib
219219
},
220220
newAlertsFunc: func(idx int, _ config.InhibitRule) []types.Alert {
221221
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)),
222+
for src := 0; src < numSources; src++ {
223+
for i := 0; i < numInhibitingAlerts; i++ {
224+
alerts = append(alerts, types.Alert{
225+
Alert: model.Alert{
226+
Labels: model.LabelSet{
227+
"src": model.LabelValue(strconv.Itoa(src)),
228+
"idx": model.LabelValue(strconv.Itoa(i)),
229+
},
228230
},
229-
},
230-
})
231+
})
232+
}
231233
}
232234
return alerts
233235
}, benchFunc: func(mutesFunc func(set model.LabelSet) bool) error {

0 commit comments

Comments
 (0)