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

Function TestRulerAPISingleBinary

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

Source from the content-addressed store, hash-verified

202}
203
204func TestRulerAPISingleBinary(t *testing.T) {
205 s, err := e2e.NewScenario(networkName)
206 require.NoError(t, err)
207 defer s.Close()
208
209 namespace := "ns"
210 user := "fake"
211
212 configOverrides := map[string]string{
213 "-ruler-storage.local.directory": filepath.Join(e2e.ContainerSharedDir, "ruler_configs"),
214 "-ruler.poll-interval": "2s",
215 "-ruler.rule-path": filepath.Join(e2e.ContainerSharedDir, "rule_tmp/"),
216 // alert manager
217 "-alertmanager.web.external-url": "http://localhost/alertmanager",
218 "-alertmanager-storage.backend": "local",
219 "-alertmanager-storage.local.path": filepath.Join(e2e.ContainerSharedDir, "alertmanager_configs"),
220 }
221 // make alert manager config dir
222 require.NoError(t, writeFileToSharedDir(s, "alertmanager_configs", []byte{}))
223
224 // Start Cortex components.
225 require.NoError(t, copyFileToSharedDir(s, "docs/configuration/single-process-config-blocks-local.yaml", cortexConfigFile))
226 require.NoError(t, writeFileToSharedDir(s, filepath.Join("ruler_configs", user, namespace), []byte(cortexRulerUserConfigYaml)))
227 cortex := e2ecortex.NewSingleBinaryWithConfigFile("cortex", cortexConfigFile, configOverrides, "", 9009, 9095)
228 require.NoError(t, s.StartAndWaitReady(cortex))
229
230 // Create a client with the ruler address configured
231 c, err := e2ecortex.NewClient("", "", "", cortex.HTTPEndpoint(), "")
232 require.NoError(t, err)
233
234 // Wait until the user manager is created
235 require.NoError(t, cortex.WaitSumMetrics(e2e.Equals(1), "cortex_ruler_managers_total"))
236
237 // Check to ensure the rules running in the cortex match what was set
238 rgs, err := c.GetRuleGroups()
239 require.NoError(t, err)
240
241 retrievedNamespace, exists := rgs[namespace]
242 require.True(t, exists)
243 require.Len(t, retrievedNamespace, 1)
244 require.Equal(t, retrievedNamespace[0].Name, "rule")
245
246 // Check to make sure prometheus engine metrics are available for both engine types
247 require.NoError(t, cortex.WaitSumMetricsWithOptions(e2e.Equals(0), []string{"prometheus_engine_queries"}, e2e.WithLabelMatchers(
248 labels.MustNewMatcher(labels.MatchEqual, "engine", "querier"))))
249
250 require.NoError(t, cortex.WaitSumMetricsWithOptions(e2e.Equals(0), []string{"prometheus_engine_queries"}, e2e.WithLabelMatchers(
251 labels.MustNewMatcher(labels.MatchEqual, "engine", "ruler"))))
252
253 // Test Cleanup and Restart
254
255 // Stop the running cortex
256 require.NoError(t, cortex.Stop())
257
258 // Restart Cortex with identical configs
259 cortexRestarted := e2ecortex.NewSingleBinaryWithConfigFile("cortex-restarted", cortexConfigFile, configOverrides, "", 9009, 9095)
260 require.NoError(t, s.StartAndWaitReady(cortexRestarted))
261

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
GetRuleGroupsMethod · 0.95
NewScenarioFunction · 0.92
NewClientFunction · 0.92
EqualsFunction · 0.92
WithLabelMatchersFunction · 0.92
writeFileToSharedDirFunction · 0.85
copyFileToSharedDirFunction · 0.85
JoinMethod · 0.80
HTTPEndpointMethod · 0.80

Tested by

no test coverage detected