Skip to content

Commit 0977b4e

Browse files
committed
fix(parca-dev#2598): querying non-range profile w/ buckets
1 parent 24af885 commit 0977b4e

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,5 @@ require (
245245
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
246246
sigs.k8s.io/yaml v1.3.0 // indirect
247247
)
248+
249+
replace github.com/polarsignals/frostdb => /home/albertlockett/Development/arcticdb

pkg/parcacol/querier.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ const (
344344
ColumnPeriodSum = "sum(" + profile.ColumnPeriod + ")"
345345
ColumnValueCount = "count(" + profile.ColumnValue + ")"
346346
ColumnValueSum = "sum(" + profile.ColumnValue + ")"
347+
ColumnValueFirst = "first(" + profile.ColumnValue + ")"
347348
)
348349

349350
func (q *Querier) queryRangeDelta(ctx context.Context, filterExpr logicalplan.Expr, step time.Duration, sampleTypeUnit string) ([]*pb.MetricsSeries, error) {
@@ -531,17 +532,27 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
531532
Filter(filterExpr).
532533
Aggregate(
533534
[]logicalplan.Expr{
534-
logicalplan.Sum(logicalplan.Col(profile.ColumnValue)),
535+
logicalplan.Sum(logicalplan.Col(profile.ColumnValue)).Alias(ColumnValueFirst),
535536
},
536537
[]logicalplan.Expr{
537538
logicalplan.DynCol(profile.ColumnLabels),
538539
logicalplan.Col(profile.ColumnTimestamp),
539540
},
540541
).
542+
Aggregate(
543+
[]logicalplan.Expr{
544+
logicalplan.Take(logicalplan.Col(profile.ColumnValue), 1).Alias(ColumnValueFirst),
545+
},
546+
[]logicalplan.Expr{
547+
logicalplan.DynCol(profile.ColumnLabels),
548+
logicalplan.Duration(1000 * time.Millisecond),
549+
},
550+
).
541551
Execute(ctx, func(ctx context.Context, r arrow.Record) error {
542552
r.Retain()
543553
records = append(records, r)
544554
rows += int(r.NumRows())
555+
fmt.Printf("%v\n", r)
545556
return nil
546557
})
547558
if err != nil {
@@ -561,7 +572,7 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
561572
// Add necessary columns and their found value is false by default.
562573
columnIndices := map[string]columnIndex{
563574
profile.ColumnTimestamp: {},
564-
ColumnValueSum: {},
575+
ColumnValueFirst: {},
565576
}
566577
labelColumnIndices := []int{}
567578
labelSet := labels.Labels{}
@@ -623,7 +634,11 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
623634
}
624635

625636
ts := ar.Column(columnIndices[profile.ColumnTimestamp].index).(*array.Int64).Value(i)
626-
value := ar.Column(columnIndices[ColumnValueSum].index).(*array.Int64).Value(i)
637+
638+
// value := ar.Column(columnIndices[ColumnValueFirst].index).(*array.Int64).Value(i)
639+
valueList := ar.Column(columnIndices[ColumnValueFirst].index).(*array.List)
640+
start, _ := valueList.ValueOffsets(i)
641+
value := valueList.ListValues().(*array.Int64).Value(int(start))
627642

628643
// Each step bucket will only return one of the timestamps and its value.
629644
// For this reason we'll take each timestamp and divide it by the step seconds.
@@ -634,6 +649,7 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
634649
// This needs to be moved to FrostDB to not even query all of this data in the first place.
635650
// With a scrape interval of 10s and a query range of 1d we'd query 8640 samples and at most return 960.
636651
// Even worse for a week, we'd query 60480 samples and only return 1000.
652+
637653
tsBucket := ts / 1000 / int64(step.Seconds())
638654
if _, found := resSeriesBuckets[index][tsBucket]; found {
639655
// We already have a MetricsSample for this timestamp bucket, ignore it.

pkg/symbolizer/__debug_bin3784063650

64.8 MB
Binary file not shown.

0 commit comments

Comments
 (0)