(t *testing.T)
| 7489 | } |
| 7490 | |
| 7491 | func TestIngester_ActiveQueriedSeries(t *testing.T) { |
| 7492 | registry := prometheus.NewRegistry() |
| 7493 | |
| 7494 | // Create ingester config with active queried series enabled |
| 7495 | cfg := defaultIngesterTestConfig(t) |
| 7496 | cfg.LifecyclerConfig.JoinAfter = 0 |
| 7497 | cfg.ActiveQueriedSeriesMetricsEnabled = true |
| 7498 | cfg.ActiveQueriedSeriesMetricsUpdatePeriod = 5 * time.Second |
| 7499 | cfg.ActiveQueriedSeriesMetricsWindowDuration = 5 * time.Second |
| 7500 | cfg.ActiveQueriedSeriesMetricsSampleRate = 1.0 // Sample all queries |
| 7501 | cfg.ActiveQueriedSeriesMetricsWindows = cortex_tsdb.DurationList{5 * time.Second, 10 * time.Second} |
| 7502 | |
| 7503 | // Create ingester |
| 7504 | i, err := prepareIngesterWithBlocksStorage(t, cfg, registry) |
| 7505 | require.NoError(t, err) |
| 7506 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 7507 | defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck |
| 7508 | |
| 7509 | ctx := user.InjectOrgID(context.Background(), "test-user") |
| 7510 | |
| 7511 | // Wait until the ingester is ACTIVE |
| 7512 | test.Poll(t, 100*time.Millisecond, ring.ACTIVE, func() any { |
| 7513 | return i.lifecycler.GetState() |
| 7514 | }) |
| 7515 | |
| 7516 | // Push some sample data |
| 7517 | now := time.Now() |
| 7518 | for idx := range 10 { |
| 7519 | req := &cortexpb.WriteRequest{} |
| 7520 | for seriesIdx := range 5 { |
| 7521 | req.Timeseries = append(req.Timeseries, cortexpb.PreallocTimeseries{ |
| 7522 | TimeSeries: &cortexpb.TimeSeries{ |
| 7523 | Labels: []cortexpb.LabelAdapter{ |
| 7524 | {Name: labels.MetricName, Value: "test_metric"}, |
| 7525 | {Name: "series", Value: fmt.Sprintf("series_%d", seriesIdx)}, |
| 7526 | }, |
| 7527 | Samples: []cortexpb.Sample{ |
| 7528 | {Value: float64(idx), TimestampMs: now.Add(time.Duration(idx) * time.Second).UnixMilli()}, |
| 7529 | }, |
| 7530 | }, |
| 7531 | }) |
| 7532 | } |
| 7533 | _, err := i.Push(ctx, req) |
| 7534 | require.NoError(t, err) |
| 7535 | } |
| 7536 | |
| 7537 | // Verify initial state - no queries run yet, so metric should be 0 or not exist |
| 7538 | metricsBefore := fetchMetrics(t, registry, "cortex_ingester_active_queried_series") |
| 7539 | t.Logf("Metrics before query: %v", metricsBefore) |
| 7540 | |
| 7541 | // Run a query to trigger active queried series tracking |
| 7542 | matcher := &client.LabelMatcher{ |
| 7543 | Type: client.REGEX_MATCH, |
| 7544 | Name: labels.MetricName, |
| 7545 | Value: ".*", |
| 7546 | } |
| 7547 | |
| 7548 | req := &client.QueryRequest{ |
nothing calls this directly
no test coverage detected