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

Function TestExpendedPostingsCacheIsolation

pkg/ingester/ingester_test.go:6255–6322  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6253}
6254
6255func TestExpendedPostingsCacheIsolation(t *testing.T) {
6256 cfg := defaultIngesterTestConfig(t)
6257 cfg.BlocksStorageConfig.TSDB.BlockRanges = []time.Duration{2 * time.Hour}
6258 cfg.LifecyclerConfig.JoinAfter = 0
6259 cfg.BlocksStorageConfig.TSDB.PostingsCache = cortex_tsdb.TSDBPostingsCacheConfig{
6260 SeedSize: 3, // lets make sure all metric names collide
6261 Head: cortex_tsdb.PostingsCacheConfig{
6262 Enabled: true,
6263 Ttl: time.Hour,
6264 MaxBytes: 1024 * 1024 * 1024,
6265 },
6266 Blocks: cortex_tsdb.PostingsCacheConfig{
6267 Enabled: true,
6268 Ttl: time.Hour,
6269 MaxBytes: 1024 * 1024 * 1024,
6270 },
6271 }
6272
6273 r := prometheus.NewRegistry()
6274 i, err := prepareIngesterWithBlocksStorage(t, cfg, r)
6275 require.NoError(t, err)
6276 require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
6277 defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
6278
6279 // Wait until the ingester is ACTIVE
6280 test.Poll(t, 100*time.Millisecond, ring.ACTIVE, func() any {
6281 return i.lifecycler.GetState()
6282 })
6283
6284 numberOfTenants := 100
6285 wg := sync.WaitGroup{}
6286
6287 for k := range 10 {
6288 wg.Add(numberOfTenants)
6289 for j := range numberOfTenants {
6290 go func() {
6291 defer wg.Done()
6292 userId := fmt.Sprintf("user%v", j)
6293 ctx := user.InjectOrgID(context.Background(), userId)
6294 _, err := i.Push(ctx, cortexpb.ToWriteRequest(
6295 []labels.Labels{labels.FromStrings(labels.MetricName, "foo", "userId", userId, "k", strconv.Itoa(k))}, []cortexpb.Sample{{Value: 2, TimestampMs: 4 * 60 * 60 * 1000}}, nil, nil, cortexpb.API))
6296 require.NoError(t, err)
6297 }()
6298 }
6299 wg.Wait()
6300 }
6301
6302 wg.Add(numberOfTenants)
6303 for j := range numberOfTenants {
6304 go func() {
6305 defer wg.Done()
6306 userId := fmt.Sprintf("user%v", j)
6307 ctx := user.InjectOrgID(context.Background(), userId)
6308 s := &mockQueryStreamServer{ctx: ctx}
6309
6310 err := i.QueryStream(&client.QueryRequest{
6311 StartTimestampMs: 0,
6312 EndTimestampMs: math.MaxInt64,

Callers

nothing calls this directly

Calls 15

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
ToWriteRequestFunction · 0.92
DoneMethod · 0.80
PushMethod · 0.65
QueryStreamMethod · 0.65
EqualMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected