Skip to content

Commit

Permalink
fix: don't compute delta on relabeled godeltaprof_memory->memory prof…
Browse files Browse the repository at this point in the history
…iles (#3398) (#3399)

* fix: do not compute delta on relabeled godeltaprof_memory->memory profiles

* add repro

* fmt

* fix test

* fix test
  • Loading branch information
korniltsev authored Jul 3, 2024
1 parent 3fb6d31 commit ece0a32
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ func Test_SampleLabels(t *testing.T) {
series: []*distributormodel.ProfileSeries{
{
Labels: []*typesv1.LabelPair{
{Name: "__delta__", Value: "false"},
{Name: "__name__", Value: "memory"},
{Name: "__name_replaced__", Value: "godeltaprof_memory"},
},
Expand Down
15 changes: 14 additions & 1 deletion pkg/test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (b *RequestBuilder) Render(metric string) *flamebearer.FlamebearerProfile {
return fb
}

func (b *RequestBuilder) PushPPROFRequest(file string, metric string) *connect.Request[pushv1.PushRequest] {
func (b *RequestBuilder) PushPPROFRequestFromFile(file string, metric string) *connect.Request[pushv1.PushRequest] {
updateTimestamp := func(rawProfile []byte) []byte {
expectedProfile, err := pprof.RawFromBytes(rawProfile)
require.NoError(b.t, err)
Expand Down Expand Up @@ -337,6 +337,19 @@ func (b *RequestBuilder) PushPPROFRequest(file string, metric string) *connect.R
return req
}

func (b *RequestBuilder) PushPPROFRequestFromBytes(rawProfile []byte, name string) *connect.Request[pushv1.PushRequest] {
req := connect.NewRequest(&pushv1.PushRequest{
Series: []*pushv1.RawProfileSeries{{
Labels: []*typesv1.LabelPair{
{Name: "__name__", Value: name},
{Name: "service_name", Value: b.AppName},
},
Samples: []*pushv1.RawSample{{RawProfile: rawProfile}},
}},
})
return req
}

func (b *RequestBuilder) QueryClient() querierv1connect.QuerierServiceClient {
return querierv1connect.NewQuerierServiceClient(
http.DefaultClient,
Expand Down
36 changes: 35 additions & 1 deletion pkg/test/integration/ingest_pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/grafana/pyroscope/pkg/pprof/testhelper"

"connectrpc.com/connect"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -318,6 +321,37 @@ func TestIngestPPROFFixPythonLinenumbers(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestGodeltaprofRelabelPush(t *testing.T) {
const blockSize = 1024
const metric = "godeltaprof_memory"

p := PyroscopeTest{}
p.Start(t)
defer p.Stop(t)

p1, _ := testhelper.NewProfileBuilder(time.Now().Add(-time.Second).UnixNano()).
MemoryProfile().
ForStacktraceString("my", "other").
AddSamples(239, 239*blockSize, 1000, 1000*blockSize).
Profile.MarshalVT()

p2, _ := testhelper.NewProfileBuilder(time.Now().UnixNano()).
MemoryProfile().
ForStacktraceString("my", "other").
AddSamples(3, 3*blockSize, 1000, 1000*blockSize).
Profile.MarshalVT()

rb := p.NewRequestBuilder(t)
rb.Push(rb.PushPPROFRequestFromBytes(p1, metric), 200, "")
rb.Push(rb.PushPPROFRequestFromBytes(p2, metric), 200, "")
renderedProfile := rb.SelectMergeProfile("memory:alloc_objects:count:space:bytes", nil)
actual := bench.StackCollapseProto(renderedProfile.Msg, 0, 1)
expected := []string{
"other;my 242",
}
assert.Equal(t, expected, actual)
}

func TestPush(t *testing.T) {
p := new(PyroscopeTest)
p.Start(t)
Expand All @@ -330,7 +364,7 @@ func TestPush(t *testing.T) {
t.Run(td.profile, func(t *testing.T) {
rb := p.NewRequestBuilder(t)

req := rb.PushPPROFRequest(td.profile, td.metrics[0].name)
req := rb.PushPPROFRequestFromFile(td.profile, td.metrics[0].name)
rb.Push(req, td.expectStatusPush, td.expectedError)

if td.expectStatusPush == 200 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/validation/relabeling.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ var (
TargetLabel: "__name_replaced__",
Replacement: "$0",
},
{
SourceLabels: []model.LabelName{"__name_replaced__"},
Action: relabel.Replace,
Regex: godeltaprof,
TargetLabel: "__delta__",
Replacement: "false",
},
{
SourceLabels: []model.LabelName{"__name__"},
Regex: godeltaprof,
Expand Down
1 change: 1 addition & 0 deletions pkg/validation/relabeling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func Test_defaultRelabelRules(t *testing.T) {
expected: labels.FromStrings(
phlaremodel.LabelNameProfileName, "memory",
"__name_replaced__", "godeltaprof_memory",
"__delta__", "false",
),
kept: true,
},
Expand Down

0 comments on commit ece0a32

Please sign in to comment.