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

Function TestRulerAPI

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

Source from the content-addressed store, hash-verified

38)
39
40func TestRulerAPI(t *testing.T) {
41 var (
42 namespaceOne = "test_/encoded_+namespace/?"
43 namespaceTwo = "test_/encoded_+namespace/?/two"
44 )
45 ruleGroup := createTestRuleGroup(t)
46
47 for _, thanosEngine := range []bool{false, true} {
48 t.Run(fmt.Sprintf("thanosEngine=%t", thanosEngine), func(t *testing.T) {
49 s, err := e2e.NewScenario(networkName)
50 require.NoError(t, err)
51 defer s.Close()
52
53 // Start dependencies.
54 consul := e2edb.NewConsul()
55 minio := e2edb.NewMinio(9000, rulestoreBucketName, bucketName)
56 require.NoError(t, s.StartAndWaitReady(consul, minio))
57
58 flags := mergeFlags(BlocksStorageFlags(), RulerFlags(), map[string]string{
59 "-querier.thanos-engine": strconv.FormatBool(thanosEngine),
60 })
61
62 // Start Cortex components.
63 ruler := e2ecortex.NewRuler("ruler", consul.NetworkHTTPEndpoint(), flags, "")
64 require.NoError(t, s.StartAndWaitReady(ruler))
65
66 // Create a client with the ruler address configured
67 c, err := e2ecortex.NewClient("", "", "", ruler.HTTPEndpoint(), "user-1")
68 require.NoError(t, err)
69
70 // Set the rule group into the ruler
71 require.NoError(t, c.SetRuleGroup(ruleGroup, namespaceOne))
72
73 // Wait until the user manager is created
74 require.NoError(t, ruler.WaitSumMetrics(e2e.Equals(1), "cortex_ruler_managers_total"))
75
76 // Check to ensure the rules running in the ruler match what was set
77 rgs, err := c.GetRuleGroups()
78 require.NoError(t, err)
79
80 retrievedNamespace, exists := rgs[namespaceOne]
81 require.True(t, exists)
82 require.Len(t, retrievedNamespace, 1)
83 require.Equal(t, retrievedNamespace[0].Name, ruleGroup.Name)
84
85 // Add a second rule group with a similar namespace
86 require.NoError(t, c.SetRuleGroup(ruleGroup, namespaceTwo))
87 require.NoError(t, ruler.WaitSumMetrics(e2e.Equals(2), "cortex_prometheus_rule_group_rules"))
88
89 // Check to ensure the rules running in the ruler match what was set
90 rgs, err = c.GetRuleGroups()
91 require.NoError(t, err)
92
93 retrievedNamespace, exists = rgs[namespaceOne]
94 require.True(t, exists)
95 require.Len(t, retrievedNamespace, 1)
96 require.Equal(t, retrievedNamespace[0].Name, ruleGroup.Name)
97

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
SetRuleGroupMethod · 0.95
GetRuleGroupsMethod · 0.95
DeleteRuleGroupMethod · 0.95
DeleteRuleNamespaceMethod · 0.95
GetRuleGroupMethod · 0.95
NewScenarioFunction · 0.92
NewRulerFunction · 0.92
NewClientFunction · 0.92
EqualsFunction · 0.92
createTestRuleGroupFunction · 0.85

Tested by

no test coverage detected