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

Function getRulesHATest

pkg/ruler/ruler_test.go:1661–1885  ·  view source on GitHub ↗
(replicationFactor int)

Source from the content-addressed store, hash-verified

1659}
1660
1661func getRulesHATest(replicationFactor int) func(t *testing.T) {
1662 return func(t *testing.T) {
1663 // ruler ID -> (user ID -> list of groups).
1664 type expectedRulesMap map[string]map[string]rulespb.RuleGroupList
1665
1666 rule := []*rulespb.RuleDesc{
1667 {
1668 Record: "rtest_user1_1",
1669 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1670 },
1671 {
1672 Alert: "atest_user1_1",
1673 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1674 },
1675 {
1676 Record: "rtest_user1_2",
1677 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1678 Labels: []cortexpb.LabelAdapter{
1679 {Name: "key", Value: "val"},
1680 },
1681 },
1682 {
1683 Alert: "atest_user1_2",
1684 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1685 Labels: []cortexpb.LabelAdapter{
1686 {Name: "key", Value: "val"},
1687 },
1688 Annotations: []cortexpb.LabelAdapter{
1689 {Name: "aKey", Value: "aVal"},
1690 },
1691 For: 10 * time.Second,
1692 KeepFiringFor: 20 * time.Second,
1693 },
1694 }
1695
1696 tenantId := "user1"
1697
1698 rulerStateMapOnePending := map[string]ring.InstanceState{
1699 "ruler1": ring.PENDING,
1700 "ruler2": ring.ACTIVE,
1701 "ruler3": ring.ACTIVE,
1702 }
1703
1704 rulerAZEvenSpread := map[string]string{
1705 "ruler1": "a",
1706 "ruler2": "b",
1707 "ruler3": "c",
1708 }
1709
1710 expectedRules := expectedRulesMap{
1711 "ruler1": map[string]rulespb.RuleGroupList{
1712 tenantId: {
1713 &rulespb.RuleGroupDesc{User: "user1", Namespace: "namespace", Name: "l1", Interval: 10 * time.Minute, Limit: 10, Rules: rule},
1714 &rulespb.RuleGroupDesc{User: "user1", Namespace: "namespace", Name: "l2", Interval: 0, Rules: rule},
1715 },
1716 },
1717 "ruler2": map[string]rulespb.RuleGroupList{
1718 tenantId: {

Callers 1

TestGetRules_HAFunction · 0.85

Calls 15

NewInMemoryClientFunction · 0.92
GetCodecFunction · 0.92
StartAndAwaitRunningFunction · 0.92
NewDescFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
buildRulerFunction · 0.85
generateTokenForGroupsFunction · 0.85
AddIngesterMethod · 0.80
GetInstanceAddrMethod · 0.80
GetInstanceZoneMethod · 0.80
syncRulesMethod · 0.80

Tested by

no test coverage detected