Skip to content

Introduce pprofile.PutAttribute helper #12798

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

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

Conversation

rockdaboot
Copy link
Contributor

@rockdaboot rockdaboot commented Apr 3, 2025

Description

This introduces the pprofile.PutAttribute() helper method so profile extensions can modify attributes.

It replaces the yet unused pprofile.AddAttribute() function, as Add doesn't resonate well with the pcommon.Map Put* functions.

Additionally, the PutAttributes() helper takes into account the map k/v nature of attributes, while AddAttributes() didn't do this.

Testing

goos: linux
goarch: amd64
pkg: go.opentelemetry.io/collector/pdata/pprofile
cpu: 12th Gen Intel(R) Core(TM) i7-12800H
                                                          │   old.txt   │      new.txt       │
                                                          │   sec/op    │   sec/op     vs base   │
AddAttribute/with_a_new_string_attribute-20                 27.66n ± 3%
AddAttribute/with_an_existing_attribute-20                  27.18n ± 4%
AddAttribute/with_a_duplicate_attribute-20                  27.18n ± 2%
AddAttribute/with_a_hundred_attributes_to_loop_through-20   103.0n ± 4%
PutAttribute/with_a_new_string_attribute-20                               27.71n ± 2%
PutAttribute/with_an_existing_attribute-20                                28.14n ± 1%
PutAttribute/with_a_duplicate_attribute-20                                28.14n ± 2%
PutAttribute/with_a_hundred_attributes_to_loop_through-20                 28.15n ± 2%
geomean                                                     38.08n        28.04n       ? ¹ ²
¹ benchmark set differs from baseline; geomeans may not be comparable
² ratios must be >0 to compute geomean

                                                          │  old.txt   │      new.txt      │
                                                          │    B/op    │    B/op     vs base   │
AddAttribute/with_a_new_string_attribute-20                 16.00 ± 0%
AddAttribute/with_an_existing_attribute-20                  16.00 ± 0%
AddAttribute/with_a_duplicate_attribute-20                  16.00 ± 0%
AddAttribute/with_a_hundred_attributes_to_loop_through-20   16.00 ± 0%
PutAttribute/with_a_new_string_attribute-20                              16.00 ± 0%
PutAttribute/with_an_existing_attribute-20                               16.00 ± 0%
PutAttribute/with_a_duplicate_attribute-20                               16.00 ± 0%
PutAttribute/with_a_hundred_attributes_to_loop_through-20                16.00 ± 0%
geomean                                                     16.00        16.00       ? ¹ ²
¹ benchmark set differs from baseline; geomeans may not be comparable
² ratios must be >0 to compute geomean

                                                          │  old.txt   │      new.txt      │
                                                          │ allocs/op  │ allocs/op   vs base   │
AddAttribute/with_a_new_string_attribute-20                 1.000 ± 0%
AddAttribute/with_an_existing_attribute-20                  1.000 ± 0%
AddAttribute/with_a_duplicate_attribute-20                  1.000 ± 0%
AddAttribute/with_a_hundred_attributes_to_loop_through-20   1.000 ± 0%
PutAttribute/with_a_new_string_attribute-20                              1.000 ± 0%
PutAttribute/with_an_existing_attribute-20                               1.000 ± 0%
PutAttribute/with_a_duplicate_attribute-20                               1.000 ± 0%
PutAttribute/with_a_hundred_attributes_to_loop_through-20                1.000 ± 0%
geomean                                                     1.000        1.000       ? ¹ ²
¹ benchmark set differs from baseline; geomeans may not be comparable
² ratios must be >0 to compute geomean

See also #12390

@github-actions github-actions bot requested review from bogdandrutu and dmitryax April 3, 2025 14:59
@rockdaboot rockdaboot force-pushed the profiles-PutAttributes branch from 58245f3 to f5c3129 Compare April 3, 2025 15:00
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 68.29268% with 13 lines in your changes missing coverage. Please review.

Project coverage is 91.63%. Comparing base (564818f) to head (2ae3be6).
Report is 62 commits behind head on main.

Files with missing lines Patch % Lines
pdata/pprofile/attributes.go 68.29% 9 Missing and 4 partials ⚠️

❌ Your patch check has failed because the patch coverage (68.29%) 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   #12798      +/-   ##
==========================================
+ Coverage   91.43%   91.63%   +0.20%     
==========================================
  Files         487      499      +12     
  Lines       26808    27452     +644     
==========================================
+ Hits        24511    25155     +644     
- Misses       1814     1815       +1     
+ Partials      483      482       -1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rockdaboot rockdaboot marked this pull request as ready for review April 3, 2025 15:22
@rockdaboot rockdaboot requested review from mx-psi, dmathieu and a team as code owners April 3, 2025 15:22
@dmathieu
Copy link
Member

dmathieu commented Apr 7, 2025

Additionally, the PutAttributes() helper takes into account the map k/v nature of attributes, while AddAttributes() didn't do this.

Could you describe that a bit more? (maybe in the changelog?) I find the motivation for this change hard to figure out.

@rockdaboot rockdaboot requested a review from dmathieu April 7, 2025 10:11
@rockdaboot rockdaboot requested a review from dmathieu April 14, 2025 10:06
@rockdaboot
Copy link
Contributor Author

@bogdandrutu @dmitryax Can you please take a look?

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