MCPcopy Index your code
hub / github.com/cortexproject/cortex / testRulesPaginationAPIWithSharding

Function testRulesPaginationAPIWithSharding

integration/ruler_test.go:599–763  ·  view source on GitHub ↗
(t *testing.T, enableRulesBackup bool)

Source from the content-addressed store, hash-verified

597}
598
599func testRulesPaginationAPIWithSharding(t *testing.T, enableRulesBackup bool) {
600 const numRulesGroups = 100
601
602 random := rand.New(rand.NewSource(time.Now().UnixNano()))
603 s, err := e2e.NewScenario(networkName)
604 require.NoError(t, err)
605 defer s.Close()
606
607 // Generate multiple rule groups, with 1 rule each.
608 ruleGroups := make([]rulefmt.RuleGroup, numRulesGroups)
609 expectedNames := make([]string, numRulesGroups)
610 alertCount := 0
611 evalInterval, _ := model.ParseDuration("1s")
612 for i := 0; i < numRulesGroups; i++ {
613 num := random.Intn(100)
614 ruleName := fmt.Sprintf("test_%d", i)
615
616 expectedNames[i] = ruleName
617 if num%2 == 0 {
618 alertCount++
619 ruleGroups[i] = rulefmt.RuleGroup{
620 Name: ruleName,
621 Interval: evalInterval,
622 Rules: []rulefmt.Rule{{
623 Alert: fmt.Sprintf("rule_%d", i),
624 Expr: strconv.Itoa(i),
625 }},
626 }
627 } else {
628 ruleGroups[i] = rulefmt.RuleGroup{
629 Name: ruleName,
630 Interval: evalInterval,
631 Rules: []rulefmt.Rule{{
632 Record: fmt.Sprintf("rule_%d", i),
633 Expr: strconv.Itoa(i),
634 }},
635 }
636 }
637 }
638
639 // Start dependencies.
640 consul := e2edb.NewConsul()
641 minio := e2edb.NewMinio(9000, rulestoreBucketName)
642 require.NoError(t, s.StartAndWaitReady(consul, minio))
643
644 // Configure the ruler.
645 overrides := map[string]string{
646 // Since we're not going to run any rule, we don't need the
647 // store-gateway to be configured to a valid address.
648 "-querier.store-gateway-addresses": "localhost:12345",
649 // Enable the bucket index so we can skip the initial bucket scan.
650 "-blocks-storage.bucket-store.bucket-index.enabled": "true",
651 "-ruler.poll-interval": "5s",
652 }
653 if enableRulesBackup {
654 overrides["-ruler.ring.replication-factor"] = "2"
655 }
656 rulerFlags := mergeFlags(

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
SetRuleGroupMethod · 0.95
GetPrometheusRulesMethod · 0.95
NewScenarioFunction · 0.92
NewRulerFunction · 0.92
NewClientFunction · 0.92
EqualsFunction · 0.92
LessFunction · 0.92
NetworkHTTPEndpointMethod · 0.80
HTTPEndpointMethod · 0.80

Tested by

no test coverage detected