Skip to content

Commit ece0a32

Browse files
authored
fix: don't compute delta on relabeled godeltaprof_memory->memory profiles (#3398) (#3399)
* fix: do not compute delta on relabeled godeltaprof_memory->memory profiles * add repro * fmt * fix test * fix test
1 parent 3fb6d31 commit ece0a32

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

pkg/distributor/distributor_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ func Test_SampleLabels(t *testing.T) {
733733
series: []*distributormodel.ProfileSeries{
734734
{
735735
Labels: []*typesv1.LabelPair{
736+
{Name: "__delta__", Value: "false"},
736737
{Name: "__name__", Value: "memory"},
737738
{Name: "__name_replaced__", Value: "godeltaprof_memory"},
738739
},

pkg/test/integration/helper.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (b *RequestBuilder) Render(metric string) *flamebearer.FlamebearerProfile {
305305
return fb
306306
}
307307

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

340+
func (b *RequestBuilder) PushPPROFRequestFromBytes(rawProfile []byte, name string) *connect.Request[pushv1.PushRequest] {
341+
req := connect.NewRequest(&pushv1.PushRequest{
342+
Series: []*pushv1.RawProfileSeries{{
343+
Labels: []*typesv1.LabelPair{
344+
{Name: "__name__", Value: name},
345+
{Name: "service_name", Value: b.AppName},
346+
},
347+
Samples: []*pushv1.RawSample{{RawProfile: rawProfile}},
348+
}},
349+
})
350+
return req
351+
}
352+
340353
func (b *RequestBuilder) QueryClient() querierv1connect.QuerierServiceClient {
341354
return querierv1connect.NewQuerierServiceClient(
342355
http.DefaultClient,

pkg/test/integration/ingest_pprof_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"fmt"
55
"os"
66
"testing"
7+
"time"
8+
9+
"github.com/grafana/pyroscope/pkg/pprof/testhelper"
710

811
"connectrpc.com/connect"
912
"github.com/stretchr/testify/assert"
@@ -318,6 +321,37 @@ func TestIngestPPROFFixPythonLinenumbers(t *testing.T) {
318321
assert.Equal(t, expected, actual)
319322
}
320323

324+
func TestGodeltaprofRelabelPush(t *testing.T) {
325+
const blockSize = 1024
326+
const metric = "godeltaprof_memory"
327+
328+
p := PyroscopeTest{}
329+
p.Start(t)
330+
defer p.Stop(t)
331+
332+
p1, _ := testhelper.NewProfileBuilder(time.Now().Add(-time.Second).UnixNano()).
333+
MemoryProfile().
334+
ForStacktraceString("my", "other").
335+
AddSamples(239, 239*blockSize, 1000, 1000*blockSize).
336+
Profile.MarshalVT()
337+
338+
p2, _ := testhelper.NewProfileBuilder(time.Now().UnixNano()).
339+
MemoryProfile().
340+
ForStacktraceString("my", "other").
341+
AddSamples(3, 3*blockSize, 1000, 1000*blockSize).
342+
Profile.MarshalVT()
343+
344+
rb := p.NewRequestBuilder(t)
345+
rb.Push(rb.PushPPROFRequestFromBytes(p1, metric), 200, "")
346+
rb.Push(rb.PushPPROFRequestFromBytes(p2, metric), 200, "")
347+
renderedProfile := rb.SelectMergeProfile("memory:alloc_objects:count:space:bytes", nil)
348+
actual := bench.StackCollapseProto(renderedProfile.Msg, 0, 1)
349+
expected := []string{
350+
"other;my 242",
351+
}
352+
assert.Equal(t, expected, actual)
353+
}
354+
321355
func TestPush(t *testing.T) {
322356
p := new(PyroscopeTest)
323357
p.Start(t)
@@ -330,7 +364,7 @@ func TestPush(t *testing.T) {
330364
t.Run(td.profile, func(t *testing.T) {
331365
rb := p.NewRequestBuilder(t)
332366

333-
req := rb.PushPPROFRequest(td.profile, td.metrics[0].name)
367+
req := rb.PushPPROFRequestFromFile(td.profile, td.metrics[0].name)
334368
rb.Push(req, td.expectStatusPush, td.expectedError)
335369

336370
if td.expectStatusPush == 200 {

pkg/validation/relabeling.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ var (
1616
TargetLabel: "__name_replaced__",
1717
Replacement: "$0",
1818
},
19+
{
20+
SourceLabels: []model.LabelName{"__name_replaced__"},
21+
Action: relabel.Replace,
22+
Regex: godeltaprof,
23+
TargetLabel: "__delta__",
24+
Replacement: "false",
25+
},
1926
{
2027
SourceLabels: []model.LabelName{"__name__"},
2128
Regex: godeltaprof,

pkg/validation/relabeling_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func Test_defaultRelabelRules(t *testing.T) {
122122
expected: labels.FromStrings(
123123
phlaremodel.LabelNameProfileName, "memory",
124124
"__name_replaced__", "godeltaprof_memory",
125+
"__delta__", "false",
125126
),
126127
kept: true,
127128
},

0 commit comments

Comments
 (0)