Skip to content

Commit f3ba44a

Browse files
authored
Merge pull request #5893 from parca-dev/nanosecond-ts
Use nanosecond timestamps for profile queries
2 parents 70a798c + 81eda32 commit f3ba44a

15 files changed

Lines changed: 1317 additions & 1462 deletions

File tree

pkg/parcacol/querier.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ func (q *Querier) Labels(
107107
}
108108

109109
if startTime.Unix() != 0 && endTime.Unix() != 0 {
110-
start := timestamp.FromTime(startTime)
111-
end := timestamp.FromTime(endTime)
110+
start := startTime.UnixNano()
111+
end := endTime.UnixNano()
112112

113113
filterExpr = append(filterExpr,
114-
logicalplan.Col(profile.ColumnTimestamp).Gt(logicalplan.Literal(start)),
115-
logicalplan.Col(profile.ColumnTimestamp).Lt(logicalplan.Literal(end)),
114+
logicalplan.Col(profile.ColumnTimeNanos).Gt(logicalplan.Literal(start)),
115+
logicalplan.Col(profile.ColumnTimeNanos).Lt(logicalplan.Literal(end)),
116116
)
117117
}
118118

@@ -170,11 +170,11 @@ func (q *Querier) Values(
170170
}
171171

172172
if startTime.Unix() != 0 && endTime.Unix() != 0 {
173-
start := timestamp.FromTime(startTime)
174-
end := timestamp.FromTime(endTime)
173+
start := startTime.UnixNano()
174+
end := endTime.UnixNano()
175175

176-
filterExpr = append(filterExpr, logicalplan.Col(profile.ColumnTimestamp).Gt(logicalplan.Literal(start)),
177-
logicalplan.Col(profile.ColumnTimestamp).Lt(logicalplan.Literal(end)))
176+
filterExpr = append(filterExpr, logicalplan.Col(profile.ColumnTimeNanos).Gt(logicalplan.Literal(start)),
177+
logicalplan.Col(profile.ColumnTimeNanos).Lt(logicalplan.Literal(end)))
178178
}
179179

180180
err := q.engine.ScanTable(q.tableName).
@@ -349,18 +349,18 @@ func (q *Querier) QueryRange(
349349
return nil, err
350350
}
351351

352-
start := timestamp.FromTime(startTime)
353-
end := timestamp.FromTime(endTime)
354-
355352
// The step cannot be lower than 1s
356353
if step < time.Second {
357354
step = time.Second
358355
}
359356

357+
start := startTime.UnixNano()
358+
end := endTime.UnixNano()
359+
360360
exprs := append(
361361
selectorExprs,
362-
logicalplan.Col(profile.ColumnTimestamp).Gt(logicalplan.Literal(start)),
363-
logicalplan.Col(profile.ColumnTimestamp).Lt(logicalplan.Literal(end)),
362+
logicalplan.Col(profile.ColumnTimeNanos).GtEq(logicalplan.Literal(start)),
363+
logicalplan.Col(profile.ColumnTimeNanos).LtEq(logicalplan.Literal(end)),
364364
)
365365

