Skip to content
Merged
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-remove-add-attribute.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: Remove deprecated AddAttribute method

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

# (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]
34 changes: 0 additions & 34 deletions pdata/pprofile/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,6 @@ func FromAttributeIndices(table AttributeTableSlice, record attributable) pcommo
return m
}

// Deprecated: [v0.126.0] Use PutAttribute instead.
func AddAttribute(table AttributeTableSlice, record attributable, key string, value pcommon.Value) error {
for i := range table.Len() {
a := table.At(i)

if a.Key() == key && a.Value().Equal(value) {
if i >= math.MaxInt32 {
return fmt.Errorf("Attribute %s=%#v has too high an index to be added to AttributeIndices", key, value)
}

for j := range record.AttributeIndices().Len() {
v := record.AttributeIndices().At(j)
if v == int32(i) { //nolint:gosec // overflow checked
return nil
}
}

record.AttributeIndices().Append(int32(i)) //nolint:gosec // overflow checked
return nil
}
}

if table.Len() >= math.MaxInt32 {
return errors.New("AttributeTable can't take more attributes")
}
table.EnsureCapacity(table.Len() + 1)
entry := table.AppendEmpty()
entry.SetKey(key)
value.CopyTo(entry.Value())
record.AttributeIndices().Append(int32(table.Len()) - 1) //nolint:gosec // overflow checked

return nil
}

var errTooManyTableEntries = errors.New("too many entries in AttributeTable")

// PutAttribute updates an AttributeTable and a record's AttributeIndices to
Expand Down
30 changes: 0 additions & 30 deletions pdata/pprofile/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,6 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
)

func TestAddAttribute(t *testing.T) {
table := NewAttributeTableSlice()
att := table.AppendEmpty()
att.SetKey("hello")
att.Value().SetStr("world")

// Add a brand new attribute
loc := NewLocation()
err := AddAttribute(table, loc, "bonjour", pcommon.NewValueStr("monde"))
require.NoError(t, err)

assert.Equal(t, 2, table.Len())
assert.Equal(t, []int32{1}, loc.AttributeIndices().AsRaw())

// Add an already existing attribute
mapp := NewMapping()
err = AddAttribute(table, mapp, "hello", pcommon.NewValueStr("world"))
require.NoError(t, err)

assert.Equal(t, 2, table.Len())
assert.Equal(t, []int32{0}, mapp.AttributeIndices().AsRaw())

// Add a duplicate attribute
err = AddAttribute(table, mapp, "hello", pcommon.NewValueStr("world"))
require.NoError(t, err)

assert.Equal(t, 2, table.Len())
assert.Equal(t, []int32{0}, mapp.AttributeIndices().AsRaw())
}

func TestFromAttributeIndices(t *testing.T) {
table := NewAttributeTableSlice()
att := table.AppendEmpty()
Expand Down
Loading