From 309ecdb58074c3f9b3b90bf71aea91147f838e81 Mon Sep 17 00:00:00 2001 From: hainenber Date: Tue, 16 Apr 2024 21:53:22 +0700 Subject: [PATCH] feat(pyroscope/scrape): add support for configuring CPU profile's duration scraped by `pyroscope.scrape` Signed-off-by: hainenber --- .../component/pyroscope/scrape/target_test.go | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/internal/component/pyroscope/scrape/target_test.go b/internal/component/pyroscope/scrape/target_test.go index d7793a6156..6f630bdbb4 100644 --- a/internal/component/pyroscope/scrape/target_test.go +++ b/internal/component/pyroscope/scrape/target_test.go @@ -346,3 +346,65 @@ func Test_NewTarget_godeltaprof(t *testing.T) { require.NotEqual(t, withGodeltaprof.allLabels, withoutGodeltaprof.allLabels) require.Equal(t, withGodeltaprof.publicLabels, withoutGodeltaprof.publicLabels) } + +func Test_targetsFromGroup_withSpecifiedProfilingDuration(t *testing.T) { + args := NewDefaultArguments() + args.ProfilingConfig.Block.Enabled = false + args.ProfilingConfig.Goroutine.Enabled = false + args.ProfilingConfig.Mutex.Enabled = false + args.ProfilingDuration = 20 * time.Second + + active, dropped, err := targetsFromGroup(&targetgroup.Group{ + Targets: []model.LabelSet{ + {model.AddressLabel: "localhost:9090"}, + }, + Labels: model.LabelSet{ + "foo": "bar", + }, + }, args, args.ProfilingConfig.AllTargets()) + expected := []*Target{ + // unspecified + NewTarget( + labels.FromMap(map[string]string{ + model.AddressLabel: "localhost:9090", + serviceNameLabel: "unspecified", + model.MetricNameLabel: pprofMemory, + ProfilePath: "/debug/pprof/allocs", + model.SchemeLabel: "http", + "foo": "bar", + "instance": "localhost:9090", + }), + labels.FromMap(map[string]string{ + model.AddressLabel: "localhost:9090", + model.MetricNameLabel: pprofMemory, + ProfilePath: "/debug/pprof/allocs", + model.SchemeLabel: "http", + "foo": "bar", + }), + url.Values{}), + NewTarget( + labels.FromMap(map[string]string{ + model.AddressLabel: "localhost:9090", + serviceNameLabel: "unspecified", + model.MetricNameLabel: pprofProcessCPU, + ProfilePath: "/debug/pprof/profile", + model.SchemeLabel: "http", + "foo": "bar", + "instance": "localhost:9090", + }), + labels.FromMap(map[string]string{ + model.AddressLabel: "localhost:9090", + model.MetricNameLabel: pprofProcessCPU, + ProfilePath: "/debug/pprof/profile", + model.SchemeLabel: "http", + "foo": "bar", + }), + url.Values{"seconds": []string{"20"}}), + } + + require.NoError(t, err) + sort.Sort(Targets(active)) + sort.Sort(Targets(expected)) + require.Equal(t, expected, active) + require.Empty(t, dropped) +}