MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRuler_LimitsPerGroup

Function TestRuler_LimitsPerGroup

pkg/ruler/api_test.go:601–653  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

599}
600
601func TestRuler_LimitsPerGroup(t *testing.T) {
602 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)
603 cfg := defaultRulerConfig(t)
604
605 r := newTestRuler(t, cfg, store, nil)
606 defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck
607
608 r.limits = &ruleLimits{maxRuleGroups: 1, maxRulesPerRuleGroup: 1}
609
610 a := NewAPI(r, r.store, log.NewNopLogger())
611
612 tc := []struct {
613 name string
614 input string
615 output string
616 err error
617 status int
618 }{
619 {
620 name: "when exceeding the rules per rule group limit",
621 status: 400,
622 input: `
623name: test
624interval: 15s
625rules:
626- record: up_rule
627 expr: up{}
628- alert: up_alert
629 expr: sum(up{}) > 1
630 for: 30s
631 annotations:
632 test: test
633 labels:
634 test: test
635`,
636 output: "per-user rules per rule group limit (limit: 1 actual: 2) exceeded\n",
637 },
638 }
639
640 for _, tt := range tc {
641 t.Run(tt.name, func(t *testing.T) {
642 router := mux.NewRouter()
643 router.Path("/api/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup)
644 // POST
645 req := requestFor(t, http.MethodPost, "https://localhost:8080/api/v1/rules/namespace", strings.NewReader(tt.input), "user1")
646 w := httptest.NewRecorder()
647
648 router.ServeHTTP(w, req)
649 require.Equal(t, tt.status, w.Code)
650 require.Equal(t, tt.output, w.Body.String())
651 })
652 }
653}
654
655func TestRuler_RulerGroupLimits(t *testing.T) {
656 store := newMockRuleStore(make(map[string]rulespb.RuleGroupList), nil)

Callers

nothing calls this directly

Calls 10

StopAndAwaitTerminatedFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
newTestRulerFunction · 0.85
requestForFunction · 0.85
NewAPIFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected