Skip to content

Commit 033fcc7

Browse files
korniltsevmarcsanmi
authored andcommitted
Revert "feat: add __unsymbolized__ label on ingest path (#4147)"
This reverts commit eb12a50.
1 parent 3dc9b1c commit 033fcc7

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
@@ -116,7 +116,7 @@ func (sh *shard) flushSegment(ctx context.Context, wg *sync.WaitGroup) {
116116
if s.debuginfo.movedHeads > 0 {
117117
_ = level.Debug(s.logger).Log("msg",
118118
"writing segment block done",
119-
"heads-count", len(s.datasets),
119+
"heads-count", len(s.heads),
120120
"heads-moved-count", s.debuginfo.movedHeads,
121121
"inflight-duration", s.debuginfo.waitInflight,
122122
"flush-heads-duration", s.debuginfo.flushHeadsDuration,
@@ -203,7 +203,7 @@ func (sw *segmentsWriter) newSegment(sh *shard, sk shardKey, sl log.Logger) *seg
203203
s := &segment{
204204
logger: log.With(sl, "segment-id", id.String()),
205205
ulid: id,
206-
datasets: make(map[datasetKey]*dataset),
206+
heads: make(map[datasetKey]dataset),
207207
sw: sw,
208208
sh: sh,
209209
shard: sk,
@@ -216,7 +216,7 @@ func (sw *segmentsWriter) newSegment(sh *shard, sk shardKey, sl log.Logger) *seg
216216
func (s *segment) flush(ctx context.Context) (err error) {
217217
span, ctx := opentracing.StartSpanFromContext(ctx, "segment.flush", opentracing.Tags{
218218
"block_id": s.ulid.String(),
219-
"datasets": len(s.datasets),
219+
"datasets": len(s.heads),
220220
"shard": s.shard,
221221
})
222222
defer span.Finish()
@@ -340,10 +340,6 @@ func concatSegmentHead(f *headFlush, w *writerOffset, s *metadata.StringTable) *
340340
lb.WithLabelSet(model.LabelNameServiceName, f.head.key.service, model.LabelNameProfileType, profileType)
341341
}
342342

343-
if f.flushed.HasUnsymbolizedProfiles {
344-
lb.WithLabelSet(model.LabelNameServiceName, f.head.key.service, metadata.LabelNameUnsymbolized, "true")
345-
}
346-
347343
// Other optional labels:
348344
// lb.WithLabelSet("label_name", "label_value", ...)
349345
ds.Labels = lb.Build()
@@ -352,8 +348,8 @@ func concatSegmentHead(f *headFlush, w *writerOffset, s *metadata.StringTable) *
352348
}
353349

354350
func (s *segment) flushHeads(ctx context.Context) flushStream {
355-
heads := maps.Values(s.datasets)
356-
slices.SortFunc(heads, func(a, b *dataset) int {
351+
heads := maps.Values(s.heads)
352+
slices.SortFunc(heads, func(a, b dataset) int {
357353
return a.key.compare(b.key)
358354
})
359355

@@ -368,15 +364,15 @@ func (s *segment) flushHeads(ctx context.Context) flushStream {
368364
defer close(f.done)
369365
flushed, err := s.flushHead(ctx, f.head)
370366
if err != nil {
371-
level.Error(s.logger).Log("msg", "failed to flush dataset", "err", err)
367+
level.Error(s.logger).Log("msg", "failed to flush head", "err", err)
372368
return
373369
}
374370
if flushed == nil {
375-
level.Debug(s.logger).Log("msg", "skipping nil dataset")
371+
level.Debug(s.logger).Log("msg", "skipping nil head")
376372
return
377373
}
378374
if flushed.Meta.NumSamples == 0 {
379-
level.Debug(s.logger).Log("msg", "skipping empty dataset")
375+
level.Debug(s.logger).Log("msg", "skipping empty head")
380376
return
381377
}
382378
f.flushed = flushed
@@ -407,24 +403,24 @@ func (s *flushStream) Next() bool {
407403
return false
408404
}
409405

410-
func (s *segment) flushHead(ctx context.Context, e *dataset) (*memdb.FlushedHead, error) {
406+
func (s *segment) flushHead(ctx context.Context, e dataset) (*memdb.FlushedHead, error) {
411407
th := time.Now()
412408
flushed, err := e.head.Flush(ctx)
413409
if err != nil {
414410
s.sw.metrics.flushServiceHeadDuration.WithLabelValues(s.sshard, e.key.tenant).Observe(time.Since(th).Seconds())
415411
s.sw.metrics.flushServiceHeadError.WithLabelValues(s.sshard, e.key.tenant).Inc()
416-
return nil, fmt.Errorf("failed to flush dataset : %w", err)
412+
return nil, fmt.Errorf("failed to flush head : %w", err)
417413
}
418414
s.sw.metrics.flushServiceHeadDuration.WithLabelValues(s.sshard, e.key.tenant).Observe(time.Since(th).Seconds())
419415
level.Debug(s.logger).Log(
420-
"msg", "flushed dataset",
416+
"msg", "flushed head",
421417
"tenant", e.key.tenant,
422418
"service", e.key.service,
423419
"profiles", flushed.Meta.NumProfiles,
424420
"profiletypes", fmt.Sprintf("%v", flushed.Meta.ProfileTypeNames),
425421
"mintime", flushed.Meta.MinTimeNanos,
426422
"maxtime", flushed.Meta.MaxTimeNanos,
427-
"dataset-flush-duration", time.Since(th).String(),
423+
"head-flush-duration", time.Since(th).String(),
428424
)
429425
return flushed, nil
430426
}
@@ -447,7 +443,7 @@ type dataset struct {
447443
}
448444

449445
type headFlush struct {
450-
head *dataset
446+
head dataset
451447
flushed *memdb.FlushedHead
452448
// protects head
453449
done chan struct{}
@@ -458,12 +454,10 @@ type segment struct {
458454
shard shardKey
459455
sshard string
460456
inFlightProfiles sync.WaitGroup
461-
462-
mu sync.RWMutex
463-
datasets map[datasetKey]*dataset
464-
465-
logger log.Logger
466-
sw *segmentsWriter
457+
heads map[datasetKey]dataset
458+
headsLock sync.RWMutex
459+
logger log.Logger
460+
sw *segmentsWriter
467461

468462
// TODO(kolesnikovae): Revisit.
469463
doneChan chan struct{}
@@ -507,12 +501,11 @@ func (s *segment) ingest(tenantID string, p *profilev1.Profile, id uuid.UUID, la
507501
tenant: tenantID,
508502
service: model.Labels(labels).Get(model.LabelNameServiceName),
509503
}
510-
ds := s.datasetForIngest(k)
511504
size := p.SizeVT()
512505
rules := s.sw.limits.IngestionRelabelingRules(tenantID)
513506
usage := s.sw.limits.DistributorUsageGroups(tenantID).GetUsageGroups(tenantID, labels)
514507
appender := &sampleAppender{
515-
dataset: ds,
508+
head: s.headForIngest(k),
516509
profile: p,
517510
id: id,
518511
annotations: annotations,
@@ -526,7 +519,7 @@ func (s *segment) ingest(tenantID string, p *profilev1.Profile, id uuid.UUID, la
526519

527520
type sampleAppender struct {
528521
id uuid.UUID
529-
dataset *dataset
522+
head *memdb.Head
530523
profile *profilev1.Profile
531524
exporter *pprofmodel.SampleExporter
532525
annotations []*typesv1.ProfileAnnotation
@@ -536,7 +529,7 @@ type sampleAppender struct {
536529
}
537530

538531
func (v *sampleAppender) VisitProfile(labels []*typesv1.LabelPair) {
539-
v.dataset.head.Ingest(v.profile, v.id, labels, v.annotations)
532+
v.head.Ingest(v.profile, v.id, labels, v.annotations)
540533
}
541534

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

551544
func (v *sampleAppender) Discarded(profiles, bytes int) {
552545
v.discardedProfiles += profiles
553546
v.discardedBytes += bytes
554547
}
555548

556-
func (s *segment) datasetForIngest(k datasetKey) *dataset {
557-
s.mu.RLock()
558-
ds, ok := s.datasets[k]
559-
s.mu.RUnlock()
549+
func (s *segment) headForIngest(k datasetKey) *memdb.Head {
550+
s.headsLock.RLock()
551+
h, ok := s.heads[k]
552+
s.headsLock.RUnlock()
560553
if ok {
561-
return ds
554+
return h.head
562555
}
563556

564-
s.mu.Lock()
565-
defer s.mu.Unlock()
566-
if ds, ok = s.datasets[k]; ok {
567-
return ds
557+
s.headsLock.Lock()
558+
defer s.headsLock.Unlock()
559+
h, ok = s.heads[k]
560+
if ok {
561+
return h.head
568562
}
569563

570-
h := memdb.NewHead(s.sw.headMetrics)
571-
ds = &dataset{
564+
nh := memdb.NewHead(s.sw.headMetrics)
565+
566+
s.heads[k] = dataset{
572567
key: k,
573-
head: h,
568+
head: nh,
574569
}
575570

576-
s.datasets[k] = ds
577-
return ds
571+
return nh
578572
}
579573

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

0 commit comments

Comments
 (0)