Phlare: Fix panic on empty pprof profile (#64888)

pull/64999/head
Andrej Ocenas 2 years ago committed by GitHub
parent fef0ee913c
commit 998b035d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      pkg/tsdb/phlare/query.go
  2. 8
      pkg/tsdb/phlare/query_test.go

@ -374,6 +374,8 @@ func treeToNestedSetDataFrame(tree *ProfileTree, profileTypeID string) *data.Fra
labelField := NewEnumField("label", nil)
fileNameField := NewEnumField("fileName", nil)
// Tree can be nil if profile was empty, we can still send empty frame in that case
if tree != nil {
walkTree(tree, func(tree *ProfileTree) {
levelField.Append(int64(tree.Level))
valueField.Append(tree.Value)
@ -384,6 +386,7 @@ func treeToNestedSetDataFrame(tree *ProfileTree, profileTypeID string) *data.Fra
labelField.Append(tree.Function.FunctionName)
fileNameField.Append(tree.Function.FileName)
})
}
frame.Fields = append(frame.Fields, labelField.GetField(), fileNameField.GetField())
return frame

@ -109,6 +109,7 @@ func makeDataQuery() *backend.DataQuery {
}
func Test_treeToNestedDataFrame(t *testing.T) {
t.Run("sample profile tree", func(t *testing.T) {
tree := &ProfileTree{
Value: 100, Level: 0, Self: 1, Function: &Function{FunctionName: "root"}, Nodes: []*ProfileTree{
{
@ -145,6 +146,13 @@ func Test_treeToNestedDataFrame(t *testing.T) {
data.NewField("label", nil, []int64{0, 1, 2, 3}).SetConfig(labelConfig),
data.NewField("fileName", nil, []int64{0, 1, 2, 3}).SetConfig(filenameConfig),
}, frame.Fields)
})
t.Run("nil profile tree", func(t *testing.T) {
frame := treeToNestedSetDataFrame(nil, "memory:alloc_objects:count:space:bytes")
require.Equal(t, 6, len(frame.Fields))
require.Equal(t, 0, frame.Fields[0].Len())
})
}
var fooProfile = &googlev1.Profile{

Loading…
Cancel
Save