The only tool you need to know what is happening and how to fix it.
Go alertingexception-trackerissue-trackinglogsmetricsmonitoringobservability-platformopen-telemetryotelsession-replaytelemetrytraces
fix: compute list percentiles over the filtered rows (tasks, AI traces, endpoints) (#319)
FrameAutomataa2d7b1da4550
diff --git a/backend/app/repositories/telemetry/ai_trace_repository_test.go b/backend/app/repositories/telemetry/ai_trace_repository_test.goindex 9342659f..ba1fc67c 100644--- a/backend/app/repositories/telemetry/ai_trace_repository_test.go+++ b/backend/app/repositories/telemetry/ai_trace_repository_test.go@@ -507,3 +507,75 @@ func TestAiTraceRepository_ListModels(t *testing.T) {t.Errorf("ListModels = %v, expected [claude-sonnet-5 gpt-4o]", names)}}++// Percentiles must describe the rows the filter selects, since the list is+// ordered and paginated on them.+func TestAiTraceRepository_FindGroupedByTraceName_PercentilesUseFilteredRows(t *testing.T) {+ setupTestDB(t)+ ctx := context.Background()+ projectId := uuid.New()+ now := truncateMs(time.Now().UTC())++ var traces []models.AiTrace+ for range 4 {+ traces = append(traces, makeAiTraceWithRoot(projectId, "agent.plan", 200*time.Millisecond, 100, 0.01, now, true))+ traces = append(traces, makeAiTraceWithRoot(projectId, "agent.plan", 30*time.Second, 100, 0.01, now, false))+ }++ if err := AiTraceRepository.InsertAsync(ctx, traces); err != nil {+ t.Fatalf("InsertAsync failed: %v", err)+ }++ stats, _, err := AiTraceRepository.FindGroupedByTraceName(ctx, projectId, now.Add(-time.Hour), now.Add(time.Hour), 1, 10, "count", "desc", "", "root")+ if err != nil {+ t.Fatalf("FindGroupedByTraceName failed: %v", err)+ }+ if len(stats) != 1 {+ t.Fatalf("expected 1 grouped stat, got %d", len(stats))+ }+ if stats[0].Count != 4 {+ t.Errorf("expected count 4 under rootFilter=root, got %d", stats[0].Count)+ }+ if stats[0].P50Duration != 200*time.Millisecond {+ t.Errorf("P50 computed over unfiltered rows: got %v, want 200ms", stats[0].P50Duration)+ }+ if stats[0].P95Duration != 200*time.Millisecond {+ t.Errorf("P95 computed over unfiltered rows: got %v, want 200ms", stats[0].P95Duration)+ }+}++// FindGroupedByTraceName sorts and paginates in Go on P50/P95, so percentiles+// computed over the unfiltered population reorder the page as well as+// misreporting it. These two traces rank one way on all rows and the other way+// on root rows alone.+func TestAiTraceRepository_FindGroupedByTraceName_RanksOnFilteredRows(t *testing.T) {+ setupTestDB(t)+ ctx := context.Background()+ projectId := uuid.New()+ now := truncateMs(time.Now().UTC())++ var traces []models.AiTrace+ for range 4 {+ // Slow as a root call, which is what "root" asks to see.+ traces = append(traces, makeAiTraceWithRoot(projectId, "trace.slow-root", 500*time.Millisecond, 100, 0.01, now, true))+ traces = append(traces, makeAiTraceWithRoot(projectId, "trace.slow-root", 50*time.Millisecond, 100, 0.01, now, false))+ // Fast as a root call, slow only in the rows the filter drops.+ traces = append(traces, makeAiTraceWithRoot(projectId, "trace.fast-root", 100*time.Millisecond, 100, 0.01, now, true))+ traces = append(traces, makeAiTraceWithRoot(projectId, "trace.fast-root", 10*time.Second, 100, 0.01, now, false))+ }++ if err := AiTraceRepository.InsertAsync(ctx, traces); err != nil {+ t.Fatalf("InsertAsync failed: %v", err)+ }++ stats, _, err := AiTraceRepository.FindGroupedByTraceName(ctx, projectId, now.Add(-time.Hour), now.Add(time.Hour), 1, 10, "p95_duration", "desc", "", "root")+ if err != nil {+ t.Fatalf("FindGroupedByTraceName failed: %v", err)+ }+ if len(stats) != 2 {+ t.Fatalf("expected 2 grouped stats, got %d", len(stats))+ }+ if stats[0].TraceName != "trace.slow-root" {+ t.Errorf("page ordered on unfiltered percentiles: got %q first, want \"trace.slow-root\"", stats[0].TraceName)+ }+}diff --git a/backend/app/repositories/telemetry/endpoint_repository_test.go b/backend/app/repositories/telemetry/endpoint_repository_test.goindex d4488e1d..2bc8d348 100644--- a/backend/app/repositories/telemetry/endpoint_repository_test.go+++ b/backend/app/repositories/telemetry/endpoint_repository_test.go@@ -582,3 +582,41 @@ func TestEndpointRepository_FindGroupedByEndpoint_RootFilterPercentiles(t *testit.Errorf("p95 = %v, want the root-only 100ms; non-root durations leaked into the percentile", stats[0].P95Duration)}}++// The chart ranks the top 5 on percentiles and then plots only the filtered+// rows, so ranking on the unfiltered population puts endpoints on the chart that+// are not slow under the filter. These two rank one way on all rows and the+// other way on root rows alone.+func TestEndpointRepository_GetEndpointStackedChart_RanksOnFilteredRows(t *testing.T) {+ setupTestDB(t)+ ctx := context.Background()+ projectId := uuid.New()+ now := truncateMs(time.Now().UTC())++ var endpoints []models.Endpoint+ for range 3 {+ // Slow as a root request, which is what "root" asks to see.+ slowRoot := makeEndpoint(projectId, "GET /slow-root", 500*time.Millisecond, 200, now)+ slowRoot.IsRoot = true+ // Fast as a root request, slow only in the rows the filter drops.+ fastRoot := makeEndpoint(projectId, "GET /fast-root", 10*time.Millisecond, 200, now)+ fastRoot.IsRoot = true+ endpoints = append(endpoints, slowRoot, fastRoot,+ makeEndpoint(projectId, "GET /fast-root", 5*time.Second, 200, now))+ }++ if err := EndpointRepository.InsertAsync(ctx, endpoints); err != nil {+ t.Fatalf("InsertAsync failed: %v", err)+ }++ chart, err := EndpointRepository.GetEndpointStackedChart(ctx, projectId, now.Add(-time.Hour), now.Add(time.Hour), 5, "p95", "", "root", "")+ if err != nil {+ t.Fatalf("GetEndpointStackedChart failed: %v", err)+ }+ if len(chart.Endpoints) < 2 {+ t.Fatalf("expected both endpoints in the chart, got %v", chart.Endpoints)+ }+ if chart.Endpoints[0] != "GET /slow-root" {+ t.Errorf("top endpoint ranked on unfiltered rows: got %v, want 'GET /slow-root' first", chart.Endpoints)+ }+}diff --git a/backend/app/repositories/telemetry/helpers_test.go b/backend/app/repositories/telemetry/helpers_test.goindex cfbc6a5b..e58ae2a3 100644--- a/backend/app/repositories/telemetry/helpers_test.go+++ b/backend/app/repositories/telemetry/helpers_test.go@@ -44,6 +44,12 @@ func makeTask(projectId uuid.UUID, taskName string, duration time.Duration, reco}}+func makeTaskWithRoot(projectId uuid.UUID, taskName string, duration time.Duration, recordedAt time.Time, isRoot bool) models.Task {+ t := makeTask(projectId, taskName, duration, recordedAt)+ t.IsRoot = isRoot+ return t+}+func makeAiTrace(projectId uuid.UUID, traceName string, duration time.Duration, totalTokens int64, totalCost float64, recordedAt time.Time) models.AiTrace {return models.AiTrace{Id: uuid.New(),@@ -61,10 +67,18 @@ func makeAiTrace(projectId uuid.UUID, traceName string, duration time.Duration,TraceName: traceName,ServerName: "test-server",AppVersion: "1.0.0",- IsRoot: true,+ // Unlike makeTask/makeEndpoint, AI traces default to root -- callers that+ // need a child span go through makeAiTraceWithRoot.+ IsRoot: true,}}+func makeAiTraceWithRoot(projectId uuid.UUID, traceName string, duration time.Duration, totalTokens int64, totalCost float64, recordedAt time.Time, isRoot bool) models.AiTrace {+ tr := makeAiTrace(projectId, traceName, duration, totalTokens, totalCost, recordedAt)+ tr.IsRoot = isRoot+ return tr+}+func makeException(projectId uuid.UUID, hash, stackTrace string, recordedAt time.Time) models.ExceptionStackTrace {return models.ExceptionStackTrace{Id: uuid.New(),diff --git a/backend/app/repositories/telemetry/sqlite/ai_trace.repository.go b/backend/app/repositories/telemetry/sqlite/ai_trace.repository.goindex a03f7f88..05342baf 100644--- a/backend/app/repositories/telemetry/sqlite/ai_trace.repository.go+++ b/backend/app/repositories/telemetry/sqlite/ai_trace.repository.go@@ -231,15 +231,24 @@ func (r *aiTraceRepository) InsertAsync(ctx context.Context, lines []models.AiTrreturn tx.Commit()}-func (r *aiTraceRepository) FindGroupedByTraceName(ctx context.Context, projectId uuid.UUID, fromDate, toDate time.Time, page, pageSize int, orderBy, sortDirection, search, rootFilter string) ([]models.AiTraceStats, int64, error) {- params := lit.P{"project_id": projectId, "from": sqlitetypes.NewSQLiteTime(fromDate), "to": sqlitetypes.NewSQLiteTime(toDate)}-- whereClause := "project_id = :project_id AND recorded_at >= :from AND recorded_at <= :to"+// aiTraceFilterClause appends the AI-traces list's filter to a WHERE clause and+// binds what it needs into params. Both the query that selects a trace_name and+// the query that reads its durations go through it, so they cannot filter+// differently.+func aiTraceFilterClause(params lit.P, search, rootFilter string) string {+ clause := ""if search != "" {- whereClause += " AND INSTR(LOWER(trace_name), LOWER(:search)) > 0"+ clause += " AND INSTR(LOWER(trace_name), LOWER(:search)) > 0"params["search"] = search}- whereClause += shared.RootFilterClause("is_root", rootFilter)+ clause += shared.RootFilterClause("is_root", rootFilter)+ return clause+}++func (r *aiTraceRepository) FindGroupedByTraceName(ctx context.Context, projectId uuid.UUID, fromDate, toDate time.Time, page, pageSize int, orderBy, sortDirection, search, rootFilter string) ([]models.AiTraceStats, int64, error) {+ params := lit.P{"project_id": projectId, "from": sqlitetypes.NewSQLiteTime(fromDate), "to": sqlitetypes.NewSQLiteTime(toDate)}++ whereClause := "project_id = :project_id AND recorded_at >= :from AND recorded_at <= :to" + aiTraceFilterClause(params, search, rootFilter)countResult, err := lit.SelectSingleNamed[models.CountResult](db.TelemetryDB,"SELECT COUNT(DISTINCT trace_name) AS count FROM ai_traces WHERE "+whereClause, params)@@ -271,9 +280,10 @@ func (r *aiTraceRepository) FindGroupedByTraceName(ctx context.Context, projectIfor _, row := range rows {// Compute percentiles from raw durations for this trace_namedurationParams := lit.P{"project_id": projectId, "from": sqlitetypes.NewSQLiteTime(fromDate), "to": sqlitetypes.NewSQLiteTime(toDate), "trace_name": row.TraceName}+ durationFilter := aiTraceFilterClause(durationParams, search, rootFilter)durationRows, err := lit.SelectNamed[aiTraceDurationRow](db.TelemetryDB,`SELECT CAST(duration AS REAL) AS duration FROM ai_traces- WHERE project_id = :project_id AND trace_name = :trace_name AND recorded_at >= :from AND recorded_at <= :to+ WHERE project_id = :project_id AND trace_name = :trace_name AND recorded_at >= :from AND recorded_at <= :to`+durationFilter+`ORDER BY duration ASC`, durationParams)if err != nil {return nil, 0, errdiff --git a/backend/app/repositories/telemetry/sqlite/endpoint.repository.go b/backend/app/repositories/telemetry/sqlite/endpoint.repository.goindex 41577084..d547b39b 100644--- a/backend/app/repositories/telemetry/sqlite/endpoint.repository.go+++ b/backend/app/repositories/telemetry/sqlite/endpoint.repository.go@@ -306,7 +306,7 @@ func (e *endpointRepository) FindGroupedByEndpoint(ctx context.Context, projectIcontinue}- durations, err := fetchSortedDurations(ctx, projectId, g.Endpoint, fromDate, toDate, rootFilter)+ durations, err := fetchSortedDurations(ctx, projectId, g.Endpoint, fromDate, toDate, search, rootFilter, methodFilter)if err != nil {return nil, 0, err}@@ -534,7 +534,7 @@ func (e *endpointRepository) FindWorstEndpoints(ctx context.Context, projectId uvar stats []models.EndpointStatsfor _, g := range groups {- durations, err := fetchSortedDurations(ctx, projectId, g.Endpoint, start, end, "")+ durations, err := fetchSortedDurations(ctx, projectId, g.Endpoint, start, end, "", "", "")if err != nil {return nil, err}@@ -616,7 +616,7 @@ func (e *endpointRepository) GetEndpointStats(ctx context.Context, projectId uuistats.Apdex = row.SatisfiedTolerating / float64(row.Count)}- durations, err := fetchSortedDurations(ctx, projectId, endpoint, start, end, "")+ durations, err := fetchSortedDurations(ctx, projectId, endpoint, start, end, "", "", "")if err != nil {return nil, err}@@ -838,10 +838,17 @@ func (e *endpointRepository) UpsertSlowEndpoint(ctx context.Context, projectId u// --- helpers ----func fetchSortedDurations(ctx context.Context, projectId uuid.UUID, endpoint string, from, to time.Time, rootFilter string) ([]float64, error) {+// fetchSortedDurations runs the same filter as the query that selected the+// endpoint, via endpointFilterClause rather than picking out the one leg that+// constrains rows today, so a row-level predicate added there cannot silently+// leave the percentiles describing a different population.+func fetchSortedDurations(ctx context.Context, projectId uuid.UUID, endpoint string, from, to time.Time, search, rootFilter, methodFilter string) ([]float64, error) {+ params := lit.P{"project_id": projectId, "endpoint": endpoint, "from": sqlitetypes.NewSQLiteTime(from), "to": sqlitetypes.NewSQLiteTime(to)}+ filterClause := endpointFilterClause(params, "", search, rootFilter, methodFilter)+results, err := lit.SelectNamed[endpointDurationRow](db.TelemetryDB,- "SELECT duration FROM endpoints WHERE project_id = :project_id AND endpoint = :endpoint AND recorded_at >= :from AND recorded_at <= :to AND is_stream = 0"+shared.RootFilterClause("is_root", rootFilter)+" ORDER BY duration ASC",- lit.P{"project_id": projectId, "endpoint": endpoint, "from": sqlitetypes.NewSQLiteTime(from), "to": sqlitetypes.NewSQLiteTime(to)})+ "SELECT duration FROM endpoints WHERE project_id = :project_id AND endpoint = :endpoint AND recorded_at >= :from AND recorded_at <= :to AND is_stream = 0"+filterClause+" ORDER BY duration ASC",+ params)if err != nil {return nil, err}@@ -925,7 +932,7 @@ func getTopEndpointsByMetric(ctx context.Context, projectId uuid.UUID, from, tovar metrics []epMetricfor _, ep := range epRows {- durations, err := fetchSortedDurations(ctx, projectId, ep.Endpoint, from, to, rootFilter)+ durations, err := fetchSortedDurations(ctx, projectId, ep.Endpoint, from, to, search, rootFilter, methodFilter)if err != nil {return nil, err}diff --git a/backend/app/repositories/telemetry/sqlite/task.repository.go b/backend/app/repositories/telemetry/sqlite/task.repository.goindex 0cb03841..6c2e05a7 100644--- a/backend/app/repositories/telemetry/sqlite/task.repository.go+++ b/backend/app/repositories/telemetry/sqlite/task.repository.go@@ -168,14 +168,22 @@ func (e *taskRepository) FindAll(ctx context.Context, projectId uuid.UUID, fromDreturn tasks, count, nil}-func (e *taskRepository) FindGroupedByTaskName(ctx context.Context, projectId uuid.UUID, fromDate, toDate time.Time, page, pageSize int, orderBy string, sortDirection string, search string, rootFilter string) ([]models.TaskStats, int64, error) {- params := lit.P{"project_id": projectId, "from": sqlitetypes.NewSQLiteTime(fromDate), "to": sqlitetypes.NewSQLiteTime(toDate)}- whereClause := "project_id = :project_id AND recorded_at >= :from AND recorded_at <= :to"+// taskFilterClause appends the task list's filter to a WHERE clause and binds+// what it needs into params. Both the query that selects a task and the query+// that reads its durations go through it, so they cannot filter differently.+func taskFilterClause(params lit.P, search, rootFilter string) string {+ clause := ""if search != "" {- whereClause += " AND INSTR(LOWER(task_name), LOWER(:search)) > 0"+ clause += " AND INSTR(LOWER(task_name), LOWER(:search)) > 0"params["search"] = search}- whereClause += shared.RootFilterClause("is_root", rootFilter)+ clause += shared.RootFilterClause("is_root", rootFilter)+ return clause+}++func (e *taskRepository) FindGroupedByTaskName(ctx context.Context, projectId uuid.UUID, fromDate, toDate time.Time, page, pageSize int, orderBy string, sortDirection string, search string, rootFilter string) ([]models.TaskStats, int64, error) {+ params := lit.P{"project_id": projectId, "from": sqlitetypes.NewSQLiteTime(fromDate), "to": sqlitetypes.NewSQLiteTime(toDate)}+ whereClause := "project_id = :project_id AND recorded_at >= :from AND recorded_at <= :to" + taskFilterClause(params, search, rootFilter)totalResult, err := lit.SelectSingleNamed[models.CountResult](db.TelemetryDB,"SELECT COUNT(DISTINCT task_name) AS count FROM tasks WHERE "+whereClause,@@ -198,10 +206,6 @@ func (e *taskRepository) FindGroupedByTaskName(ctx context.Context, projectId uuoffset := (page - 1) * pageSizevar baseQuery string- groupParams := lit.P{"project_id": projectId, "from": sqlitetypes.NewSQLiteTime(fromDate), "to": sqlitetypes.NewSQLiteTime(toDate)}- if search != "" {- groupParams["search"] = search- }groupedCols := `task_name, COUNT(*) as count, AVG(duration) as avg_duration, MAX(recorded_at) as last_seen,MAX(is_root) as has_root, MAX(CASE WHEN is_root = 0 THEN 1 ELSE 0 END) as has_non_root`@@ -219,18 +223,18 @@ func (e *taskRepository) FindGroupedByTaskName(ctx context.Context, projectId uubaseQuery = fmt.Sprintf(`SELECT `+groupedCols+`FROM tasks WHERE `+whereClause+`GROUP BY task_name ORDER BY %s %s LIMIT :limit OFFSET :offset`, expr, sortDir)- groupParams["limit"] = pageSize- groupParams["offset"] = offset+ params["limit"] = pageSize+ params["offset"] = offset}- groups, err := lit.SelectNamed[taskGroupRow](db.TelemetryDB, baseQuery, groupParams)+ groups, err := lit.SelectNamed[taskGroupRow](db.TelemetryDB, baseQuery, params)if err != nil {return nil, 0, err}var stats []models.TaskStatsfor _, g := range groups {- durations, err := fetchSortedTaskDurations(ctx, projectId, g.TaskName, fromDate, toDate)+ durations, err := fetchSortedTaskDurations(ctx, projectId, g.TaskName, fromDate, toDate, search, rootFilter)if err != nil {return nil, 0, err}@@ -419,7 +423,7 @@ func (e *taskRepository) FindWorstTasks(ctx context.Context, projectId uuid.UUIDvar stats []models.TaskStatsfor _, g := range groups {- durations, err := fetchSortedTaskDurations(ctx, projectId, g.TaskName, start, end)+ durations, err := fetchSortedTaskDurations(ctx, projectId, g.TaskName, start, end, "", "")if err != nil {return nil, err}@@ -465,7 +469,7 @@ func (e *taskRepository) GetTaskStats(ctx context.Context, projectId uuid.UUID,return &models.TaskDetailStats{}, nil}- durations, err := fetchSortedTaskDurations(ctx, projectId, taskName, start, end)+ durations, err := fetchSortedTaskDurations(ctx, projectId, taskName, start, end, "", "")if err != nil {return nil, err}@@ -525,10 +529,13 @@ func (e *taskRepository) FindByDistributedTraceId(ctx context.Context, distributreturn tasks, nil}-func fetchSortedTaskDurations(ctx context.Context, projectId uuid.UUID, taskName string, from, to time.Time) ([]float64, error) {+func fetchSortedTaskDurations(ctx context.Context, projectId uuid.UUID, taskName string, from, to time.Time, search, rootFilter string) ([]float64, error) {+ params := lit.P{"project_id": projectId, "task_name": taskName, "from": sqlitetypes.NewSQLiteTime(from), "to": sqlitetypes.NewSQLiteTime(to)}+ filterClause := taskFilterClause(params, search, rootFilter)+results, err := lit.SelectNamed[durationValueRow](db.TelemetryDB,- "SELECT duration FROM tasks WHERE project_id = :project_id AND task_name = :task_name AND recorded_at >= :from AND recorded_at <= :to ORDER BY duration ASC",- lit.P{"project_id": projectId, "task_name": taskName, "from": sqlitetypes.NewSQLiteTime(from), "to": sqlitetypes.NewSQLiteTime(to)})+ "SELECT duration FROM tasks WHERE project_id = :project_id AND task_name = :task_name AND recorded_at >= :from AND recorded_at <= :to"+filterClause+" ORDER BY duration ASC",+ params)if err != nil {return nil, err}diff --git a/backend/app/repositories/telemetry/task_repository_test.go b/backend/app/repositories/telemetry/task_repository_test.goindex 469de9e5..92b5cf6d 100644--- a/backend/app/repositories/telemetry/task_repository_test.go+++ b/backend/app/repositories/telemetry/task_repository_test.go@@ -441,3 +441,74 @@ func TestTaskRepository_GetTaskStats_EmptyWindow(t *testing.T) {t.Errorf("expected count 0, got %d", stats.Count)}}++// The P50/P95 columns must describe the rows the active filter selects.+func TestTaskRepository_FindGroupedByTaskName_PercentilesUseFilteredRows(t *testing.T) {+ setupTestDB(t)+ ctx := context.Background()+ projectId := uuid.New()+ now := truncateMs(time.Now().UTC())++ var tasks []models.Task+ for range 4 {+ tasks = append(tasks, makeTaskWithRoot(projectId, "nightly.report", 100*time.Millisecond, now, true))+ tasks = append(tasks, makeTaskWithRoot(projectId, "nightly.report", 10*time.Second, now, false))+ }++ if err := TaskRepository.InsertAsync(ctx, tasks); err != nil {+ t.Fatalf("InsertAsync failed: %v", err)+ }++ stats, _, err := TaskRepository.FindGroupedByTaskName(ctx, projectId, now.Add(-time.Hour), now.Add(time.Hour), 1, 10, "count", "desc", "", "root")+ if err != nil {+ t.Fatalf("FindGroupedByTaskName failed: %v", err)+ }+ if len(stats) != 1 {+ t.Fatalf("expected 1 grouped stat, got %d", len(stats))+ }+ if stats[0].Count != 4 {+ t.Errorf("expected count 4 under rootFilter=root, got %d", stats[0].Count)+ }+ if stats[0].P50Duration != 100*time.Millisecond {+ t.Errorf("P50 computed over unfiltered rows: got %v, want 100ms", stats[0].P50Duration)+ }+ if stats[0].P95Duration != 100*time.Millisecond {+ t.Errorf("P95 computed over unfiltered rows: got %v, want 100ms", stats[0].P95Duration)+ }+}++// orderBy=p50_duration/p95_duration/impact takes the Go-sort path, so percentiles+// computed over the unfiltered population reorder the page as well as+// misreporting it. Here the two tasks rank one way on all rows and the other way+// on root rows alone.+func TestTaskRepository_FindGroupedByTaskName_RanksOnFilteredRows(t *testing.T) {+ setupTestDB(t)+ ctx := context.Background()+ projectId := uuid.New()+ now := truncateMs(time.Now().UTC())++ var tasks []models.Task+ for range 4 {+ // Slow as a root task, which is what "root" asks to see.+ tasks = append(tasks, makeTaskWithRoot(projectId, "task.slow-root", 500*time.Millisecond, now, true))+ tasks = append(tasks, makeTaskWithRoot(projectId, "task.slow-root", 50*time.Millisecond, now, false))+ // Fast as a root task, slow only in the rows the filter drops.+ tasks = append(tasks, makeTaskWithRoot(projectId, "task.fast-root", 100*time.Millisecond, now, true))+ tasks = append(tasks, makeTaskWithRoot(projectId, "task.fast-root", 10*time.Second, now, false))+ }++ if err := TaskRepository.InsertAsync(ctx, tasks); err != nil {+ t.Fatalf("InsertAsync failed: %v", err)+ }++ stats, _, err := TaskRepository.FindGroupedByTaskName(ctx, projectId, now.Add(-time.Hour), now.Add(time.Hour), 1, 10, "p95_duration", "desc", "", "root")+ if err != nil {+ t.Fatalf("FindGroupedByTaskName failed: %v", err)+ }+ if len(stats) != 2 {+ t.Fatalf("expected 2 grouped stats, got %d", len(stats))+ }+ if stats[0].TaskName != "task.slow-root" {+ t.Errorf("page ordered on unfiltered percentiles: got %q first, want \"task.slow-root\"", stats[0].TaskName)+ }+}