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

Function TestGetRulesFromBackup

pkg/ruler/ruler_test.go:1445–1654  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1443}
1444
1445func TestGetRulesFromBackup(t *testing.T) {
1446 // ruler ID -> (user ID -> list of groups).
1447 type expectedRulesMap map[string]map[string]rulespb.RuleGroupList
1448
1449 rule := []*rulespb.RuleDesc{
1450 {
1451 Record: "rtest_user1_1",
1452 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1453 },
1454 {
1455 Alert: "atest_user1_1",
1456 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1457 },
1458 {
1459 Record: "rtest_user1_2",
1460 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1461 Labels: []cortexpb.LabelAdapter{
1462 {Name: "key", Value: "val"},
1463 },
1464 },
1465 {
1466 Alert: "atest_user1_2",
1467 Expr: "sum(rate(node_cpu_seconds_total[3h:10m]))",
1468 Labels: []cortexpb.LabelAdapter{
1469 {Name: "key", Value: "val"},
1470 },
1471 Annotations: []cortexpb.LabelAdapter{
1472 {Name: "aKey", Value: "aVal"},
1473 },
1474 For: 10 * time.Second,
1475 KeepFiringFor: 20 * time.Second,
1476 },
1477 }
1478
1479 tenantId := "user1"
1480
1481 rulerStateMapOnePending := map[string]ring.InstanceState{
1482 "ruler1": ring.ACTIVE,
1483 "ruler2": ring.PENDING,
1484 "ruler3": ring.ACTIVE,
1485 }
1486
1487 rulerAZEvenSpread := map[string]string{
1488 "ruler1": "a",
1489 "ruler2": "b",
1490 "ruler3": "c",
1491 }
1492
1493 expectedRules := expectedRulesMap{
1494 "ruler1": map[string]rulespb.RuleGroupList{
1495 tenantId: {
1496 &rulespb.RuleGroupDesc{User: "user1", Namespace: "namespace", Name: "l1", Interval: 10 * time.Minute, Limit: 10, Rules: rule},
1497 &rulespb.RuleGroupDesc{User: "user1", Namespace: "namespace", Name: "l2", Interval: 0, Rules: rule},
1498 },
1499 },
1500 "ruler2": map[string]rulespb.RuleGroupList{
1501 tenantId: {
1502 &rulespb.RuleGroupDesc{User: "user1", Namespace: "namespace", Name: "b1", Interval: 10 * time.Minute, Limit: 10, Rules: rule},

Callers

nothing calls this directly

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