Skip to content

Commit

Permalink
[pdata] Remove deprecated primitive slice getters/setters
Browse files Browse the repository at this point in the history
This is the second step in a sequence of backward changes to replace primitive slices with immutable structs
  • Loading branch information
dmitryax committed May 11, 2022
1 parent c368d49 commit cd13d54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 102 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
### 🛑 Breaking changes 🛑

- Remove deprecated pdata funcs/structs from v0.50.0 (#5345)
- Remove deprecated pdata getters and setters of primitive slice values: `Value.BytesVal`, `Value.SetBytesVal`,
`Value.UpdateBytes`, `Value.InsertBytes`, `Value.UpsertBytes`, `<HistogramDataPoint|Buckets>.BucketCounts`,
`<HistogramDataPoint|Buckets>.SetBucketCounts`, `HistogramDataPoint.ExplicitBounds`,
`HistogramDataPoint.SetExplicitBounds` (#5347)

### 🚩 Deprecations 🚩

Expand Down
59 changes: 2 additions & 57 deletions pdata/internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,6 @@ func (v Value) SliceVal() Slice {
return newSlice(&arr.Values)
}

// BytesVal returns the []byte value associated with this Value.
// If the Type() is not ValueTypeBytes then returns false.
// Calling this function on zero-initialized Value will cause a panic.
// Modifying the returned []byte in-place is forbidden.
// Deprecated: [0.51.0] Use MBytesVal instead.
func (v Value) BytesVal() []byte {
return v.orig.GetBytesValue()
}

// MBytesVal returns the []byte value associated with this Value.
// If the Type() is not ValueTypeBytes then returns false.
// Calling this function on zero-initialized Value will cause a panic.
Expand Down Expand Up @@ -303,16 +294,6 @@ func (v Value) SetBoolVal(bv bool) {
v.orig.Value = &otlpcommon.AnyValue_BoolValue{BoolValue: bv}
}

// SetBytesVal replaces the []byte value associated with this Value,
// it also changes the type to be ValueTypeBytes.
// Calling this function on zero-initialized Value will cause a panic.
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
// across multiple attributes is forbidden.
// Deprecated: [0.51.0] Use SetMBytesVal instead.
func (v Value) SetBytesVal(bv []byte) {
v.orig.Value = &otlpcommon.AnyValue_BytesValue{BytesValue: bv}
}

// SetMBytesVal replaces the []byte value associated with this Value,
// it also changes the type to be ValueTypeBytes.
// Calling this function on zero-initialized Value will cause a panic.
Expand Down Expand Up @@ -464,7 +445,7 @@ func (v Value) AsString() string {
return string(jsonStr)

case ValueTypeBytes:
return base64.StdEncoding.EncodeToString(v.BytesVal())
return base64.StdEncoding.EncodeToString(v.MBytesVal())

case ValueTypeSlice:
jsonStr, _ := json.Marshal(v.SliceVal().AsRaw())
Expand Down Expand Up @@ -519,7 +500,7 @@ func (v Value) asRaw() interface{} {
case ValueTypeInt:
return v.IntVal()
case ValueTypeBytes:
return v.BytesVal()
return v.MBytesVal()
case ValueTypeMap:
return v.MapVal().AsRaw()
case ValueTypeSlice:
Expand Down Expand Up @@ -724,17 +705,6 @@ func (m Map) InsertBool(k string, v bool) {
}
}

// InsertBytes adds the []byte Value to the map when the key does not exist.
// No action is applied to the map where the key already exists.
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
// across multiple attributes is forbidden.
// Deprecated: [0.51.0] Use InsertMBytes instead.
func (m Map) InsertBytes(k string, v []byte) {
if _, existing := m.Get(k); !existing {
*m.orig = append(*m.orig, newAttributeKeyValueBytes(k, v))
}
}

// InsertMBytes adds the []byte Value to the map when the key does not exist.
// No action is applied to the map where the key already exists.
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
Expand Down Expand Up @@ -790,17 +760,6 @@ func (m Map) UpdateBool(k string, v bool) {
}
}

// UpdateBytes updates an existing []byte Value with a value.
// No action is applied to the map where the key does not exist.
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
// across multiple attributes is forbidden.
// Deprecated: [0.51.0] Use UpdateMBytes instead.
func (m Map) UpdateBytes(k string, v []byte) {
if av, existing := m.Get(k); existing {
av.SetMBytesVal(v)
}
}

// UpdateMBytes updates an existing []byte Value with a value.
// No action is applied to the map where the key does not exist.
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
Expand Down Expand Up @@ -871,20 +830,6 @@ func (m Map) UpsertBool(k string, v bool) {
}
}

// UpsertBytes performs the Insert or Update action. The []byte Value is
// inserted to the map that did not originally have the key. The key/value is
// updated to the map where the key already existed.
// The caller must ensure the []byte passed in is not modified after the call is made, sharing the data
// across multiple attributes is forbidden.
// Deprecated: [0.51.0] Use UpsertMBytes instead.
func (m Map) UpsertBytes(k string, v []byte) {
if av, existing := m.Get(k); existing {
av.SetMBytesVal(v)
} else {
*m.orig = append(*m.orig, newAttributeKeyValueBytes(k, v))
}
}

// UpsertMBytes performs the Insert or Update action. The []byte Value is
// inserted to the map that did not originally have the key. The key/value is
// updated to the map where the key already existed.
Expand Down
18 changes: 9 additions & 9 deletions pdata/internal/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestAttributeValue(t *testing.T) {
bytesValue := []byte{1, 2, 3, 4}
v = NewValueBytes(bytesValue)
assert.EqualValues(t, ValueTypeBytes, v.Type())
assert.EqualValues(t, bytesValue, v.BytesVal())
assert.EqualValues(t, bytesValue, v.MBytesVal())
}

func TestAttributeValueType(t *testing.T) {
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestNilOrigSetAttributeValue(t *testing.T) {

av = NewValueEmpty()
av.SetBytesVal([]byte{1, 2, 3})
assert.Equal(t, []byte{1, 2, 3}, av.BytesVal())
assert.Equal(t, []byte{1, 2, 3}, av.MBytesVal())
}

func TestAttributeValueEqual(t *testing.T) {
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestMapWithEmpty(t *testing.T) {
val, exist = sm.Get("other_key_bytes")
assert.True(t, exist)
assert.EqualValues(t, ValueTypeBytes, val.Type())
assert.EqualValues(t, []byte{1, 2, 3}, val.BytesVal())
assert.EqualValues(t, []byte{1, 2, 3}, val.MBytesVal())

sm.Update("other_key", NewValueString("yet_another_value"))
val, exist = sm.Get("other_key")
Expand Down Expand Up @@ -452,7 +452,7 @@ func TestMapWithEmpty(t *testing.T) {
val, exist = sm.Get("other_key_bytes")
assert.True(t, exist)
assert.EqualValues(t, ValueTypeBytes, val.Type())
assert.EqualValues(t, []byte{4, 5, 6}, val.BytesVal())
assert.EqualValues(t, []byte{4, 5, 6}, val.MBytesVal())

sm.Upsert("other_key", NewValueString("other_value"))
val, exist = sm.Get("other_key")
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestMapWithEmpty(t *testing.T) {
val, exist = sm.Get("other_key_bytes")
assert.True(t, exist)
assert.EqualValues(t, ValueTypeBytes, val.Type())
assert.EqualValues(t, []byte{7, 8, 9}, val.BytesVal())
assert.EqualValues(t, []byte{7, 8, 9}, val.MBytesVal())

sm.Upsert("yet_another_key", NewValueString("yet_another_value"))
val, exist = sm.Get("yet_another_key")
Expand Down Expand Up @@ -524,7 +524,7 @@ func TestMapWithEmpty(t *testing.T) {
val, exist = sm.Get("yet_another_key_bytes")
assert.True(t, exist)
assert.EqualValues(t, ValueTypeBytes, val.Type())
assert.EqualValues(t, []byte{1}, val.BytesVal())
assert.EqualValues(t, []byte{1}, val.MBytesVal())

assert.True(t, sm.Remove("other_key"))
assert.True(t, sm.Remove("other_key_string"))
Expand Down Expand Up @@ -669,10 +669,10 @@ func TestValueBytes_CopyTo(t *testing.T) {
orig.CopyTo(dest)
assert.Equal(t, orig, dest)

orig.BytesVal()[0] = 10
orig.MBytesVal()[0] = 10
assert.NotEqual(t, orig, dest)
assert.Equal(t, []byte{1, 2, 3}, dest.BytesVal())
assert.Equal(t, []byte{10, 2, 3}, orig.BytesVal())
assert.Equal(t, []byte{1, 2, 3}, dest.MBytesVal())
assert.Equal(t, []byte{10, 2, 3}, orig.MBytesVal())
}

func TestMap_Update(t *testing.T) {
Expand Down
36 changes: 0 additions & 36 deletions pdata/internal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,39 +284,3 @@ func (ot OptionalType) String() string {
}
return ""
}

// BucketCounts returns the bucketcounts associated with this HistogramDataPoint.
// Deprecated: [0.51.0] Use MBucketCounts instead.
func (ms HistogramDataPoint) BucketCounts() []uint64 {
return ms.orig.BucketCounts
}

// SetBucketCounts replaces the bucketcounts associated with this HistogramDataPoint.
// Deprecated: [0.51.0] Use SetMBucketCounts instead.
func (ms HistogramDataPoint) SetBucketCounts(v []uint64) {
ms.orig.BucketCounts = v
}

// ExplicitBounds returns the explicitbounds associated with this HistogramDataPoint.
// Deprecated: [0.51.0] Use MExplicitBounds instead.
func (ms HistogramDataPoint) ExplicitBounds() []float64 {
return ms.orig.ExplicitBounds
}

// SetExplicitBounds replaces the explicitbounds associated with this HistogramDataPoint.
// Deprecated: [0.51.0] Use SetMExplicitBounds instead.
func (ms HistogramDataPoint) SetExplicitBounds(v []float64) {
ms.orig.ExplicitBounds = v
}

// BucketCounts returns the bucketcounts associated with this Buckets.
// Deprecated: [0.51.0] Use MBucketCounts instead.
func (ms Buckets) BucketCounts() []uint64 {
return ms.orig.BucketCounts
}

// SetBucketCounts replaces the bucketcounts associated with this Buckets.
// Deprecated: [0.51.0] Use SetMBucketCounts instead.
func (ms Buckets) SetBucketCounts(v []uint64) {
ms.orig.BucketCounts = v
}

0 comments on commit cd13d54

Please sign in to comment.