Skip to content

Commit

Permalink
fix(otel): do not use mappings for otel profile partitioning
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed Dec 19, 2024
1 parent 0e34df1 commit 2b47b7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
12 changes: 10 additions & 2 deletions pkg/ingester/otlp/ingest_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"net/http"
"strings"

model2 "github.com/prometheus/common/model"

"github.com/grafana/pyroscope/pkg/model"

"connectrpc.com/connect"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -159,13 +163,17 @@ func getServiceNameFromAttributes(attrs []v1.KeyValue) string {
func getDefaultLabels() []*typesv1.LabelPair {
return []*typesv1.LabelPair{
{
Name: "__name__",
Name: model2.MetricNameLabel,
Value: "process_cpu",
},
{
Name: "__delta__",
Name: model.LabelNameDelta,
Value: "false",
},
{
Name: model.LabelNameOTEL,
Value: "true",
},
{
Name: "pyroscope_spy",
Value: "unknown",
Expand Down
1 change: 1 addition & 0 deletions pkg/model/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
LabelNameProfileType = "__profile_type__"
LabelNameServiceNamePrivate = "__service_name__"
LabelNameDelta = "__delta__"
LabelNameOTEL = "__otel__"
LabelNameProfileName = pmodel.MetricNameLabel
LabelNamePeriodType = "__period_type__"
LabelNamePeriodUnit = "__period_unit__"
Expand Down
12 changes: 7 additions & 5 deletions pkg/model/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ func NewSpanSelector(spans []string) (SpanSelector, error) {
return m, nil
}

func StacktracePartitionFromProfile(lbls []Labels, p *profilev1.Profile) uint64 {
return xxhash.Sum64String(stacktracePartitionKeyFromProfile(lbls, p))
func StacktracePartitionFromProfile(lbls []Labels, p *profilev1.Profile, otel bool) uint64 {
return xxhash.Sum64String(stacktracePartitionKeyFromProfile(lbls, p, otel))
}

func stacktracePartitionKeyFromProfile(lbls []Labels, p *profilev1.Profile) string {
// take the first mapping (which is the main binary's file basename)
if len(p.Mapping) > 0 {
func stacktracePartitionKeyFromProfile(lbls []Labels, p *profilev1.Profile, otel bool) string {
// Take the first mapping (which is the main binary's file basename)
// OTEL (at least from ebpf profiler at the time of writing) mappings are unreliable and ordered unpredictably and
// have no VA addresses (only relative to the shared object base)
if len(p.Mapping) > 0 && !otel {
if filenameID := p.Mapping[0].Filename; filenameID > 0 {
if filename := extractMappingFilename(p.StringTable[filenameID]); filename != "" {
return filename
Expand Down
4 changes: 3 additions & 1 deletion pkg/phlaredb/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func (h *Head) Ingest(ctx context.Context, p *profilev1.Profile, id uuid.UUID, e

delta := phlaremodel.Labels(externalLabels).Get(phlaremodel.LabelNameDelta) != "false"
externalLabels = phlaremodel.Labels(externalLabels).Delete(phlaremodel.LabelNameDelta)
otel := phlaremodel.Labels(externalLabels).Get(phlaremodel.LabelNameOTEL) == "true"
externalLabels = phlaremodel.Labels(externalLabels).Delete(phlaremodel.LabelNameOTEL)

enforceLabelOrder := phlaremodel.Labels(externalLabels).Get(phlaremodel.LabelNameOrder) == phlaremodel.LabelOrderEnforced
externalLabels = phlaremodel.Labels(externalLabels).Delete(phlaremodel.LabelNameOrder)
Expand All @@ -207,7 +209,7 @@ func (h *Head) Ingest(ctx context.Context, p *profilev1.Profile, id uuid.UUID, e
}

// determine the stacktraces partition ID
partition := phlaremodel.StacktracePartitionFromProfile(lbls, p)
partition := phlaremodel.StacktracePartitionFromProfile(lbls, p, otel)

metricName := phlaremodel.Labels(externalLabels).Get(model.MetricNameLabel)

Expand Down

0 comments on commit 2b47b7f

Please sign in to comment.