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

Function Test_Ingester_UserStats

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

Source from the content-addressed store, hash-verified

5336}
5337
5338func Test_Ingester_UserStats(t *testing.T) {
5339 series := []struct {
5340 lbls labels.Labels
5341 value float64
5342 timestamp int64
5343 }{
5344
5345 {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "200"), 1, 100000},
5346 {labels.FromStrings("__name__", "test_1", "route", "get_user", "status", "500"), 1, 110000},
5347 {labels.FromStrings("__name__", "test_2"), 2, 200000},
5348 }
5349
5350 // Create ingester
5351 i, err := prepareIngesterWithBlocksStorage(t, defaultIngesterTestConfig(t), prometheus.NewRegistry())
5352 require.NoError(t, err)
5353 require.NoError(t, services.StartAndAwaitRunning(context.Background(), i))
5354 defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck
5355
5356 // Wait until it's ACTIVE
5357 test.Poll(t, 1*time.Second, ring.ACTIVE, func() any {
5358 return i.lifecycler.GetState()
5359 })
5360
5361 // Push series
5362 ctx := user.InjectOrgID(context.Background(), "test")
5363
5364 for _, series := range series {
5365 req, _ := mockWriteRequest(t, series.lbls, series.value, series.timestamp)
5366 _, err := i.Push(ctx, req)
5367 require.NoError(t, err)
5368 }
5369
5370 // force update statistics
5371 for _, db := range i.TSDBState.dbs {
5372 db.ingestedAPISamples.Tick()
5373 db.ingestedRuleSamples.Tick()
5374 }
5375
5376 // Get label names
5377 res, err := i.UserStats(ctx, &client.UserStatsRequest{})
5378 require.NoError(t, err)
5379 assert.InDelta(t, 0.2, res.ApiIngestionRate, 0.0001)
5380 assert.InDelta(t, float64(0), res.RuleIngestionRate, 0.0001)
5381 assert.Equal(t, uint64(3), res.NumSeries)
5382}
5383
5384func Test_Ingester_AllUserStats(t *testing.T) {
5385 series := []struct {

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected