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

Function TestRulerSharding

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

Source from the content-addressed store, hash-verified

264}
265
266func TestRulerSharding(t *testing.T) {
267 const numRulesGroups = 100
268
269 s, err := e2e.NewScenario(networkName)
270 require.NoError(t, err)
271 defer s.Close()
272
273 // Generate multiple rule groups, with 1 rule each.
274 ruleGroups := make([]rulefmt.RuleGroup, numRulesGroups)
275 expectedNames := make([]string, numRulesGroups)
276 for i := 0; i < numRulesGroups; i++ {
277 ruleName := fmt.Sprintf("test_%d", i)
278
279 expectedNames[i] = ruleName
280 ruleGroups[i] = rulefmt.RuleGroup{
281 Name: ruleName,
282 Interval: 60,
283 Rules: []rulefmt.Rule{{
284 Record: fmt.Sprintf("rule_%d", i),
285 Expr: strconv.Itoa(i),
286 }},
287 }
288 }
289
290 // Start dependencies.
291 consul := e2edb.NewConsul()
292 minio := e2edb.NewMinio(9000, rulestoreBucketName)
293 require.NoError(t, s.StartAndWaitReady(consul, minio))
294
295 // Configure the ruler.
296 rulerFlags := mergeFlags(
297 BlocksStorageFlags(),
298 RulerFlags(),
299 RulerShardingFlags(consul.NetworkHTTPEndpoint()),
300 map[string]string{
301 // Since we're not going to run any rule, we don't need the
302 // store-gateway to be configured to a valid address.
303 "-querier.store-gateway-addresses": "localhost:12345",
304 // Enable the bucket index so we can skip the initial bucket scan.
305 "-blocks-storage.bucket-store.bucket-index.enabled": "true",
306 },
307 )
308
309 // Start rulers.
310 ruler1 := e2ecortex.NewRuler("ruler-1", consul.NetworkHTTPEndpoint(), rulerFlags, "")
311 ruler2 := e2ecortex.NewRuler("ruler-2", consul.NetworkHTTPEndpoint(), rulerFlags, "")
312 rulers := e2ecortex.NewCompositeCortexService(ruler1, ruler2)
313 require.NoError(t, s.StartAndWaitReady(ruler1, ruler2))
314
315 // Upload rule groups to one of the rulers.
316 c, err := e2ecortex.NewClient("", "", "", ruler1.HTTPEndpoint(), "user-1")
317 require.NoError(t, err)
318
319 for _, ruleGroup := range ruleGroups {
320 require.NoError(t, c.SetRuleGroup(ruleGroup, "test"))
321 }
322
323 // Wait until rulers have loaded all rules.

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
SetRuleGroupMethod · 0.95
GetPrometheusRulesMethod · 0.95
NewScenarioFunction · 0.92
NewRulerFunction · 0.92
NewClientFunction · 0.92
EqualsFunction · 0.92
LessFunction · 0.92
NetworkHTTPEndpointMethod · 0.80
HTTPEndpointMethod · 0.80

Tested by

no test coverage detected