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

Function prepare

pkg/distributor/distributor_test.go:3271–3434  ·  view source on GitHub ↗
(tb testing.TB, cfg prepConfig)

Source from the content-addressed store, hash-verified

3269}
3270
3271func prepare(tb testing.TB, cfg prepConfig) ([]*Distributor, []*mockIngester, []*prometheus.Registry, *ring.Ring) {
3272 // Strings to be used for get labels values/Names
3273 var unusedStrings []string
3274 if cfg.lblValuesPerIngester > 0 {
3275 unusedStrings = make([]string, min(len(randomStrings), cfg.numIngesters*cfg.lblValuesPerIngester))
3276 copy(unusedStrings, randomStrings)
3277 }
3278 s := &prepState{
3279 unusedStrings: unusedStrings,
3280 }
3281 ingesters := []*mockIngester{}
3282 for i := 0; i < cfg.happyIngesters; i++ {
3283 ingesters = append(ingesters, newMockIngester(i, s, cfg))
3284 }
3285 for i := cfg.happyIngesters; i < cfg.numIngesters; i++ {
3286 miError := errFail
3287 if cfg.errFail != nil {
3288 miError = cfg.errFail
3289 }
3290
3291 ingesters = append(ingesters, &mockIngester{
3292 queryDelay: cfg.queryDelay,
3293 failResp: *atomic.NewError(miError),
3294 })
3295 }
3296
3297 // Use a real ring with a mock KV store to test ring RF logic.
3298 ingesterDescs := map[string]ring.InstanceDesc{}
3299 ingestersByAddr := map[string]*mockIngester{}
3300 for i := range ingesters {
3301 var tokens []uint32
3302 if len(cfg.tokens) > i {
3303 tokens = cfg.tokens[i]
3304 } else {
3305 tokens = []uint32{uint32((math.MaxUint32 / cfg.numIngesters) * i)}
3306 }
3307 ingester := fmt.Sprintf("ingester-%d", i)
3308 addr := fmt.Sprintf("ip-ingester-%d", i)
3309 ingesterDescs[ingester] = ring.InstanceDesc{
3310 Addr: addr,
3311 Zone: "",
3312 State: ring.ACTIVE,
3313 Timestamp: time.Now().Unix(),
3314 RegisteredTimestamp: time.Now().Add(-2 * time.Hour).Unix(),
3315 Tokens: tokens,
3316 }
3317 ingestersByAddr[addr] = ingesters[i]
3318 }
3319
3320 kvStore, closer := consul.NewInMemoryClient(ring.GetCodec(), log.NewNopLogger(), nil)
3321 tb.Cleanup(func() { assert.NoError(tb, closer.Close()) })
3322
3323 err := kvStore.CAS(context.Background(), ingester.RingKey,
3324 func(_ any) (any, bool, error) {
3325 return &ring.Desc{
3326 Ingesters: ingesterDescs,
3327 }, true, nil
3328 },

Calls 15

NewInMemoryClientFunction · 0.92
GetCodecFunction · 0.92
NewFunction · 0.92
StartAndAwaitRunningFunction · 0.92
PollFunction · 0.92
DefaultValuesFunction · 0.92
GetReplicaDescCodecFunction · 0.92
PrefixClientFunction · 0.92
NewOverridesFunction · 0.92
newMockIngesterFunction · 0.85
stopAllFunction · 0.85
NewFunction · 0.70

Tested by

no test coverage detected