Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sanitization of samples with negative value #3627

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,11 @@ func sanitizeProfile(p *profilev1.Profile) {
if len(x.Value) != vs {
return true
}
for i := range x.Value {
if x.Value[i] < 0 {
x.Value[i] = 0
}
}
Comment on lines +1334 to +1338
Copy link
Collaborator

@kolesnikovae kolesnikovae Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit more complicated: we already do this sanitisation outside this function, in https://github.com/grafana/pyroscope/blob/main/pkg/pprof/pprof.go#L390-L394

In ad-hoc, profiles travel a different path, and this is handled here actually:
https://github.com/grafana/pyroscope/blob/main/pkg/og/structs/flamebearer/convert/convert.go#L205

for i := range x.LocationId {
if x.LocationId[i] = t[x.LocationId[i]]; x.LocationId[i] == 0 {
return true
Expand Down
3 changes: 3 additions & 0 deletions pkg/pprof/pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ func TestNormalizeProfile(t *testing.T) {
},
Sample: []*profilev1.Sample{
{LocationId: []uint64{2, 3}, Value: []int64{0, 1}, Label: []*profilev1.Label{{Num: 10, Key: 1}, {Num: 11, Key: 1}}},
{LocationId: []uint64{3}, Value: []int64{-10, 2}, Label: []*profilev1.Label{{Num: 13, Key: 1}}},
// Those samples should be dropped.
{LocationId: []uint64{1, 2, 3}, Value: []int64{0, 0}, Label: []*profilev1.Label{{Num: 10, Key: 1}}},
{LocationId: []uint64{4}, Value: []int64{0, 0}, Label: []*profilev1.Label{{Num: 10, Key: 1}}},
{LocationId: []uint64{1, 2, 3}, Value: []int64{-1, -1}, Label: []*profilev1.Label{{Num: 10, Key: 1}}},
},
Mapping: []*profilev1.Mapping{{Id: 1, HasFunctions: true, MemoryStart: 100, MemoryLimit: 200, FileOffset: 200}},
Location: []*profilev1.Location{
Expand Down Expand Up @@ -76,6 +78,7 @@ func TestNormalizeProfile(t *testing.T) {
},
Sample: []*profilev1.Sample{
{LocationId: []uint64{1, 2}, Value: []int64{0, 1}, Label: []*profilev1.Label{}},
{LocationId: []uint64{2}, Value: []int64{0, 2}, Label: []*profilev1.Label{}},
},
Mapping: []*profilev1.Mapping{{
Id: 1,
Expand Down
Loading