Skip to content

Commit

Permalink
added sanitization of samples with negative value
Browse files Browse the repository at this point in the history
  • Loading branch information
Pickausernaame committed Oct 14, 2024
1 parent 88ac084 commit 243f3fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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
}
}
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

0 comments on commit 243f3fd

Please sign in to comment.