366366
filterExpr := logicalplan.And(exprs...)
@@ -403,17 +403,17 @@ func (q *Querier) queryRangeDelta(
403403
totalSum := logicalplan.Sum(logicalplan.Col(profile.ColumnValue))
404404
totalSumColumn := totalSum.Name()
405405
durationMin := logicalplan.Min(logicalplan.Col(profile.ColumnDuration))
406-
timestampUnique := logicalplan.Unique(logicalplan.Col(profile.ColumnTimestamp))
406+
timestampUnique := logicalplan.Unique(logicalplan.Col(profile.ColumnTimeNanos))
407407

408408
preProjection := []logicalplan.Expr{
409409
logicalplan.Mul(
410410
logicalplan.Div(
411-
logicalplan.Col(profile.ColumnTimestamp),
412-
logicalplan.Literal(step.Milliseconds()),
411+
logicalplan.Col(profile.ColumnTimeNanos),
412+
logicalplan.Literal(step.Nanoseconds()),
413413
),
414-
logicalplan.Literal(step.Milliseconds()),
414+
logicalplan.Literal(step.Nanoseconds()),
415415
).Alias(TimestampBucket),
416-
logicalplan.Col(profile.ColumnTimestamp),
416+
logicalplan.Col(profile.ColumnTimeNanos),
417417
logicalplan.DynCol(profile.ColumnLabels),
418418
logicalplan.Col(profile.ColumnDuration),
419419
}
@@ -610,7 +610,7 @@ func (q *Querier) queryRangeDelta(
610610

611611
series := resSeries[index]
612612
series.Samples = append(series.Samples, &pb.MetricsSample{
613-
Timestamp: timestamppb.New(timestamp.Time(ts)),
613+
Timestamp: timestamppb.New(time.Unix(0, ts)),
614614
Value: valueSum,
615615
ValuePerSecond: valuePerSecond,
616616
Duration: duration,
@@ -655,7 +655,7 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
655655
valueSum,
656656
},
657657
[]logicalplan.Expr{
658-
logicalplan.Col(profile.ColumnTimestamp),
658+
logicalplan.Col(profile.ColumnTimeNanos),
659659
logicalplan.DynCol(profile.ColumnLabels),
660660
},
661661
).
@@ -681,7 +681,7 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
681681
}
682682
// Add necessary columns and their found value is false by default.
683683
columnIndices := map[string]columnIndex{
684-
profile.ColumnTimestamp: {},
684+
profile.ColumnTimeNanos: {},
685685
valueSumColumn: {},
686686
}
687687
labelColumnIndices := []int{}
@@ -744,7 +744,7 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
744744
resSeriesBuckets[index] = map[int64]struct{}{}
745745
}
746746

747-
ts := ar.Column(columnIndices[profile.ColumnTimestamp].index).(*array.Int64).Value(i)
747+
ts := ar.Column(columnIndices[profile.ColumnTimeNanos].index).(*array.Int64).Value(i)
748748
value := ar.Column(columnIndices[valueSumColumn].index).(*array.Int64).Value(i)
749749

