(t *testing.T)
| 1443 | } |
| 1444 | |
| 1445 | func 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}, |
nothing calls this directly
no test coverage detected