Skip to content

Commit de70cc4

Browse files
committed
Revert "feat: add __unsymbolized__ label on ingest path (#4147)"
This reverts commit eb12a50.
1 parent eb12a50 commit de70cc4

File tree

4 files changed

+40
-145
lines changed

4 files changed

+40
-145
lines changed

pkg/experiment/block/metadata/metadata_labels.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
const (
1919
LabelNameTenantDataset = "__tenant_dataset__"
2020
LabelValueDatasetTSDBIndex = "dataset_tsdb_index"
21-
LabelNameUnsymbolized = "__unsymbolized__"
2221
)
2322

2423
type LabelBuilder struct {

pkg/experiment/ingester/memdb/head.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import (
2121
)
2222

2323
type FlushedHead struct {
24-
Index []byte
25-
Profiles []byte
26-
Symbols []byte
27-
HasUnsymbolizedProfiles bool
28-
Meta struct {
24+
Index []byte
25+
Profiles []byte
26+
Symbols []byte
27+
Meta struct {
2928
ProfileTypeNames []string
3029
MinTimeNanos int64
3130
MaxTimeNanos int64
@@ -154,8 +153,6 @@ func (h *Head) flush(ctx context.Context) (*FlushedHead, error) {
154153
return res, nil
155154
}
156155

157-
res.HasUnsymbolizedProfiles = HasUnsymbolizedProfiles(h.symbols.Symbols())
158-
159156
symbolsBuffer := bytes.NewBuffer(nil)
160157
if err := symdb.WritePartition(h.symbols, symbolsBuffer); err != nil {
161158
return nil, err
@@ -176,15 +173,3 @@ func (h *Head) flush(ctx context.Context) (*FlushedHead, error) {
176173
}
177174
return res, nil
178175
}
179-
180-
// TODO: move into the symbolizer package when available
181-
func HasUnsymbolizedProfiles(symbols *symdb.Symbols) bool {
182-
locations := symbols.Locations
183-
mappings := symbols.Mappings
184-
for _, loc := range locations {
185-
if !mappings[loc.MappingId].HasFunctions {
186-
return true
187-
}
188-
}
189-
return false
190-
}

pkg/experiment/ingester/memdb/head_test.go

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/grafana/pyroscope/pkg/og/convert/pprof/bench"
2828
"github.com/grafana/pyroscope/pkg/phlaredb"
2929
testutil2 "github.com/grafana/pyroscope/pkg/phlaredb/block/testutil"
30-
"github.com/grafana/pyroscope/pkg/phlaredb/symdb"
3130
"github.com/grafana/pyroscope/pkg/pprof"
3231
"github.com/grafana/pyroscope/pkg/pprof/testhelper"
3332
)
@@ -673,88 +672,6 @@ func Test_HeadFlush_DuplicateLabels(t *testing.T) {
673672
&typesv1.LabelPair{Name: "pod", Value: "not-my-pod"},
674673
)
675674
}
676-
677-
// TODO: move into the symbolizer package when available
678-
func TestUnsymbolized(t *testing.T) {
679-
testCases := []struct {
680-
name string
681-
profile *profilev1.Profile
682-
expectUnsymbolized bool
683-
}{
684-
{
685-
name: "fully symbolized profile",
686-
profile: &profilev1.Profile{
687-
StringTable: []string{"", "a"},
688-
Function: []*profilev1.Function{
689-
{Id: 4, Name: 1},
690-
},
691-
Mapping: []*profilev1.Mapping{
692-
{Id: 239, HasFunctions: true},
693-
},
694-
Location: []*profilev1.Location{
695-
{Id: 5, MappingId: 239, Line: []*profilev1.Line{{FunctionId: 4, Line: 1}}},
696-
},
697-
Sample: []*profilev1.Sample{
698-
{LocationId: []uint64{5}, Value: []int64{1}},
699-
},
700-
},
701-
expectUnsymbolized: false,
702-
},
703-
{
704-
name: "mapping without functions",
705-
profile: &profilev1.Profile{
706-
StringTable: []string{"", "a"},
707-
Function: []*profilev1.Function{
708-
{Id: 4, Name: 1},
709-
},
710-
Mapping: []*profilev1.Mapping{
711-
{Id: 239, HasFunctions: false},
712-
},
713-
Location: []*profilev1.Location{
714-
{Id: 5, MappingId: 239, Line: []*profilev1.Line{{FunctionId: 4, Line: 1}}},
715-
},
716-
Sample: []*profilev1.Sample{
717-
{LocationId: []uint64{5}, Value: []int64{1}},
718-
},
719-
},
720-
expectUnsymbolized: true,
721-
},
722-
{
723-
name: "multiple locations with mixed symbolization",
724-
profile: &profilev1.Profile{
725-
StringTable: []string{"", "a", "b"},
726-
Function: []*profilev1.Function{
727-
{Id: 4, Name: 1},
728-
{Id: 5, Name: 2},
729-
},
730-
Mapping: []*profilev1.Mapping{
731-
{Id: 239, HasFunctions: true},
732-
{Id: 240, HasFunctions: false},
733-
},
734-
Location: []*profilev1.Location{
735-
{Id: 5, MappingId: 239, Line: []*profilev1.Line{{FunctionId: 4, Line: 1}}},
736-
{Id: 6, MappingId: 240, Line: nil},
737-
},
738-
Sample: []*profilev1.Sample{
739-
{LocationId: []uint64{5, 6}, Value: []int64{1}},
740-
},
741-
},
742-
expectUnsymbolized: true,
743-
},
744-
}
745-
746-
for _, tc := range testCases {
747-
t.Run(tc.name, func(t *testing.T) {
748-
symbols := symdb.NewPartitionWriter(0, &symdb.Config{
749-
Version: symdb.FormatV3,
750-
})
751-
symbols.WriteProfileSymbols(tc.profile)
752-
unsymbolized := HasUnsymbolizedProfiles(symbols.Symbols())
753-
assert.Equal(t, tc.expectUnsymbolized, unsymbolized)
754-
})
755-
}
756-
}
757-
758675
func BenchmarkHeadIngestProfiles(t *testing.B) {
759676
var (
760677
profilePaths = []string{

pkg/experiment/ingester/segment.go

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (sh *shard) flushSegment(ctx context.Context, lastTick bool) {
108108
if s.debuginfo.movedHeads > 0 {
109109
_ = level.Debug(s.logger).Log("msg",
110110
"writing segment block done",
111-
"heads-count", len(s.datasets),
111+
"heads-count", len(s.heads),
112112
"heads-moved-count", s.debuginfo.movedHeads,
113113
"inflight-duration", s.debuginfo.waitInflight,
114114
"flush-heads-duration", s.debuginfo.flushHeadsDuration,
@@ -200,7 +200,7 @@ func (sw *segmentsWriter) newSegment(sh *shard, sk shardKey, sl log.Logger) *seg
200200
s := &segment{
201201
logger: log.With(sl, "segment-id", id.String()),
202202
ulid: id,
203-
datasets: make(map[datasetKey]*dataset),
203+
heads: make(map[datasetKey]dataset),
204204
sw: sw,
205205
sh: sh,
206206
shard: sk,
@@ -213,7 +213,7 @@ func (sw *segmentsWriter) newSegment(sh *shard, sk shardKey, sl log.Logger) *seg
213213
func (s *segment) flush(ctx context.Context) (err error) {
214214
span, ctx := opentracing.StartSpanFromContext(ctx, "segment.flush", opentracing.Tags{
215215
"block_id": s.ulid.String(),
216-
"datasets": len(s.datasets),
216+
"datasets": len(s.heads),
217217
"shard": s.shard,
218218
})
219219
defer span.Finish()
@@ -337,10 +337,6 @@ func concatSegmentHead(f *headFlush, w *writerOffset, s *metadata.StringTable) *
337337
lb.WithLabelSet(model.LabelNameServiceName, f.head.key.service, model.LabelNameProfileType, profileType)
338338
}
339339

340-
if f.flushed.HasUnsymbolizedProfiles {
341-
lb.WithLabelSet(model.LabelNameServiceName, f.head.key.service, metadata.LabelNameUnsymbolized, "true")
342-
}
343-
344340
// Other optional labels:
345341
// lb.WithLabelSet("label_name", "label_value", ...)
346342
ds.Labels = lb.Build()
@@ -349,8 +345,8 @@ func concatSegmentHead(f *headFlush, w *writerOffset, s *metadata.StringTable) *
349345
}
350346

351347
func (s *segment) flushHeads(ctx context.Context) flushStream {
352-
heads := maps.Values(s.datasets)
353-
slices.SortFunc(heads, func(a, b *dataset) int {
348+
heads := maps.Values(s.heads)
349+
slices.SortFunc(heads, func(a, b dataset) int {
354350
return a.key.compare(b.key)
355351
})
356352

@@ -365,15 +361,15 @@ func (s *segment) flushHeads(ctx context.Context) flushStream {
365361
defer close(f.done)
366362
flushed, err := s.flushHead(ctx, f.head)
367363
if err != nil {
368-
level.Error(s.logger).Log("msg", "failed to flush dataset", "err", err)
364+
level.Error(s.logger).Log("msg", "failed to flush head", "err", err)
369365
return
370366
}
371367
if flushed == nil {
372-
level.Debug(s.logger).Log("msg", "skipping nil dataset")
368+
level.Debug(s.logger).Log("msg", "skipping nil head")
373369
return
374370
}
375371
if flushed.Meta.NumSamples == 0 {
376-
level.Debug(s.logger).Log("msg", "skipping empty dataset")
372+
level.Debug(s.logger).Log("msg", "skipping empty head")
377373
return
378374
}
379375
f.flushed = flushed
@@ -404,24 +400,24 @@ func (s *flushStream) Next() bool {
404400
return false
405401
}
406402

407-
func (s *segment) flushHead(ctx context.Context, e *dataset) (*memdb.FlushedHead, error) {
403+
func (s *segment) flushHead(ctx context.Context, e dataset) (*memdb.FlushedHead, error) {
408404
th := time.Now()
409405
flushed, err := e.head.Flush(ctx)
410406
if err != nil {
411407
s.sw.metrics.flushServiceHeadDuration.WithLabelValues(s.sshard, e.key.tenant).Observe(time.Since(th).Seconds())
412408
s.sw.metrics.flushServiceHeadError.WithLabelValues(s.sshard, e.key.tenant).Inc()
413-
return nil, fmt.Errorf("failed to flush dataset : %w", err)
409+
return nil, fmt.Errorf("failed to flush head : %w", err)
414410
}
415411
s.sw.metrics.flushServiceHeadDuration.WithLabelValues(s.sshard, e.key.tenant).Observe(time.Since(th).Seconds())
416412
level.Debug(s.logger).Log(
417-
"msg", "flushed dataset",
413+
"msg", "flushed head",
418414
"tenant", e.key.tenant,
419415
"service", e.key.service,
420416
"profiles", flushed.Meta.NumProfiles,
421417
"profiletypes", fmt.Sprintf("%v", flushed.Meta.ProfileTypeNames),
422418
"mintime", flushed.Meta.MinTimeNanos,
423419
"maxtime", flushed.Meta.MaxTimeNanos,
424-
"dataset-flush-duration", time.Since(th).String(),
420+
"head-flush-duration", time.Since(th).String(),
425421
)
426422
return flushed, nil
427423
}
@@ -444,7 +440,7 @@ type dataset struct {
444440
}
445441

446442
type headFlush struct {
447-
head *dataset
443+
head dataset
448444
flushed *memdb.FlushedHead
449445
// protects head
450446
done chan struct{}
@@ -455,12 +451,10 @@ type segment struct {
455451
shard shardKey
456452
sshard string
457453
inFlightProfiles sync.WaitGroup
458-
459-
mu sync.RWMutex
460-
datasets map[datasetKey]*dataset
461-
462-
logger log.Logger
463-
sw *segmentsWriter
454+
heads map[datasetKey]dataset
455+
headsLock sync.RWMutex
456+
logger log.Logger
457+
sw *segmentsWriter
464458

465459
// TODO(kolesnikovae): Revisit.
466460
doneChan chan struct{}
@@ -504,12 +498,11 @@ func (s *segment) ingest(tenantID string, p *profilev1.Profile, id uuid.UUID, la
504498
tenant: tenantID,
505499
service: model.Labels(labels).Get(model.LabelNameServiceName),
506500
}
507-
ds := s.datasetForIngest(k)
508501
size := p.SizeVT()
509502
rules := s.sw.limits.IngestionRelabelingRules(tenantID)
510503
usage := s.sw.limits.DistributorUsageGroups(tenantID).GetUsageGroups(tenantID, labels)
511504
appender := &sampleAppender{
512-
dataset: ds,
505+
head: s.headForIngest(k),
513506
profile: p,
514507
id: id,
515508
annotations: annotations,
@@ -523,7 +516,7 @@ func (s *segment) ingest(tenantID string, p *profilev1.Profile, id uuid.UUID, la
523516

524517
type sampleAppender struct {
525518
id uuid.UUID
526-
dataset *dataset
519+
head *memdb.Head
527520
profile *profilev1.Profile
528521
exporter *pprofmodel.SampleExporter
529522
annotations []*typesv1.ProfileAnnotation
@@ -533,7 +526,7 @@ type sampleAppender struct {
533526
}
534527

535528
func (v *sampleAppender) VisitProfile(labels []*typesv1.LabelPair) {
536-
v.dataset.head.Ingest(v.profile, v.id, labels, v.annotations)
529+
v.head.Ingest(v.profile, v.id, labels, v.annotations)
537530
}
538531

539532
func (v *sampleAppender) VisitSampleSeries(labels []*typesv1.LabelPair, samples []*profilev1.Sample) {
@@ -542,36 +535,37 @@ func (v *sampleAppender) VisitSampleSeries(labels []*typesv1.LabelPair, samples
542535
}
543536
var n profilev1.Profile
544537
v.exporter.ExportSamples(&n, samples)
545-
v.dataset.head.Ingest(v.profile, v.id, labels, v.annotations)
538+
v.head.Ingest(&n, v.id, labels, v.annotations)
546539
}
547540

548541
func (v *sampleAppender) Discarded(profiles, bytes int) {
549542
v.discardedProfiles += profiles
550543
v.discardedBytes += bytes
551544
}
552545

553-
func (s *segment) datasetForIngest(k datasetKey) *dataset {
554-
s.mu.RLock()
555-
ds, ok := s.datasets[k]
556-
s.mu.RUnlock()
546+
func (s *segment) headForIngest(k datasetKey) *memdb.Head {
547+
s.headsLock.RLock()
548+
h, ok := s.heads[k]
549+
s.headsLock.RUnlock()
557550
if ok {
558-
return ds
551+
return h.head
559552
}
560553

561-
s.mu.Lock()
562-
defer s.mu.Unlock()
563-
if ds, ok = s.datasets[k]; ok {
564-
return ds
554+
s.headsLock.Lock()
555+
defer s.headsLock.Unlock()
556+
h, ok = s.heads[k]
557+
if ok {
558+
return h.head
565559
}
566560

567-
h := memdb.NewHead(s.sw.headMetrics)
568-
ds = &dataset{
561+
nh := memdb.NewHead(s.sw.headMetrics)
562+
563+
s.heads[k] = dataset{
569564
key: k,
570-
head: h,
565+
head: nh,
571566
}
572567

573-
s.datasets[k] = ds
574-
return ds
568+
return nh
575569
}
576570

577571
func (sw *segmentsWriter) uploadBlock(ctx context.Context, blockData []byte, meta *metastorev1.BlockMeta, s *segment) error {

0 commit comments

Comments
 (0)