Skip to content

Commit

Permalink
[pdata] Create real copy of Value with ValueTypeBytes type (#5267)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Apr 27, 2022
1 parent b80d754 commit f38e3e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
### 🧰 Bug fixes 🧰
- Fix translation from otlp.Request to pdata representation, changes to the returned pdata not all reflected to the otlp.Request (#5197)
- `exporterhelper` now properly consumes any remaining items on stop (#5203)
- `pdata`: Fix copying of `Value` with `ValueTypeBytes` type (#5267)

## v0.49.0 Beta

Expand Down
8 changes: 8 additions & 0 deletions pdata/internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ func (v Value) copyTo(dest *otlpcommon.AnyValue) {
}
// Deep copy to dest.
newSlice(&ov.ArrayValue.Values).CopyTo(newSlice(&av.ArrayValue.Values))
case *otlpcommon.AnyValue_BytesValue:
bv, ok := dest.Value.(*otlpcommon.AnyValue_BytesValue)
if !ok {
bv = &otlpcommon.AnyValue_BytesValue{}
dest.Value = bv
}
bv.BytesValue = make([]byte, len(ov.BytesValue))
copy(bv.BytesValue, ov.BytesValue)
default:
// Primitive immutable type, no need for deep copy.
dest.Value = v.orig.Value
Expand Down
12 changes: 12 additions & 0 deletions pdata/internal/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,18 @@ func TestAttributeValue_copyTo(t *testing.T) {
assert.EqualValues(t, nil, destVal.Value)
}

func TestValueBytes_CopyTo(t *testing.T) {
orig := NewValueBytes([]byte{1, 2, 3})
dest := NewValueEmpty()
orig.CopyTo(dest)
assert.Equal(t, orig, dest)

orig.BytesVal()[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())
}

func TestMap_Update(t *testing.T) {
origWithNil := []otlpcommon.KeyValue{
{
Expand Down

0 comments on commit f38e3e5

Please sign in to comment.