Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BuildAttributes helper to pprofile #12176

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dmathieu
Copy link
Member

@dmathieu dmathieu commented Jan 23, 2025

Description

Profiles attributes are stored in a single AttributeTable attribute, and then referenced in each substruct as AttributeIndices.

This means to read them as a pcommon.Map, a bit of pre-processing is required.
This adds an helper method so each component manipulating profiles doesn't have to reimplement it.

Benchmark:

goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/collector/pdata/pprofile
cpu: Apple M1 Max
BenchmarkBuildAttributes-10      4778193               242.9 ns/op           316 B/op          9 allocs/op
PASS
ok      go.opentelemetry.io/collector/pdata/pprofile    1.931s
PASS
ok      go.opentelemetry.io/collector/pdata/pprofile/pprofileotlp       0.375s

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 45.16129% with 17 lines in your changes missing coverage. Please review.

Project coverage is 91.69%. Comparing base (e8807bf) to head (e0a0548).

Files with missing lines Patch % Lines
pdata/pprofile/attributes.go 45.16% 17 Missing ⚠️

❌ Your patch check has failed because the patch coverage (45.16%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12176      +/-   ##
==========================================
- Coverage   91.75%   91.69%   -0.06%     
==========================================
  Files         464      465       +1     
  Lines       24763    24794      +31     
==========================================
+ Hits        22722    22736      +14     
- Misses       1656     1673      +17     
  Partials      385      385              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmathieu dmathieu marked this pull request as ready for review January 23, 2025 17:08
@dmathieu dmathieu requested review from mx-psi and a team as code owners January 23, 2025 17:08
pdata/pprofile/attributes.go Outdated Show resolved Hide resolved
@dmathieu dmathieu marked this pull request as draft January 23, 2025 17:26
@dmathieu dmathieu force-pushed the pprofile-build-attributes-helper branch from 4dc8a4a to e0a0548 Compare January 24, 2025 08:33
@dmathieu dmathieu marked this pull request as ready for review January 24, 2025 08:41
@dmathieu dmathieu requested a review from bogdandrutu January 24, 2025 08:41
Comment on lines +17 to +18
m := pcommon.NewMap()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m.EnsureCapacity(record.AttributeIndices().Len())

key := a.Key()
val := a.Value()

switch val.Type() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply replace whole switch statement with: val.CopyTo(m.PutEmpty(key))

Comment on lines +20 to +21
id := int(record.AttributeIndices().At(i))
a := profile.AttributeTable().At(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kv := profile.AttributeTable().At(int(record.AttributeIndices().At(i)))

@bogdandrutu bogdandrutu dismissed their stale review January 24, 2025 16:53

The blocking request part is resolved.


// BuildAttributes builds a [pcommon.Map] containing the attributes of a record.
// The record can by any struct that implements an `AttributeIndices` method.
func BuildAttributes(profile Profile, record attributable) pcommon.Map {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably use something like FromAttributeIndices?


// BuildAttributes builds a [pcommon.Map] containing the attributes of a record.
// The record can by any struct that implements an `AttributeIndices` method.
func BuildAttributes(profile Profile, record attributable) pcommon.Map {
Copy link
Member

@bogdandrutu bogdandrutu Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a func on Profile then? Or actually, you only need the AttributeIndices not the whole Profile correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants