Skip to content

Commit 6cde802

Browse files
authored
[pdata] Rename methods dealing with slices of primitive type items (#5344)
* [pdata] Rename methods dealing with slices of primitive type items - In preparation of migration to immutable slices for primitive type items the following methods are renamed: - `Value.BytesVal` func is deprecated in favor of `Value.MBytesVal`. - `Value.SetBytesVal` func is deprecated in favor of `Value.SetMBytesVal`. - `Value.UpdateBytes` func is deprecated in favor of `Value.UpdateMBytes`. - `Value.InsertBytes` func is deprecated in favor of `Value.InsertMBytes`. - `Value.UpsertBytes` func is deprecated in favor of `Value.UpsertMBytes`. - `<HistogramDataPoint|Buckets>.BucketCounts` funcs are deprecated in favor of `<HistogramDataPoint|Buckets>.MBucketCounts`. - `<HistogramDataPoint|Buckets>.SetBucketCounts` funcs are deprecated in favor of `<HistogramDataPoint|Buckets>.SetMBucketCounts`. - `HistogramDataPoint.ExplicitBounds` func is deprecated in favor of `HistogramDataPoint.MExplicitBounds`. - `HistogramDataPoint.SetExplicitBounds` func is deprecated in favor of `HistogramDataPoint.SetMExplicitBounds`. * Update CHANGELOG.md
1 parent 7f66c9c commit 6cde802

File tree

11 files changed

+172
-68
lines changed

11 files changed

+172
-68
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111
### 🚩 Deprecations 🚩
1212

13+
- In preparation of migration to immutable slices for primitive type items, the following methods are renamed (#5344)
14+
- `Value.BytesVal` func is deprecated in favor of `Value.MBytesVal`.
15+
- `Value.SetBytesVal` func is deprecated in favor of `Value.SetMBytesVal`.
16+
- `Value.UpdateBytes` func is deprecated in favor of `Value.UpdateMBytes`.
17+
- `Value.InsertBytes` func is deprecated in favor of `Value.InsertMBytes`.
18+
- `Value.UpsertBytes` func is deprecated in favor of `Value.UpsertMBytes`.
19+
- `<HistogramDataPoint|Buckets>.BucketCounts` funcs are deprecated in favor of
20+
`<HistogramDataPoint|Buckets>.MBucketCounts`.
21+
- `<HistogramDataPoint|Buckets>.SetBucketCounts` funcs are deprecated in favor of
22+
`<HistogramDataPoint|Buckets>.SetMBucketCounts`.
23+
- `HistogramDataPoint.ExplicitBounds` func is deprecated in favor of `HistogramDataPoint.MExplicitBounds`.
24+
- `HistogramDataPoint.SetExplicitBounds` func is deprecated in favor of `HistogramDataPoint.SetMExplicitBounds`.
25+
1326
### 💡 Enhancements 💡
1427

1528
- `pdata`: Expose `pcommon.NewSliceFromRay` and `pcommon.Slice.AsRaw` functions (#5298)

internal/otlptext/databuffer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ func (b *dataBuffer) logDoubleHistogramDataPoints(ps pmetric.HistogramDataPointS
119119
b.logEntry("Count: %d", p.Count())
120120
b.logEntry("Sum: %f", p.Sum())
121121

122-
bounds := p.ExplicitBounds()
122+
bounds := p.MExplicitBounds()
123123
if len(bounds) != 0 {
124124
for i, bound := range bounds {
125125
b.logEntry("ExplicitBounds #%d: %f", i, bound)
126126
}
127127
}
128128

129-
buckets := p.BucketCounts()
129+
buckets := p.MBucketCounts()
130130
if len(buckets) != 0 {
131131
for j, bucket := range buckets {
132132
b.logEntry("Buckets #%d, Count: %d", j, bucket)
@@ -157,13 +157,13 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis
157157
// uses a lookup table for the last finite boundary, which can be
158158
// easily computed using `math/big` (for scales up to 20).
159159

160-
negB := p.Negative().BucketCounts()
161-
posB := p.Positive().BucketCounts()
160+
negB := p.Negative().MBucketCounts()
161+
posB := p.Positive().MBucketCounts()
162162

163163
for i := 0; i < len(negB); i++ {
164164
pos := len(negB) - i - 1
165165
index := p.Negative().Offset() + int32(pos)
166-
count := p.Negative().BucketCounts()[pos]
166+
count := p.Negative().MBucketCounts()[pos]
167167
lower := math.Exp(float64(index) * factor)
168168
upper := math.Exp(float64(index+1) * factor)
169169
b.logEntry("Bucket (%f, %f], Count: %d", -upper, -lower, count)
@@ -175,7 +175,7 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis
175175

176176
for pos := 0; pos < len(posB); pos++ {
177177
index := p.Positive().Offset() + int32(pos)
178-
count := p.Positive().BucketCounts()[pos]
178+
count := p.Positive().MBucketCounts()[pos]
179179
lower := math.Exp(float64(index) * factor)
180180
upper := math.Exp(float64(index+1) * factor)
181181
b.logEntry("Bucket [%f, %f), Count: %d", lower, upper, count)

internal/testdata/metric.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ func initHistogramMetric(hm pmetric.Metric) {
206206
hdp1.SetTimestamp(TestMetricTimestamp)
207207
hdp1.SetCount(1)
208208
hdp1.SetSum(15)
209-
hdp1.SetBucketCounts([]uint64{0, 1})
209+
hdp1.SetMBucketCounts([]uint64{0, 1})
210210
exemplar := hdp1.Exemplars().AppendEmpty()
211211
exemplar.SetTimestamp(TestMetricExemplarTimestamp)
212212
exemplar.SetDoubleVal(15)
213213
initMetricAttachment(exemplar.FilteredAttributes())
214-
hdp1.SetExplicitBounds([]float64{1})
214+
hdp1.SetMExplicitBounds([]float64{1})
215215
}
216216

217217
func initExponentialHistogramMetric(hm pmetric.Metric) {
@@ -229,10 +229,10 @@ func initExponentialHistogramMetric(hm pmetric.Metric) {
229229

230230
// positive index 1 and 2 are values sqrt(2), 2 at scale 1
231231
hdp0.Positive().SetOffset(1)
232-
hdp0.Positive().SetBucketCounts([]uint64{1, 1})
232+
hdp0.Positive().SetMBucketCounts([]uint64{1, 1})
233233
// negative index -1 and 0 are values -1/sqrt(2), -1 at scale 1
234234
hdp0.Negative().SetOffset(-1)
235-
hdp0.Negative().SetBucketCounts([]uint64{1, 1})
235+
hdp0.Negative().SetMBucketCounts([]uint64{1, 1})
236236

237237
// The above will print:
238238
// Bucket (-1.414214, -1.000000], Count: 1
@@ -252,7 +252,7 @@ func initExponentialHistogramMetric(hm pmetric.Metric) {
252252

253253
// index -1 and 0 are values 0.25, 1 at scale -1
254254
hdp1.Positive().SetOffset(-1)
255-
hdp1.Positive().SetBucketCounts([]uint64{1, 1})
255+
hdp1.Positive().SetMBucketCounts([]uint64{1, 1})
256256

257257
// The above will print:
258258
// Bucket [0, 0], Count: 1

pdata/internal/cmd/pdatagen/internal/metrics_structs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ var valueFloat64Field = &primitiveField{
476476
}
477477

478478
var bucketCountsField = &primitiveSliceField{
479-
fieldName: "BucketCounts",
479+
fieldName: "MBucketCounts",
480480
originFieldName: "BucketCounts",
481481
returnType: "[]uint64",
482482
defaultVal: "[]uint64(nil)",
@@ -485,7 +485,7 @@ var bucketCountsField = &primitiveSliceField{
485485
}
486486

487487
var explicitBoundsField = &primitiveSliceField{
488-
fieldName: "ExplicitBounds",
488+
fieldName: "MExplicitBounds",
489489
originFieldName: "ExplicitBounds",
490490
returnType: "[]float64",
491491
defaultVal: "[]float64(nil)",

pdata/internal/common.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,19 @@ func (v Value) SliceVal() Slice {
262262
// If the Type() is not ValueTypeBytes then returns false.
263263
// Calling this function on zero-initialized Value will cause a panic.
264264
// Modifying the returned []byte in-place is forbidden.
265+
// Deprecated: [0.51.0] Use MBytesVal instead.
265266
func (v Value) BytesVal() []byte {
266267
return v.orig.GetBytesValue()
267268
}
268269

270+
// MBytesVal returns the []byte value associated with this Value.
271+
// If the Type() is not ValueTypeBytes then returns false.
272+
// Calling this function on zero-initialized Value will cause a panic.
273+
// Modifying the returned []byte in-place is forbidden.
274+
func (v Value) MBytesVal() []byte {
275+
return v.orig.GetBytesValue()
276+
}
277+
269278
// SetStringVal replaces the string value associated with this Value,
270279
// it also changes the type to be ValueTypeString.
271280
// Calling this function on zero-initialized Value will cause a panic.
@@ -299,10 +308,20 @@ func (v Value) SetBoolVal(bv bool) {
299308
// Calling this function on zero-initialized Value will cause a panic.
300309
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
301310
// across multiple attributes is forbidden.
311+
// Deprecated: [0.51.0] Use SetMBytesVal instead.
302312
func (v Value) SetBytesVal(bv []byte) {
303313
v.orig.Value = &otlpcommon.AnyValue_BytesValue{BytesValue: bv}
304314
}
305315

316+
// SetMBytesVal replaces the []byte value associated with this Value,
317+
// it also changes the type to be ValueTypeBytes.
318+
// Calling this function on zero-initialized Value will cause a panic.
319+
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
320+
// across multiple attributes is forbidden.
321+
func (v Value) SetMBytesVal(bv []byte) {
322+
v.orig.Value = &otlpcommon.AnyValue_BytesValue{BytesValue: bv}
323+
}
324+
306325
// copyTo copies the value to Value. Will panic if dest is nil.
307326
func (v Value) copyTo(dest *otlpcommon.AnyValue) {
308327
switch ov := v.orig.Value.(type) {
@@ -709,12 +728,23 @@ func (m Map) InsertBool(k string, v bool) {
709728
// No action is applied to the map where the key already exists.
710729
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
711730
// across multiple attributes is forbidden.
731+
// Deprecated: [0.51.0] Use InsertMBytes instead.
712732
func (m Map) InsertBytes(k string, v []byte) {
713733
if _, existing := m.Get(k); !existing {
714734
*m.orig = append(*m.orig, newAttributeKeyValueBytes(k, v))
715735
}
716736
}
717737

738+
// InsertMBytes adds the []byte Value to the map when the key does not exist.
739+
// No action is applied to the map where the key already exists.
740+
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
741+
// across multiple attributes is forbidden.
742+
func (m Map) InsertMBytes(k string, v []byte) {
743+
if _, existing := m.Get(k); !existing {
744+
*m.orig = append(*m.orig, newAttributeKeyValueBytes(k, v))
745+
}
746+
}
747+
718748
// Update updates an existing Value with a value.
719749
// No action is applied to the map where the key does not exist.
720750
//
@@ -764,9 +794,20 @@ func (m Map) UpdateBool(k string, v bool) {
764794
// No action is applied to the map where the key does not exist.
765795
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
766796
// across multiple attributes is forbidden.
797+
// Deprecated: [0.51.0] Use UpdateMBytes instead.
767798
func (m Map) UpdateBytes(k string, v []byte) {
768799
if av, existing := m.Get(k); existing {
769-
av.SetBytesVal(v)
800+
av.SetMBytesVal(v)
801+
}
802+
}
803+
804+
// UpdateMBytes updates an existing []byte Value with a value.
805+
// No action is applied to the map where the key does not exist.
806+
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
807+
// across multiple attributes is forbidden.
808+
func (m Map) UpdateMBytes(k string, v []byte) {
809+
if av, existing := m.Get(k); existing {
810+
av.SetMBytesVal(v)
770811
}
771812
}
772813

@@ -835,9 +876,23 @@ func (m Map) UpsertBool(k string, v bool) {
835876
// updated to the map where the key already existed.
836877
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
837878
// across multiple attributes is forbidden.
879+
// Deprecated: [0.51.0] Use UpsertMBytes instead.
838880
func (m Map) UpsertBytes(k string, v []byte) {
839881
if av, existing := m.Get(k); existing {
840-
av.SetBytesVal(v)
882+
av.SetMBytesVal(v)
883+
} else {
884+
*m.orig = append(*m.orig, newAttributeKeyValueBytes(k, v))
885+
}
886+
}
887+
888+
// UpsertMBytes performs the Insert or Update action. The []byte Value is
889+
// inserted to the map that did not originally have the key. The key/value is
890+
// updated to the map where the key already existed.
891+
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
892+
// across multiple attributes is forbidden.
893+
func (m Map) UpsertMBytes(k string, v []byte) {
894+
if av, existing := m.Get(k); existing {
895+
av.SetMBytesVal(v)
841896
} else {
842897
*m.orig = append(*m.orig, newAttributeKeyValueBytes(k, v))
843898
}

pdata/internal/common_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func TestNilMap(t *testing.T) {
298298
assert.EqualValues(t, generateTestBoolMap(), insertMapBool)
299299

300300
insertMapBytes := NewMap()
301-
insertMapBytes.InsertBytes("k", []byte{1, 2, 3, 4, 5})
301+
insertMapBytes.InsertMBytes("k", []byte{1, 2, 3, 4, 5})
302302
assert.EqualValues(t, generateTestBytesMap(), insertMapBytes)
303303

304304
updateMap := NewMap()
@@ -322,7 +322,7 @@ func TestNilMap(t *testing.T) {
322322
assert.EqualValues(t, NewMap(), updateMapBool)
323323

324324
updateMapBytes := NewMap()
325-
updateMapBytes.UpdateBytes("k", []byte{1, 2, 3})
325+
updateMapBytes.UpdateMBytes("k", []byte{1, 2, 3})
326326
assert.EqualValues(t, NewMap(), updateMapBytes)
327327

328328
upsertMap := NewMap()
@@ -346,7 +346,7 @@ func TestNilMap(t *testing.T) {
346346
assert.EqualValues(t, generateTestBoolMap(), upsertMapBool)
347347

348348
upsertMapBytes := NewMap()
349-
upsertMapBytes.UpsertBytes("k", []byte{1, 2, 3, 4, 5})
349+
upsertMapBytes.UpsertMBytes("k", []byte{1, 2, 3, 4, 5})
350350
assert.EqualValues(t, generateTestBytesMap(), upsertMapBytes)
351351

352352
removeMap := NewMap()
@@ -412,7 +412,7 @@ func TestMapWithEmpty(t *testing.T) {
412412
assert.EqualValues(t, ValueTypeBool, val.Type())
413413
assert.True(t, val.BoolVal())
414414

415-
sm.InsertBytes("other_key_bytes", []byte{1, 2, 3})
415+
sm.InsertMBytes("other_key_bytes", []byte{1, 2, 3})
416416
val, exist = sm.Get("other_key_bytes")
417417
assert.True(t, exist)
418418
assert.EqualValues(t, ValueTypeBytes, val.Type())
@@ -448,7 +448,7 @@ func TestMapWithEmpty(t *testing.T) {
448448
assert.EqualValues(t, ValueTypeBool, val.Type())
449449
assert.False(t, val.BoolVal())
450450

451-
sm.UpdateBytes("other_key_bytes", []byte{4, 5, 6})
451+
sm.UpdateMBytes("other_key_bytes", []byte{4, 5, 6})
452452
val, exist = sm.Get("other_key_bytes")
453453
assert.True(t, exist)
454454
assert.EqualValues(t, ValueTypeBytes, val.Type())
@@ -484,7 +484,7 @@ func TestMapWithEmpty(t *testing.T) {
484484
assert.EqualValues(t, ValueTypeBool, val.Type())
485485
assert.True(t, val.BoolVal())
486486

487-
sm.UpsertBytes("other_key_bytes", []byte{7, 8, 9})
487+
sm.UpsertMBytes("other_key_bytes", []byte{7, 8, 9})
488488
val, exist = sm.Get("other_key_bytes")
489489
assert.True(t, exist)
490490
assert.EqualValues(t, ValueTypeBytes, val.Type())
@@ -520,7 +520,7 @@ func TestMapWithEmpty(t *testing.T) {
520520
assert.EqualValues(t, ValueTypeBool, val.Type())
521521
assert.False(t, val.BoolVal())
522522

523-
sm.UpsertBytes("yet_another_key_bytes", []byte{1})
523+
sm.UpsertMBytes("yet_another_key_bytes", []byte{1})
524524
val, exist = sm.Get("yet_another_key_bytes")
525525
assert.True(t, exist)
526526
assert.EqualValues(t, ValueTypeBytes, val.Type())

pdata/internal/generated_pmetric.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)