-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
introduce pprofile.AddAttribute helper #12390
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (66.66%) 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 #12390 +/- ##
==========================================
- Coverage 92.19% 92.07% -0.13%
==========================================
Files 465 465
Lines 25285 25200 -85
==========================================
- Hits 23311 23202 -109
- Misses 1575 1598 +23
- Partials 399 400 +1 ☔ View full report in Codecov by Sentry. |
@bogdandrutu I'm happy to hear your input on improvements here, especially with the loop through all attributes issue, and the use of |
Co-authored-by: Tim Rühsen <[email protected]>
Co-authored-by: Tim Rühsen <[email protected]>
// AddAttribute updates an AttributeTable and a record's AttributeIndices to | ||
// add a new attribute. | ||
// The record can by any struct that implements an `AttributeIndices` method. | ||
func AddAttribute(table AttributeTableSlice, record attributable, key string, value any) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come the attributable
type is not an exported type (of some package)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attributable is there to allow the behavior on any of the generated types that have attribute indices.
Location, Mapping, Sample.
Folks will only ever need to manipulate the generated struct. They don't need the interface.
Co-authored-by: Joshua MacDonald <[email protected]>
Description
This introduces the
pprofile.AddAttribute
helper method so profile extensions can modify attributes.Closes #12206
Those benchmarks kind of have an N+1 issue, where the method will take longer the more attributes there are.
However, since the attribute table is a map, we can't go around with looping through it.
I also had to use
FromRaw
andAsRaw
in there, to properly handleany
values.This currently doesn't support removing entries. But doing so would also have a non-trivial performance impact, since we'd have to loop through the
AttributeIndices
slice.