750750
// Each step bucket will only return one of the timestamps and its value.
@@ -764,7 +764,7 @@ func (q *Querier) queryRangeNonDelta(ctx context.Context, filterExpr logicalplan
764764

765765
series := resSeries[index]
766766
series.Samples = append(series.Samples, &pb.MetricsSample{
767-
Timestamp: timestamppb.New(timestamp.Time(ts)),
767+
Timestamp: timestamppb.New(time.Unix(0, ts)),
768768
Value: value,
769769
ValuePerSecond: float64(value),
770770
})
@@ -966,7 +966,7 @@ func (q *Querier) SymbolizeArrowRecord(
966966
defer valuePerSecondColumn.Release()
967967
}
968968

969-
indices = schema.FieldIndices(profile.ColumnTimestamp)
969+
indices = schema.FieldIndices(profile.ColumnTimeNanos)
970970
var timestampColumn *array.Int64
971971
if len(indices) == 1 {
972972
timestampColumn = r.Column(indices[0]).(*array.Int64)
@@ -1450,15 +1450,15 @@ func (q *Querier) selectMerge(
14501450
return nil, "", queryParts, err
14511451
}
14521452

1453-
start := timestamp.FromTime(startTime)
1454-
end := timestamp.FromTime(endTime)
1453+
start := startTime.UnixNano()
1454+
end := endTime.UnixNano()
14551455
resultType := queryParts.Meta.SampleType
14561456

14571457
filterExpr := logicalplan.And(
14581458
append(
14591459
selectorExprs,
1460-
logicalplan.Col(profile.ColumnTimestamp).GtEq(logicalplan.Literal(start)),
1461-
logicalplan.Col(profile.ColumnTimestamp).LtEq(logicalplan.Literal(end)),
1460+
logicalplan.Col(profile.ColumnTimeNanos).GtEq(logicalplan.Literal(start)),
1461+
logicalplan.Col(profile.ColumnTimeNanos).LtEq(logicalplan.Literal(end)),
14621462
)...,
14631463
)
14641464

@@ -1495,9 +1495,9 @@ func (q *Querier) selectMerge(
14951495

14961496
for _, col := range groupByLabels {
14971497
if col == profile.ColumnTimestamp {
1498-
firstProject = append(firstProject, logicalplan.Col(profile.ColumnTimeNanos).Alias(profile.ColumnTimestamp))
1499-
columnsGroupBy = append(columnsGroupBy, logicalplan.Col(profile.ColumnTimestamp))
1500-
finalProject = append(finalProject, logicalplan.Col(profile.ColumnTimestamp))
1498+
firstProject = append(firstProject, logicalplan.Col(profile.ColumnTimeNanos).Alias(profile.ColumnTimeNanos))
1499+
columnsGroupBy = append(columnsGroupBy, logicalplan.Col(profile.ColumnTimeNanos))
1500+
finalProject = append(finalProject, logicalplan.Col(profile.ColumnTimeNanos))
15011501
}
15021502
}
15031503

@@ -1554,13 +1554,13 @@ func (q *Querier) GetProfileMetadataMappings(
15541554
return nil, err
15551555
}
15561556

1557-
start := timestamp.FromTime(startTime)
1558-
end := timestamp.FromTime(endTime)
1557+
start := startTime.UnixNano()
1558+
end := endTime.UnixNano()
15591559
filterExpr := logicalplan.And(
15601560
append(
15611561
selectorExprs,
1562-
logicalplan.Col(profile.ColumnTimestamp).GtEq(logicalplan.Literal(start)),
1563-
logicalplan.Col(profile.ColumnTimestamp).LtEq(logicalplan.Literal(end)),
1562+
logicalplan.Col(profile.ColumnTimeNanos).GtEq(logicalplan.Literal(start)),
1563+
logicalplan.Col(profile.ColumnTimeNanos).LtEq(logicalplan.Literal(end)),
15641564
)...,
15651565
)
15661566

@@ -1618,13 +1618,13 @@ func (q *Querier) GetProfileMetadataLabels(
16181618
return nil, err
16191619
}
16201620

1621-
start := timestamp.FromTime(startTime)
1622-
end := timestamp.FromTime(endTime)
1621+
start := startTime.UnixNano()
1622+
end := endTime.UnixNano()
16231623
filterExpr := logicalplan.And(
16241624
append(
16251625
selectorExprs,
1626-
logicalplan.Col(profile.ColumnTimestamp).GtEq(logicalplan.Literal(start)),
1627-
logicalplan.Col(profile.ColumnTimestamp).LtEq(logicalplan.Literal(end)),
1626+
logicalplan.Col(profile.ColumnTimeNanos).GtEq(logicalplan.Literal(start)),
1627+
logicalplan.Col(profile.ColumnTimeNanos).LtEq(logicalplan.Literal(end)),
16281628
)...,
16291629
)
16301630

pkg/query/columnquery_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ func TestColumnQueryAPIQueryRange(t *testing.T) {
221221
)
222222
res, err := api.QueryRange(ctx, &pb.QueryRangeRequest{
223223
Query: `memory:alloc_objects:count:space:bytes{job="default"}`,
224-
Start: timestamppb.New(timestamp.Time(0)),
225-
End: timestamppb.New(timestamp.Time(9223372036854775807)),
224+
Start: timestamppb.New(time.Unix(0, 0)),
225+
End: timestamppb.New(time.Unix(0, 9223372036854775807)),
226226
})
227227
require.NoError(t, err)
228228
require.Equal(t, 1, len(res.Series))
@@ -462,8 +462,8 @@ func TestColumnQueryAPIQueryFgprof(t *testing.T) {
462462

463463
res, err := api.QueryRange(ctx, &pb.QueryRangeRequest{
464464
Query: `fgprof:samples:count:wallclock:nanoseconds:delta`,
465-
Start: timestamppb.New(timestamp.Time(0)),
466-
End: timestamppb.New(timestamp.Time(9223372036854775807)),
465+
Start: timestamppb.New(time.Unix(0, 0)),
466+
End: timestamppb.New(time.Unix(0, 9223372036854775807)),
467467
SumBy: []string{"job"},
468468
})
469469
require.NoError(t, err)

ui/packages/shared/profile/src/GraphTooltipArrow/Content.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,12 @@ const TooltipMetaInfo = ({table, row}: {table: Table<any>; row: number}): React.
159159

160160
return (
161161
<>
162-
{timestamp == null || timestamp === 0n ? (
163-
<div className="pt-2" />
164-
) : (
162+
{timestamp != null && timestamp !== 0n && (
165163
<tr>
166164
<td className="w-1/4 pt-2">Timestamp</td>
167165
<td className="w-3/4 pt-2 break-all">
168166
{formatDateTimeDownToMS(new Date(Number(timestamp / 1000000n)), timezone)}
169-
</td>{' '}
167+
</td>
170168
</tr>
171169
)}
172170
<tr>

0 commit comments

Comments
 (0)