Skip to content

Commit 9c2137c

Browse files
authored
pprofile: Remove deprecated methods PutAttribute and PutLocation (#14082)
These two methods are deprecated and can be removed.
1 parent 74fe363 commit 9c2137c

File tree

6 files changed

+51
-403
lines changed

6 files changed

+51
-403
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: pdata/pprofile
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Remove deprecated `PutAttribute` helper method
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14082]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

.chloggen/remove-put-location.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: pdata/pprofile
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Remove deprecated `PutLocation` helper method
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14082]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

pdata/pprofile/attributes.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
55

66
import (
77
"errors"
8-
"fmt"
98
"math"
109

1110
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -34,96 +33,6 @@ func FromAttributeIndices(table KeyValueAndUnitSlice, record attributable, dic P
3433

3534
var errTooManyAttributeTableEntries = errors.New("too many entries in AttributeTable")
3635

37-
// PutAttribute updates an AttributeTable and a record's AttributeIndices to
38-
// add or update an attribute.
39-
// The assumption is that attributes are a map as for other signals (metrics, logs, etc.), thus
40-
// the same key must not appear twice in a list of attributes / attribute indices.
41-
// The record can be any struct that implements an `AttributeIndices` method.
42-
//
43-
// Deprecated: [v0.138.0] use SetAttribute instead.
44-
func PutAttribute(table KeyValueAndUnitSlice, record attributable, dic ProfilesDictionary, key string, value pcommon.Value) error {
45-
for i := range record.AttributeIndices().Len() {
46-
idx := int(record.AttributeIndices().At(i))
47-
if idx < 0 || idx >= table.Len() {
48-
return fmt.Errorf("index value %d out of range in AttributeIndices[%d]", idx, i)
49-
}
50-
attr := table.At(idx)
51-
52-
if dic.StringTable().At(int(attr.KeyStrindex())) == key {
53-
if attr.Value().Equal(value) {
54-
// Attribute already exists, nothing to do.
55-
return nil
56-
}
57-
58-
// If the attribute table already contains the key/value pair, just update the index.
59-
for j := range table.Len() {
60-
a := table.At(j)
61-
if dic.StringTable().At(int(a.KeyStrindex())) == key && a.Value().Equal(value) {
62-
if j > math.MaxInt32 {
63-
return errTooManyAttributeTableEntries
64-
}
65-
record.AttributeIndices().SetAt(i, int32(j)) //nolint:gosec // overflow checked
66-
return nil
67-
}
68-
}
69-
70-
if table.Len() >= math.MaxInt32 {
71-
return errTooManyAttributeTableEntries
72-
}
73-
74-
// Find the key in the StringTable, or add it
75-
keyID, err := SetString(dic.StringTable(), key)
76-
if err != nil {
77-
return err
78-
}
79-
80-
// Add the key/value pair as a new attribute to the table...
81-
entry := table.AppendEmpty()
82-
entry.SetKeyStrindex(keyID)
83-
value.CopyTo(entry.Value())
84-
85-
// ...and update the existing index.
86-
record.AttributeIndices().SetAt(i, int32(table.Len()-1)) //nolint:gosec // overflow checked
87-
return nil
88-
}
89-
}
90-
91-
if record.AttributeIndices().Len() >= math.MaxInt32 {
92-
return errors.New("too many entries in AttributeIndices")
93-
}
94-
95-
for j := range table.Len() {
96-
a := table.At(j)
97-
if dic.StringTable().At(int(a.KeyStrindex())) == key && a.Value().Equal(value) {
98-
if j > math.MaxInt32 {
99-
return errTooManyAttributeTableEntries
100-
}
101-
// Add the index of the existing attribute to the indices.
102-
record.AttributeIndices().Append(int32(j)) //nolint:gosec // overflow checked
103-
return nil
104-
}
105-
}
106-
107-
if table.Len() >= math.MaxInt32 {
108-
return errTooManyAttributeTableEntries
109-
}
110-
111-
// Find the key in the StringTable, or add it
112-
keyID, err := SetString(dic.StringTable(), key)
113-
if err != nil {
114-
return err
115-
}
116-
117-
// Add the key/value pair as a new attribute to the table...
118-
entry := table.AppendEmpty()
119-
entry.SetKeyStrindex(keyID)
120-
value.CopyTo(entry.Value())
121-
122-
// ...and add a new index to the indices.
123-
record.AttributeIndices().Append(int32(table.Len() - 1)) //nolint:gosec // overflow checked
124-
return nil
125-
}
126-
12736
// SetAttribute updates an AttributeTable, adding or providing a value and
12837
// returns its index.
12938
func SetAttribute(table KeyValueAndUnitSlice, attr KeyValueAndUnit) (int32, error) {

pdata/pprofile/attributes_test.go

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -49,88 +49,6 @@ func TestFromAttributeIndices(t *testing.T) {
4949
assert.Equal(t, attrs.AsRaw(), m)
5050
}
5151

52-
func testPutAttribute(t *testing.T, record attributable) {
53-
dic := NewProfilesDictionary()
54-
dic.StringTable().Append("")
55-
table := NewKeyValueAndUnitSlice()
56-
57-
// Put a first attribute.
58-
require.NoError(t, PutAttribute(table, record, dic, "hello", pcommon.NewValueStr("world")))
59-
assert.Equal(t, 1, table.Len())
60-
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
61-
62-
// Put an attribute, same key, same value.
63-
// This should be a no-op.
64-
require.NoError(t, PutAttribute(table, record, dic, "hello", pcommon.NewValueStr("world")))
65-
assert.Equal(t, 1, table.Len())
66-
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
67-
68-
// Special case: removing and adding again should not change the table as
69-
// this can lead to multiple identical attributes in the table.
70-
record.AttributeIndices().FromRaw([]int32{})
71-
require.NoError(t, PutAttribute(table, record, dic, "hello", pcommon.NewValueStr("world")))
72-
assert.Equal(t, 1, table.Len())
73-
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
74-
75-
// Put an attribute, same key, different value.
76-
// This updates the index and adds to the table.
77-
require.NoError(t, PutAttribute(table, record, dic, "hello", pcommon.NewValueStr("world2")))
78-
assert.Equal(t, 2, table.Len())
79-
assert.Equal(t, []int32{1}, record.AttributeIndices().AsRaw())
80-
81-
// Put an attribute that already exists in the table.
82-
// This updates the index and does not add to the table.
83-
require.NoError(t, PutAttribute(table, record, dic, "hello", pcommon.NewValueStr("world")))
84-
assert.Equal(t, 2, table.Len())
85-
assert.Equal(t, []int32{0}, record.AttributeIndices().AsRaw())
86-
87-
// Put a new attribute.
88-
// This adds an index and adds to the table.
89-
require.NoError(t, PutAttribute(table, record, dic, "good", pcommon.NewValueStr("day")))
90-
assert.Equal(t, 3, table.Len())
91-
assert.Equal(t, []int32{0, 2}, record.AttributeIndices().AsRaw())
92-
93-
// Add multiple distinct attributes.
94-
for i := range 100 {
95-
require.NoError(t, PutAttribute(table, record, dic, fmt.Sprintf("key_%d", i), pcommon.NewValueStr("day")))
96-
assert.Equal(t, i+4, table.Len())
97-
assert.Equal(t, i+3, record.AttributeIndices().Len())
98-
}
99-
100-
// Add a negative index to the record.
101-
record.AttributeIndices().Append(-1)
102-
tableLen := table.Len()
103-
indicesLen := record.AttributeIndices().Len()
104-
// Try putting a new attribute, make sure it fails, and that table/indices didn't change.
105-
require.Error(t, PutAttribute(table, record, dic, "newKey", pcommon.NewValueStr("value")))
106-
require.Equal(t, tableLen, table.Len())
107-
require.Equal(t, indicesLen, record.AttributeIndices().Len())
108-
109-
// Set the last index to the table length, which is out of range.
110-
record.AttributeIndices().SetAt(indicesLen-1, int32(tableLen)) //nolint:gosec
111-
// Try putting a new attribute, make sure it fails, and that table/indices didn't change.
112-
require.Error(t, PutAttribute(table, record, dic, "newKey", pcommon.NewValueStr("value")))
113-
require.Equal(t, tableLen, table.Len())
114-
require.Equal(t, indicesLen, record.AttributeIndices().Len())
115-
}
116-
117-
func TestPutAttribute(t *testing.T) {
118-
// Test every existing record type.
119-
for _, tt := range []struct {
120-
name string
121-
attr attributable
122-
}{
123-
{"Profile", NewProfile()},
124-
{"Sample", NewSample()},
125-
{"Mapping", NewMapping()},
126-
{"Location", NewLocation()},
127-
} {
128-
t.Run(tt.name, func(t *testing.T) {
129-
testPutAttribute(t, tt.attr)
130-
})
131-
}
132-
}
133-
13452
func BenchmarkFromAttributeIndices(b *testing.B) {
13553
dic := NewProfilesDictionary()
13654
table := NewKeyValueAndUnitSlice()
@@ -153,80 +71,6 @@ func BenchmarkFromAttributeIndices(b *testing.B) {
15371
}
15472
}
15573

156-
func BenchmarkPutAttribute(b *testing.B) {
157-
for _, bb := range []struct {
158-
name string
159-
key string
160-
value pcommon.Value
161-
162-
runBefore func(*testing.B, KeyValueAndUnitSlice, attributable, ProfilesDictionary)
163-
}{
164-
{
165-
name: "with a new string attribute",
166-
key: "attribute",
167-
value: pcommon.NewValueStr("test"),
168-
},
169-
{
170-
name: "with an existing attribute",
171-
key: "attribute",
172-
value: pcommon.NewValueStr("test"),
173-
174-
runBefore: func(_ *testing.B, table KeyValueAndUnitSlice, _ attributable, dic ProfilesDictionary) {
175-
dic.StringTable().Append("attribute")
176-
entry := table.AppendEmpty()
177-
entry.SetKeyStrindex(int32(dic.StringTable().Len())) //nolint:gosec // overflow impossible in test
178-
entry.Value().SetStr("test")
179-
},
180-
},
181-
{
182-
name: "with a duplicate attribute",
183-
key: "attribute",
184-
value: pcommon.NewValueStr("test"),
185-
186-
runBefore: func(_ *testing.B, table KeyValueAndUnitSlice, obj attributable, dic ProfilesDictionary) {
187-
require.NoError(b, PutAttribute(table, obj, dic, "attribute", pcommon.NewValueStr("test")))
188-
},
189-
},
190-
{
191-
name: "with a hundred attributes to loop through",
192-
key: "attribute",
193-
value: pcommon.NewValueStr("test"),
194-
195-
runBefore: func(_ *testing.B, table KeyValueAndUnitSlice, _ attributable, dic ProfilesDictionary) {
196-
for i := range 100 {
197-
dic.StringTable().Append(fmt.Sprintf("attr_%d", i))
198-
199-
entry := table.AppendEmpty()
200-
entry.SetKeyStrindex(int32(dic.StringTable().Len())) //nolint:gosec // overflow impossible in test
201-
entry.Value().SetStr("test")
202-
}
203-
204-
dic.StringTable().Append("attribute")
205-
entry := table.AppendEmpty()
206-
entry.SetKeyStrindex(int32(dic.StringTable().Len())) //nolint:gosec // overflow impossible in test
207-
entry.Value().SetStr("test")
208-
},
209-
},
210-
} {
211-
b.Run(bb.name, func(b *testing.B) {
212-
dic := NewProfilesDictionary()
213-
table := NewKeyValueAndUnitSlice()
214-
obj := NewLocation()
215-
216-
if bb.runBefore != nil {
217-
bb.runBefore(b, table, obj, dic)
218-
}
219-
220-
b.ResetTimer()
221-
b.ReportAllocs()
222-
223-
for b.Loop() {
224-
_ = PutAttribute(table, obj, dic, bb.key, bb.value)
225-
}
226-
})
227-
}
228-
}
229-
23074
func TestSetAttribute(t *testing.T) {
23175
table := NewKeyValueAndUnitSlice()
23276
attr := NewKeyValueAndUnit()

pdata/pprofile/locations.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
55

66
import (
77
"errors"
8-
"fmt"
98
"math"
109
)
1110

@@ -23,39 +22,7 @@ func FromLocationIndices(table LocationSlice, record Stack) LocationSlice {
2322
return m
2423
}
2524

26-
var (
27-
errTooManyLocationTableEntries = errors.New("too many entries in LocationTable")
28-
errTooManyLocationIndicesEntries = errors.New("too many entries in LocationIndices")
29-
)
30-
31-
// PutLocation updates a LocationTable and a Stack's LocationIndices to
32-
// add or update a location.
33-
//
34-
// Deprecated: [v0.138.0] use SetLocation instead.
35-
func PutLocation(table LocationSlice, record Stack, loc Location) error {
36-
for i, locIdx := range record.LocationIndices().All() {
37-
idx := int(locIdx)
38-
if idx < 0 || idx >= table.Len() {
39-
return fmt.Errorf("index value %d out of range in LocationIndices[%d]", idx, i)
40-
}
41-
locAt := table.At(idx)
42-
if locAt.Equal(loc) {
43-
// Location already exists, nothing to do.
44-
return nil
45-
}
46-
}
47-
48-
if record.LocationIndices().Len() >= math.MaxInt32 {
49-
return errTooManyLocationIndicesEntries
50-
}
51-
52-
id, err := SetLocation(table, loc)
53-
if err != nil {
54-
return err
55-
}
56-
record.LocationIndices().Append(id)
57-
return nil
58-
}
25+
var errTooManyLocationTableEntries = errors.New("too many entries in LocationTable")
5926

6027
// SetLocation updates a LocationTable, adding or providing a value and returns
6128
// its index.

0 commit comments

Comments
 (0)