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

Function Test_Ingester_AllUserStats

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

Source from the content-addressed store, hash-verified

5382}
5383
5384func Test_Ingester_AllUserStats(t *testing.T) {
5385 series := []struct {
5386 user string
5387 lbls labels.Labels
5388 value float64
5389 timestamp int64
5390 }{
5391 {"user-1", labels.FromStrings("__name__", "test_1_1", "route", "get_user", "status", "200"), 1, 100000},
5392 {"user-1", labels.FromStrings("__name__", "test_1_1", "route", "get_user", "status", "500"), 1, 110000},
5393 {"user-1", labels.FromStrings("__name__", "test_1_2"), 2, 200000},
5394 {"user-2", labels.FromStrings("__name__", "test_2_1"), 2, 200000},
5395 {"user-2", labels.FromStrings("__name__", "test_2_2"), 2, 200000},
5396 }
5397
5398 // Create ingester
5399 i, err := prepareIngesterWithBlocksStorage(t, defaultIngesterTestConfig(t), prometheus.NewRegistry())
5400 require.NoError(t, err)
5401 require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
5402 defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
5403
5404 // Wait until it's ACTIVE
5405 test.Poll(t, 1*time.Second, ring.ACTIVE, func() any {
5406 return i.lifecycler.GetState()
5407 })
5408 for _, series := range series {
5409 ctx := user.InjectOrgID(context.Background(), series.user)
5410 req, _ := mockWriteRequest(t, series.lbls, series.value, series.timestamp)
5411 _, err := i.Push(ctx, req)
5412 require.NoError(t, err)
5413 }
5414
5415 // force update statistics
5416 for _, db := range i.TSDBState.dbs {
5417 db.ingestedAPISamples.Tick()
5418 db.ingestedRuleSamples.Tick()
5419 }
5420
5421 // Get label names
5422 res, err := i.AllUserStats(context.Background(), &client.UserStatsRequest{})
5423 require.NoError(t, err)
5424
5425 expect := []*client.UserIDStatsResponse{
5426 {
5427 UserId: "user-1",
5428 Data: &client.UserStatsResponse{
5429 IngestionRate: 0.2,
5430 NumSeries: 3,
5431 ApiIngestionRate: 0.2,
5432 RuleIngestionRate: 0,
5433 ActiveSeries: 3,
5434 LoadedBlocks: 0,
5435 },
5436 },
5437 {
5438 UserId: "user-2",
5439 Data: &client.UserStatsResponse{
5440 IngestionRate: 0.13333333333333333,
5441 NumSeries: 2,

Callers

nothing calls this directly

Calls 10

StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
mockWriteRequestFunction · 0.70
PushMethod · 0.65
AllUserStatsMethod · 0.65
GetStateMethod · 0.45
TickMethod · 0.45

Tested by

no test coverage detected