mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update state manager to accept reserved labels (#52189)
* add tests for cache getOrCreate * update ProcessEvalResults to accept extra lables * extract to getRuleExtraLabels * move populating of constant rule labels to extra labels
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -38,19 +40,11 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule {
|
||||
|
||||
var annotations map[string]string = nil
|
||||
if rand.Int63()%2 == 0 {
|
||||
qty := rand.Intn(5)
|
||||
annotations = make(map[string]string, qty)
|
||||
for i := 0; i < qty; i++ {
|
||||
annotations[util.GenerateShortUID()] = util.GenerateShortUID()
|
||||
}
|
||||
annotations = GenerateAlertLabels(rand.Intn(5), "ann-")
|
||||
}
|
||||
var labels map[string]string = nil
|
||||
if rand.Int63()%2 == 0 {
|
||||
qty := rand.Intn(5)
|
||||
labels = make(map[string]string, qty)
|
||||
for i := 0; i < qty; i++ {
|
||||
labels[util.GenerateShortUID()] = util.GenerateShortUID()
|
||||
}
|
||||
labels = GenerateAlertLabels(rand.Intn(5), "lbl-")
|
||||
}
|
||||
|
||||
var dashUID *string = nil
|
||||
@@ -91,6 +85,11 @@ func AlertRuleGen(mutators ...AlertRuleMutator) func() *AlertRule {
|
||||
}
|
||||
}
|
||||
|
||||
func WithNotEmptyLabels(count int, prefix string) AlertRuleMutator {
|
||||
return func(rule *AlertRule) {
|
||||
rule.Labels = GenerateAlertLabels(count, prefix)
|
||||
}
|
||||
}
|
||||
func WithUniqueID() AlertRuleMutator {
|
||||
usedID := make(map[int64]struct{})
|
||||
return func(rule *AlertRule) {
|
||||
@@ -133,6 +132,14 @@ func WithSequentialGroupIndex() AlertRuleMutator {
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateAlertLabels(count int, prefix string) data.Labels {
|
||||
labels := make(data.Labels, count)
|
||||
for i := 0; i < count; i++ {
|
||||
labels[prefix+"key-"+util.GenerateShortUID()] = prefix + "value-" + util.GenerateShortUID()
|
||||
}
|
||||
return labels
|
||||
}
|
||||
|
||||
func GenerateAlertQuery() AlertQuery {
|
||||
f := rand.Intn(10) + 5
|
||||
t := rand.Intn(f)
|
||||
|
||||
Reference in New Issue
Block a user