Skip to content

Commit cdd0d0b

Browse files
committed
pkg/query: Handle queries when no columns are found
This happens when the timestamp for the query is too old or simply doesn't exist. Parca should return NotFound and not Unknown gRPC codes.
1 parent 4616021 commit cdd0d0b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pkg/parcacol/arrow.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ import (
2424
"github.com/parca-dev/parca/pkg/profile"
2525
)
2626

27+
type ErrMissingColumn struct {
28+
column string
29+
columns int
30+
}
31+
32+
func (e ErrMissingColumn) Error() string {
33+
return fmt.Sprintf("expected column %s, got %d columns", e.column, e.columns)
34+
}
35+
2736
func ArrowRecordToStacktraceSamples(
2837
ctx context.Context,
2938
m pb.MetastoreServiceClient,
@@ -34,13 +43,13 @@ func ArrowRecordToStacktraceSamples(
3443
schema := ar.Schema()
3544
indices := schema.FieldIndices("stacktrace")
3645
if len(indices) != 1 {
37-
return nil, fmt.Errorf("expected exactly one stacktrace column, got %d", len(indices))
46+
return nil, ErrMissingColumn{column: "stacktrace", columns: len(indices)}
3847
}
3948
stacktraceColumn := ar.Column(indices[0]).(*array.Binary)
4049

4150
indices = schema.FieldIndices("sum(value)")
4251
if len(indices) != 1 {
43-
return nil, fmt.Errorf("expected exactly one value column, got %d", len(indices))
52+
return nil, ErrMissingColumn{column: "value", columns: len(indices)}
4453
}
4554
valueColumn := ar.Column(indices[0]).(*array.Int64)
4655

pkg/query/columnquery.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ func (q *ColumnQueryAPI) selectSingle(ctx context.Context, s *pb.SingleProfile)
563563
t := s.Time.AsTime()
564564
p, err := q.findSingle(ctx, s.Query, t)
565565
if err != nil {
566+
// if the column cannot be found the timestamp is too far in the past and we don't have data
567+
var colErr parcacol.ErrMissingColumn
568+
if errors.As(err, &colErr) {
569+
return nil, status.Error(codes.NotFound, "could not find profile at requested time and selectors")
570+
}
566571
return nil, err
567572
}
568573

0 commit comments

Comments
 (0)