Skip to content

Commit

Permalink
pyroscope.scrape: standarize profile names
Browse files Browse the repository at this point in the history
Backport of grafana/alloy#662
  • Loading branch information
simonswine committed May 13, 2024
1 parent 2d14260 commit 8ee1a5a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/component/pyroscope/scrape/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ type Target struct {
func NewTarget(lbls, discoveredLabels labels.Labels, params url.Values) *Target {
publicLabels := make(labels.Labels, 0, len(lbls))
for _, l := range lbls {
if !strings.HasPrefix(l.Name, model.ReservedLabelPrefix) {
publicLabels = append(publicLabels, l)
if strings.HasPrefix(l.Name, model.ReservedLabelPrefix) {
continue
}

// the fact that godeltaprof was used scraping should not be user visible
if l.Name == pprofGoDeltaProfMemory {
switch l.Value {
case pprofGoDeltaProfMemory:
l.Value = pprofMemory
case pprofGoDeltaProfBlock:
l.Value = pprofBlock
case pprofGoDeltaProfMutex:
l.Value = pprofMutex
}
}

publicLabels = append(publicLabels, l)
}
url := urlFromTarget(lbls, params)

Expand Down
47 changes: 47 additions & 0 deletions internal/component/pyroscope/scrape/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,50 @@ func Test_targetsFromGroup(t *testing.T) {
require.Equal(t, expected, active)
require.Empty(t, dropped)
}

// Test that the godeltaprof is not surfaced publicly
func Test_NewTarget_godeltaprof(t *testing.T) {
withGodeltaprof := NewTarget(
labels.FromMap(map[string]string{
model.AddressLabel: "localhost:9094",
serviceNameLabel: "docker-container",
model.MetricNameLabel: pprofGoDeltaProfMemory,
ProfilePath: "/debug/pprof/delta_heap",
model.SchemeLabel: "http",
"foo": "bar",
"instance": "localhost:9094",
}),
labels.FromMap(map[string]string{
model.AddressLabel: "localhost:9094",
"__meta_docker_container_name": "docker-container",
model.MetricNameLabel: pprofGoDeltaProfMemory,
ProfilePath: "/debug/pprof/delta_heap",
model.SchemeLabel: "http",
"foo": "bar",
}),
url.Values{},
)
withoutGodeltaprof := NewTarget(
labels.FromMap(map[string]string{
model.AddressLabel: "localhost:9094",
serviceNameLabel: "docker-container",
model.MetricNameLabel: pprofMemory,
ProfilePath: "/debug/pprof/heap",
model.SchemeLabel: "http",
"foo": "bar",
"instance": "localhost:9094",
}),
labels.FromMap(map[string]string{
model.AddressLabel: "localhost:9094",
"__meta_docker_container_name": "docker-container",
model.MetricNameLabel: pprofMemory,
ProfilePath: "/debug/pprof/heap",
model.SchemeLabel: "http",
"foo": "bar",
}),
url.Values{},
)

require.NotEqual(t, withGodeltaprof.allLabels, withoutGodeltaprof.allLabels)
require.Equal(t, withGodeltaprof.publicLabels, withoutGodeltaprof.publicLabels)
}

0 comments on commit 8ee1a5a

Please sign in to comment.