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

Function TestRulerKeepFiring

integration/ruler_test.go:1608–1714  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1606}
1607
1608func TestRulerKeepFiring(t *testing.T) {
1609 s, err := e2e.NewScenario(networkName)
1610 require.NoError(t, err)
1611 defer s.Close()
1612
1613 // Start dependencies.
1614 consul := e2edb.NewConsul()
1615 minio := e2edb.NewMinio(9000, bucketName, rulestoreBucketName)
1616 require.NoError(t, s.StartAndWaitReady(consul, minio))
1617
1618 // Configure the ruler.
1619 flags := mergeFlags(
1620 BlocksStorageFlags(),
1621 RulerFlags(),
1622 map[string]string{
1623 // Since we're not going to run any rule (our only rule is invalid), we don't need the
1624 // store-gateway to be configured to a valid address.
1625 "-querier.store-gateway-addresses": "localhost:12345",
1626 // Enable the bucket index so we can skip the initial bucket scan.
1627 "-blocks-storage.bucket-store.bucket-index.enabled": "true",
1628 // Evaluate rules often, so that we don't need to wait for metrics to show up.
1629 "-ruler.evaluation-interval": "2s",
1630 "-ruler.poll-interval": "2s",
1631 // No delay
1632 "-ruler.evaluation-delay-duration": "0",
1633
1634 "-blocks-storage.tsdb.block-ranges-period": "1h",
1635 "-blocks-storage.bucket-store.sync-interval": "1s",
1636 "-blocks-storage.tsdb.retention-period": "2h",
1637
1638 // We run single ingester only, no replication.
1639 "-distributor.replication-factor": "1",
1640
1641 "-querier.max-fetched-chunks-per-query": "50",
1642 },
1643 )
1644
1645 const namespace = "test"
1646 const user = "user"
1647
1648 distributor := e2ecortex.NewDistributor("distributor", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "")
1649 ruler := e2ecortex.NewRuler("ruler", consul.NetworkHTTPEndpoint(), flags, "")
1650 ingester := e2ecortex.NewIngester("ingester", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "")
1651 require.NoError(t, s.StartAndWaitReady(distributor, ingester, ruler))
1652
1653 // Wait until both the distributor and ruler have updated the ring. The querier will also watch
1654 // the store-gateway ring if blocks sharding is enabled.
1655 require.NoError(t, distributor.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total"))
1656 require.NoError(t, ruler.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total"))
1657
1658 c, err := e2ecortex.NewClient(distributor.HTTPEndpoint(), "", "", ruler.HTTPEndpoint(), user)
1659 require.NoError(t, err)
1660
1661 expression := "vector(1) > 0" // Alert will fire
1662 groupName := "rule_group_1"
1663 ruleName := "rule_keep_firing"
1664
1665 require.NoError(t, c.SetRuleGroup(alertRuleWithKeepFiringFor(groupName, ruleName, expression, model.Duration(10*time.Second)), namespace))

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
SetRuleGroupMethod · 0.95
GetPrometheusRulesMethod · 0.95
NewScenarioFunction · 0.92
NewDistributorFunction · 0.92
NewRulerFunction · 0.92
NewIngesterFunction · 0.92
EqualsFunction · 0.92
NewClientFunction · 0.92
WithLabelMatchersFunction · 0.92
GreaterOrEqualFunction · 0.92

Tested by

no test coverage detected