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

Make pprofile attribute table a real slice #11706

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/profiles-attributetable-slice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pdata/pprofile

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: AttributeTable is now a slice rather than a map

# One or more tracking issues or pull requests related to the change
issues: [11706]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
14 changes: 12 additions & 2 deletions exporter/debugexporter/internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (b *dataBuffer) logExemplars(description string, se pmetric.ExemplarSlice)
}
}

func (b *dataBuffer) logProfileSamples(ss pprofile.SampleSlice) {
func (b *dataBuffer) logProfileSamples(ss pprofile.SampleSlice, attrs pprofile.AttributeTableSlice) {
if ss.Len() == 0 {
return
}
Expand All @@ -325,7 +325,17 @@ func (b *dataBuffer) logProfileSamples(ss pprofile.SampleSlice) {
}
}
b.logEntry(" Value: %d", sample.Value().AsRaw())
b.logEntry(" Attributes: %d", sample.Attributes().AsRaw())

if lai := sample.Attributes().Len(); lai > 0 {
b.logEntry(" Attributes:")
for j := 0; j < lai; j++ {
if sample.Attributes().At(j) <= math.MaxInt32 {
Copy link
Member Author

Choose a reason for hiding this comment

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

The next version of the proto uses an int32 rather than an uint64 here. So after the next proto release/upgrade, we won't need this check anymore.

attr := attrs.At(int(sample.Attributes().At(j))) // nolint:gosec // overflow has been checked
b.logEntry(" -> %s: %s", attr.Key(), attr.Value().AsRaw())
}
}
}

b.logEntry(" Link: %d", sample.Link())
}
}
Expand Down
7 changes: 1 addition & 6 deletions exporter/debugexporter/internal/otlptext/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,11 @@ func (textProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, erro
buf.logEntry(" Drop frames: %d", profile.Profile().DropFrames())
buf.logEntry(" Keep frames: %d", profile.Profile().KeepFrames())

buf.logProfileSamples(profile.Profile().Sample())
buf.logProfileSamples(profile.Profile().Sample(), profile.Profile().AttributeTable())
buf.logProfileMappings(profile.Profile().Mapping())
buf.logProfileLocations(profile.Profile().Location())
buf.logProfileFunctions(profile.Profile().Function())

buf.logAttributesWithIndentation(
"Attribute table",
profile.Profile().AttributeTable(),
4)

buf.logAttributesWithIndentation(
"Attribute units",
attributeUnitsToMap(profile.Profile().AttributeUnits()),
Expand Down
9 changes: 4 additions & 5 deletions exporter/debugexporter/internal/otlptext/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ func extendProfiles(profiles pprofile.Profiles) pprofile.Profiles {
location.SetTypeIndex(5)
location.Attributes().FromRaw([]uint64{6, 7})

_ = profile.Profile().AttributeTable().FromRaw(map[string]any{
"value": map[string]any{
"intValue": "42",
},
})
at := profile.Profile().AttributeTable()
a := at.AppendEmpty()
a.SetKey("intValue")
a.Value().SetInt(42)

attributeUnits := profile.Profile().AttributeUnits().AppendEmpty()
attributeUnits.SetAttributeKey(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Profile #0
-> Num: 3
-> Num unit: 4
Value: [4]
Attributes: [5]
Attributes:
-> key: value
Link: 42
Location #0
ID: 2
Expand All @@ -36,8 +37,6 @@ Profile #0
Is folded: true
Type index: 5
Attributes: [6 7]
Attribute table:
-> value: Map({"intValue":"42"})
Attribute units:
-> attributeKey: Int(1)
-> unit: Int(5)
Expand All @@ -56,7 +55,8 @@ Profile #1
Location length: 20
Stacktrace ID index: 8
Value: [9]
Attributes: [10]
Attributes:
-> key: value
Link: 44
Mapping #0
ID: 1
Expand Down
27 changes: 26 additions & 1 deletion pdata/internal/cmd/pdatagen/internal/pprofile_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var pprofile = &Package{
line,
functionSlice,
function,
attributeTableSlice,
attribute,
attributeUnitSlice,
attributeUnit,
linkSlice,
Expand Down Expand Up @@ -161,7 +163,7 @@ var profile = &messageValueStruct{
},
&sliceField{
fieldName: "AttributeTable",
returnSlice: mapStruct,
returnSlice: attributeTableSlice,
},
&sliceField{
fieldName: "AttributeUnits",
Expand Down Expand Up @@ -525,6 +527,29 @@ var line = &messageValueStruct{
},
}

var attributeTableSlice = &sliceOfValues{
structName: "AttributeTableSlice",
element: attribute,
}

var attribute = &messageValueStruct{
structName: "Attribute",
description: "// Attribute describes an attribute stored in a profile's attribute table.",
originFullName: "v1.KeyValue",
fields: []baseField{
&primitiveField{
fieldName: "Key",
returnType: "string",
defaultVal: `""`,
testVal: `"key"`,
},
&messageValueField{
fieldName: "Value",
returnMessage: anyValue,
},
},
}

var functionSlice = &sliceOfPtrs{
structName: "FunctionSlice",
element: function,
Expand Down
70 changes: 70 additions & 0 deletions pdata/pprofile/generated_attribute.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions pdata/pprofile/generated_attribute_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading