Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pdata] Create real copy of Value with ValueTypeBytes type #5267

Merged
merged 1 commit into from
Apr 27, 2022
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
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