Skip to content

Commit

Permalink
Upgrade pdata to proto 1.4.0 (#11722)
Browse files Browse the repository at this point in the history
This upgrades pdata to the
[1.4.0](https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v1.4.0)
version of protobufs.

Sorry for the very large PR. This can't really be split into smaller PRs
though, as changes are not backwards compatible.

This PR includes
#11706, as
the two are very close and separating them would cause weird conflicts.
The two changes can be merged either as separate PRs (with 11706 first),
or as one.

Closes
#11720

cc @mx-psi

---------

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
dmathieu and mx-psi authored Nov 28, 2024
1 parent b52e39c commit 33264a5
Show file tree
Hide file tree
Showing 94 changed files with 3,848 additions and 4,756 deletions.
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]
25 changes: 25 additions & 0 deletions .chloggen/profiles-proto-1-4-0.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: Upgrade pdata to opentelemetry-proto v1.4.0

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

# (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: [user]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ ocb:
OPENTELEMETRY_PROTO_SRC_DIR=pdata/internal/opentelemetry-proto

# The branch matching the current version of the proto to use
OPENTELEMETRY_PROTO_VERSION=v1.3.1
OPENTELEMETRY_PROTO_VERSION=v1.4.0

# Find all .proto files.
OPENTELEMETRY_PROTO_FILES := $(subst $(OPENTELEMETRY_PROTO_SRC_DIR)/,,$(wildcard $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/*/v1/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/collector/*/v1/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/*/v1experimental/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/collector/*/v1experimental/*.proto))
OPENTELEMETRY_PROTO_FILES := $(subst $(OPENTELEMETRY_PROTO_SRC_DIR)/,,$(wildcard $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/*/v1/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/collector/*/v1/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/*/v1development/*.proto $(OPENTELEMETRY_PROTO_SRC_DIR)/opentelemetry/proto/collector/*/v1development/*.proto))

# Target directory to write generated files to.
PROTO_TARGET_GEN_DIR=pdata/internal/data/protogen
Expand Down
2 changes: 1 addition & 1 deletion exporter/debugexporter/internal/normal/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (normalProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, er
buffer.WriteString(profile.ProfileID().String())

buffer.WriteString(" samples=")
buffer.WriteString(strconv.Itoa(profile.Profile().Sample().Len()))
buffer.WriteString(strconv.Itoa(profile.Sample().Len()))

if profile.Attributes().Len() > 0 {
profileAttributes := writeAttributes(profile.Attributes())
Expand Down
4 changes: 2 additions & 2 deletions exporter/debugexporter/internal/normal/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestMarshalProfiles(t *testing.T) {
profiles := pprofile.NewProfiles()
profile := profiles.ResourceProfiles().AppendEmpty().ScopeProfiles().AppendEmpty().Profiles().AppendEmpty()
profile.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
profile.Profile().Sample().AppendEmpty()
profile.Profile().Sample().AppendEmpty()
profile.Sample().AppendEmpty()
profile.Sample().AppendEmpty()
profile.Attributes().PutStr("key1", "value1")
return profiles
}(),
Expand Down
44 changes: 17 additions & 27 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 @@ -312,21 +312,16 @@ func (b *dataBuffer) logProfileSamples(ss pprofile.SampleSlice) {
b.logEntry(" Sample #%d", i)
sample := ss.At(i)

b.logEntry(" Location index: %d", sample.LocationIndex().AsRaw())
b.logEntry(" Location length: %d", sample.LocationsLength())
b.logEntry(" Stacktrace ID index: %d", sample.StacktraceIdIndex())
if lb := sample.Label().Len(); lb > 0 {
for j := 0; j < lb; j++ {
b.logEntry(" Label #%d", j)
b.logEntry(" -> Key: %d", sample.Label().At(j).Key())
b.logEntry(" -> Str: %d", sample.Label().At(j).Str())
b.logEntry(" -> Num: %d", sample.Label().At(j).Num())
b.logEntry(" -> Num unit: %d", sample.Label().At(j).NumUnit())
b.logEntry(" Value: %d", sample.Value().AsRaw())

if lai := sample.AttributeIndices().Len(); lai > 0 {
b.logEntry(" Attributes:")
for j := 0; j < lai; j++ {
attr := attrs.At(int(sample.AttributeIndices().At(j)))
b.logEntry(" -> %s: %s", attr.Key(), attr.Value().AsRaw())
}
}
b.logEntry(" Value: %d", sample.Value().AsRaw())
b.logEntry(" Attributes: %d", sample.Attributes().AsRaw())
b.logEntry(" Link: %d", sample.Link())
}
}

Expand All @@ -339,13 +334,11 @@ func (b *dataBuffer) logProfileMappings(ms pprofile.MappingSlice) {
b.logEntry(" Mapping #%d", i)
mapping := ms.At(i)

b.logEntry(" ID: %d", mapping.ID())
b.logEntry(" Memory start: %d", mapping.MemoryStart())
b.logEntry(" Memory limit: %d", mapping.MemoryLimit())
b.logEntry(" File offset: %d", mapping.FileOffset())
b.logEntry(" File name: %d", mapping.Filename())
b.logEntry(" Build ID: %d", mapping.BuildID())
b.logEntry(" Attributes: %d", mapping.Attributes().AsRaw())
b.logEntry(" File name: %d", mapping.FilenameStrindex())
b.logEntry(" Attributes: %d", mapping.AttributeIndices().AsRaw())
b.logEntry(" Has functions: %t", mapping.HasFunctions())
b.logEntry(" Has filenames: %t", mapping.HasFilenames())
b.logEntry(" Has line numbers: %t", mapping.HasLineNumbers())
Expand All @@ -362,7 +355,6 @@ func (b *dataBuffer) logProfileLocations(ls pprofile.LocationSlice) {
b.logEntry(" Location #%d", i)
location := ls.At(i)

b.logEntry(" ID: %d", location.ID())
b.logEntry(" Mapping index: %d", location.MappingIndex())
b.logEntry(" Address: %d", location.Address())
if ll := location.Line().Len(); ll > 0 {
Expand All @@ -375,8 +367,7 @@ func (b *dataBuffer) logProfileLocations(ls pprofile.LocationSlice) {
}
}
b.logEntry(" Is folded: %t", location.IsFolded())
b.logEntry(" Type index: %d", location.TypeIndex())
b.logEntry(" Attributes: %d", location.Attributes().AsRaw())
b.logEntry(" Attributes: %d", location.AttributeIndices().AsRaw())
}
}

Expand All @@ -389,10 +380,9 @@ func (b *dataBuffer) logProfileFunctions(fs pprofile.FunctionSlice) {
b.logEntry(" Function #%d", i)
function := fs.At(i)

b.logEntry(" ID: %d", function.ID())
b.logEntry(" Name: %d", function.Name())
b.logEntry(" System name: %d", function.SystemName())
b.logEntry(" Filename: %d", function.Filename())
b.logEntry(" Name: %d", function.NameStrindex())
b.logEntry(" System name: %d", function.SystemNameStrindex())
b.logEntry(" Filename: %d", function.FilenameStrindex())
b.logEntry(" Start line: %d", function.StartLine())
}
}
Expand All @@ -408,7 +398,7 @@ func (b *dataBuffer) logStringTable(ss pcommon.StringSlice) {
}
}

func (b *dataBuffer) logComment(c pcommon.Int64Slice) {
func (b *dataBuffer) logComment(c pcommon.Int32Slice) {
if c.Len() == 0 {
return
}
Expand All @@ -423,8 +413,8 @@ func attributeUnitsToMap(aus pprofile.AttributeUnitSlice) pcommon.Map {
m := pcommon.NewMap()
for i := 0; i < aus.Len(); i++ {
au := aus.At(i)
m.PutInt("attributeKey", au.AttributeKey())
m.PutInt("unit", au.Unit())
m.PutInt("attributeKey", int64(au.AttributeKeyStrindex()))
m.PutInt("unit", int64(au.UnitStrindex()))
}
return m
}
Expand Down
29 changes: 11 additions & 18 deletions exporter/debugexporter/internal/otlptext/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,29 @@ func (textProfilesMarshaler) MarshalProfiles(pd pprofile.Profiles) ([]byte, erro
buf.logEntry("Profile #%d", k)
profile := profiles.At(k)
buf.logAttr("Profile ID", profile.ProfileID())
buf.logAttr("Start time", profile.StartTime().String())
buf.logAttr("End time", profile.EndTime().String())
buf.logAttr("Start time", profile.Time().String())
buf.logAttr("Duration", profile.Duration().String())
buf.logAttributes("Attributes", profile.Attributes())
buf.logAttr("Dropped attributes count", strconv.FormatUint(uint64(profile.DroppedAttributesCount()), 10))
buf.logEntry(" Location indices: %d", profile.Profile().LocationIndices().AsRaw())
buf.logEntry(" Drop frames: %d", profile.Profile().DropFrames())
buf.logEntry(" Keep frames: %d", profile.Profile().KeepFrames())
buf.logEntry(" Location indices: %d", profile.LocationIndices().AsRaw())

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

buf.logAttributesWithIndentation(
"Attribute table",
profile.Profile().AttributeTable(),
4)
buf.logProfileSamples(profile.Sample(), profile.AttributeTable())
buf.logProfileMappings(profile.MappingTable())
buf.logProfileLocations(profile.LocationTable())
buf.logProfileFunctions(profile.FunctionTable())

buf.logAttributesWithIndentation(
"Attribute units",
attributeUnitsToMap(profile.Profile().AttributeUnits()),
attributeUnitsToMap(profile.AttributeUnits()),
4)

buf.logAttributesWithIndentation(
"Link table",
linkTableToMap(profile.Profile().LinkTable()),
linkTableToMap(profile.LinkTable()),
4)

buf.logStringTable(profile.Profile().StringTable())
buf.logComment(profile.Profile().Comment())
buf.logStringTable(profile.StringTable())
buf.logComment(profile.CommentStrindices())
}
}
}
Expand Down
53 changes: 20 additions & 33 deletions exporter/debugexporter/internal/otlptext/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,66 +53,53 @@ func extendProfiles(profiles pprofile.Profiles) pprofile.Profiles {
switch i % 2 {
case 0:
profile := sc.Profiles().At(i)
profile.Profile().LocationIndices().FromRaw([]int64{1})
label := profile.Profile().Sample().At(0).Label().AppendEmpty()
label.SetKey(1)
label.SetStr(2)
label.SetNum(3)
label.SetNumUnit(4)
profile.LocationIndices().FromRaw([]int32{1})

location := profile.Profile().Location().AppendEmpty()
location.SetID(2)
location := profile.LocationTable().AppendEmpty()
location.SetMappingIndex(3)
location.SetAddress(4)
line := location.Line().AppendEmpty()
line.SetFunctionIndex(1)
line.SetLine(2)
line.SetColumn(3)
location.SetIsFolded(true)
location.SetTypeIndex(5)
location.Attributes().FromRaw([]uint64{6, 7})
location.AttributeIndices().FromRaw([]int32{6, 7})

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

attributeUnits := profile.Profile().AttributeUnits().AppendEmpty()
attributeUnits.SetAttributeKey(1)
attributeUnits.SetUnit(5)
attributeUnits := profile.AttributeUnits().AppendEmpty()
attributeUnits.SetAttributeKeyStrindex(1)
attributeUnits.SetUnitStrindex(5)

profile.Profile().StringTable().Append("foobar")
profile.StringTable().Append("foobar")
case 1:
profile := sc.Profiles().At(i)
profile.Profile().SetDropFrames(1)
profile.Profile().SetKeepFrames(2)

mapping := profile.Profile().Mapping().AppendEmpty()
mapping.SetID(1)
mapping := profile.MappingTable().AppendEmpty()
mapping.SetMemoryStart(2)
mapping.SetMemoryLimit(3)
mapping.SetFileOffset(4)
mapping.SetFilename(5)
mapping.SetBuildID(6)
mapping.Attributes().FromRaw([]uint64{7, 8})
mapping.SetFilenameStrindex(5)
mapping.AttributeIndices().FromRaw([]int32{7, 8})
mapping.SetHasFunctions(true)
mapping.SetHasFilenames(true)
mapping.SetHasLineNumbers(true)
mapping.SetHasInlineFrames(true)

function := profile.Profile().Function().AppendEmpty()
function.SetID(1)
function.SetName(2)
function.SetSystemName(3)
function.SetFilename(4)
function := profile.FunctionTable().AppendEmpty()
function.SetNameStrindex(2)
function.SetSystemNameStrindex(3)
function.SetFilenameStrindex(4)
function.SetStartLine(5)

linkTable := profile.Profile().LinkTable().AppendEmpty()
linkTable := profile.LinkTable().AppendEmpty()
linkTable.SetTraceID([16]byte{0x03, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
linkTable.SetSpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18})

profile.Profile().Comment().FromRaw([]int64{1, 2})
profile.CommentStrindices().FromRaw([]int32{1, 2})
}
}
return profiles
Expand Down
Loading

0 comments on commit 33264a5

Please sign in to comment.