Skip to content

Commit 3bc7ea3

Browse files
committed
feat: symbolize only otel-related profiles
1 parent 5e2b000 commit 3bc7ea3

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

pkg/experiment/ingester/segment.go

-15
Original file line numberDiff line numberDiff line change
@@ -520,21 +520,6 @@ func (s *segment) ingest(tenantID string, p *profilev1.Profile, id uuid.UUID, la
520520
// CountReceivedBytes is tracked in distributors.
521521
}
522522

523-
func hasSymbols(p *profilev1.Profile) bool {
524-
if p == nil || len(p.Function) == 0 || len(p.Location) == 0 {
525-
return false
526-
}
527-
528-
for _, loc := range p.Location {
529-
if len(loc.Line) == 0 {
530-
// If any location lacks symbols, the profile needs symbolization
531-
return false
532-
}
533-
}
534-
535-
return true
536-
}
537-
538523
// getFunctionById returns a function by its ID
539524
func getFunctionById(p *profilev1.Profile, id uint64) (*profilev1.Function, bool) {
540525
for _, fn := range p.Function {

pkg/frontend/read_path/query_frontend/query_frontend.go

+36-17
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,28 @@ func (q *QueryFrontend) Query(
142142
continue
143143
}
144144

145-
if err := q.symbolizer.SymbolizePprof(ctx, &prof); err != nil {
146-
level.Error(q.logger).Log("msg", "symbolize pprof", "err", err)
147-
}
148-
149-
// Convert back to tree if originally a tree
150-
if i < len(req.Query) && req.Query[i].QueryType == queryv1.QueryType_QUERY_TREE {
151-
if len(prof.SampleType) > 1 {
152-
return nil, fmt.Errorf("multiple sample types not supported")
145+
// TODO: check if whether it comes from OTEL!
146+
isOTEL := isProfileFromOTEL(&prof)
147+
if isOTEL {
148+
if err := q.symbolizer.SymbolizePprof(ctx, &prof); err != nil {
149+
level.Error(q.logger).Log("msg", "symbolize pprof", "err", err)
153150
}
154-
treeBytes := model.TreeFromBackendProfile(&prof, req.Query[i].Tree.MaxNodes)
155-
// Store the tree result
156-
r.Tree = &queryv1.TreeReport{Tree: treeBytes}
157-
r.ReportType = queryv1.ReportType_REPORT_TREE
158-
r.Pprof = nil
159-
} else {
160-
symbolizedBytes, err := pprof.Marshal(&prof, true)
161-
if err == nil {
162-
r.Pprof.Pprof = symbolizedBytes
151+
152+
// Convert back to tree if originally a tree
153+
if i < len(req.Query) && req.Query[i].QueryType == queryv1.QueryType_QUERY_TREE {
154+
if len(prof.SampleType) > 1 {
155+
return nil, fmt.Errorf("multiple sample types not supported")
156+
}
157+
treeBytes := model.TreeFromBackendProfile(&prof, req.Query[i].Tree.MaxNodes)
158+
// Store the tree result
159+
r.Tree = &queryv1.TreeReport{Tree: treeBytes}
160+
r.ReportType = queryv1.ReportType_REPORT_TREE
161+
r.Pprof = nil
162+
} else {
163+
symbolizedBytes, err := pprof.Marshal(&prof, true)
164+
if err == nil {
165+
r.Pprof.Pprof = symbolizedBytes
166+
}
163167
}
164168
}
165169
}
@@ -238,3 +242,18 @@ func (q *QueryFrontend) hasNativeProfiles(block *metastorev1.BlockMeta) bool {
238242

239243
return hasNativeProfiles
240244
}
245+
246+
func isProfileFromOTEL(prof *profilev1.Profile) bool {
247+
// Check sample labels
248+
for _, sample := range prof.Sample {
249+
for _, label := range sample.Label {
250+
// Get the key and value from string table
251+
keyStr := prof.StringTable[label.Key]
252+
valStr := prof.StringTable[label.Str]
253+
if keyStr == phlaremodel.LabelNameOTEL && valStr == "true" {
254+
return true
255+
}
256+
}
257+
}
258+
return false
259+
}

pkg/frontend/read_path/query_frontend/query_frontend_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_QueryFrontend_QueryMetadata(t *testing.T) {
2424
request: &metastorev1.QueryMetadataRequest{
2525
TenantId: []string{"org"},
2626
Query: `{service_name="service-a"}`,
27-
Labels: []string{"__needs_symbolization__"},
27+
Labels: []string{"__has_native_profiles__"},
2828
},
2929
response: &metastorev1.QueryMetadataResponse{
3030
Blocks: []*metastorev1.BlockMeta{{Id: "block_id_a"}},
@@ -35,7 +35,7 @@ func Test_QueryFrontend_QueryMetadata(t *testing.T) {
3535
request: &metastorev1.QueryMetadataRequest{
3636
TenantId: []string{"org"},
3737
Query: `{__tenant_dataset__="dataset_tsdb_index"}`,
38-
Labels: []string{"__needs_symbolization__", "__tenant_dataset__"},
38+
Labels: []string{"__has_native_profiles__", "__tenant_dataset__"},
3939
},
4040
response: &metastorev1.QueryMetadataResponse{
4141
Blocks: []*metastorev1.BlockMeta{{Id: "block_id_a"}},
@@ -46,7 +46,7 @@ func Test_QueryFrontend_QueryMetadata(t *testing.T) {
4646
request: &metastorev1.QueryMetadataRequest{
4747
TenantId: []string{"org"},
4848
Query: `{__tenant_dataset__="dataset_tsdb_index"}`,
49-
Labels: []string{"__needs_symbolization__", "__tenant_dataset__"},
49+
Labels: []string{"__has_native_profiles__", "__tenant_dataset__"},
5050
},
5151
response: &metastorev1.QueryMetadataResponse{
5252
Blocks: []*metastorev1.BlockMeta{{Id: "block_id_c"}},
@@ -57,7 +57,7 @@ func Test_QueryFrontend_QueryMetadata(t *testing.T) {
5757
request: &metastorev1.QueryMetadataRequest{
5858
TenantId: []string{"org"},
5959
Query: `{__tenant_dataset__="dataset_tsdb_index"}`,
60-
Labels: []string{"__needs_symbolization__", "__tenant_dataset__"},
60+
Labels: []string{"__has_native_profiles__", "__tenant_dataset__"},
6161
},
6262
response: &metastorev1.QueryMetadataResponse{
6363
Blocks: []*metastorev1.BlockMeta{{Id: "block_id_b"}},
@@ -68,7 +68,7 @@ func Test_QueryFrontend_QueryMetadata(t *testing.T) {
6868
request: &metastorev1.QueryMetadataRequest{
6969
TenantId: []string{"org"},
7070
Query: `{__tenant_dataset__="dataset_tsdb_index"}`,
71-
Labels: []string{"__needs_symbolization__", "__tenant_dataset__"},
71+
Labels: []string{"__has_native_profiles__", "__tenant_dataset__"},
7272
},
7373
response: &metastorev1.QueryMetadataResponse{
7474
Blocks: []*metastorev1.BlockMeta{{Id: "block_id_d"}},

0 commit comments

Comments
 (0)