Skip to content

Commit

Permalink
Merge branch 'main' into add-primitive-type-set-len
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Sep 15, 2022
2 parents 9f5c741 + e73963d commit cd3e8de
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 39 deletions.
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### 🛑 Breaking changes 🛑

- Delete deprecated `p[metric|log|trace].MarshalerSizer` interfaces (#6083)

### 💡 Enhancements 💡

- Add AppendEmpty and EnsureCapacity method to primitive pdata slices (#6060)
Expand Down Expand Up @@ -43,6 +47,12 @@
- Deprecate `pcommon.New[Slice|Map]FromRaw` functions in favor of `New[Slice|Map]().FromRaw` (#6045)
- Deprecate `pcommon.Map.Insert*` methods (#6051)
- Deprecate `pcommon.Map.Upsert*` methods in favor of `pcommon.Map.Put*` (#6064)
- Deprecate `ptrace.TraceState` in favor of `pcommon.TraceState`. (#6052)
- `ptrace.Span.TraceState` in favor of `ptrace.Span.TraceStateStruct().AsRaw()`
- `ptrace.Span.SetTraceState` in favor of `ptrace.Span.TraceStateStruct().FromRaw`
- `ptrace.SpanLink.TraceState` in favor of `ptrace.SpanLink.TraceStateStruct().AsRaw()`
- `ptrace.SpanLink.SetTraceState` in favor of `ptrace.SpanLink.TraceStateStruct().FromRaw`
- `TraceStateStruct` is a temporary name that will be replaced back to `TraceState` in the next release.

### 💡 Enhancements 💡

Expand Down Expand Up @@ -102,12 +112,6 @@
- `SummaryDataPoint.Flags` -> `SummaryDataPoint.FlagsImmutable`
- `MetricDataPointFlags` -> `MetricDataPointFlagsImmutable`
- `NewMetricDataPointFlags` -> `MetricDataPointFlagsImmutable`
- Deprecate `ptrace.TraceState` in favor of `pcommon.TraceState`. (#6052)
- `ptrace.Span.TraceState` in favor of `ptrace.Span.TraceStateStruct().AsRaw()`
- `ptrace.Span.SetTraceState` in favor of `ptrace.Span.TraceStateStruct().FromRaw`
- `ptrace.SpanLink.TraceState` in favor of `ptrace.SpanLink.TraceStateStruct().AsRaw()`
- `ptrace.SpanLink.SetTraceState` in favor of `ptrace.SpanLink.TraceStateStruct().FromRaw`
- `TraceStateStruct` is a temporary name that will be replaced back to `TraceState` in the next release.

### 💡 Enhancements 💡

Expand Down
30 changes: 13 additions & 17 deletions pdata/pcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,15 @@ func (v Value) SetEmptySliceVal() Slice {
return newSlice(&av.ArrayValue.Values)
}

// copyTo copies the value to Value. Will panic if dest is nil.
func (v Value) copyTo(dest *otlpcommon.AnyValue) {
// CopyTo copies the attribute to a destination.
func (v Value) CopyTo(dest Value) {
destOrig := dest.getOrig()
switch ov := v.getOrig().Value.(type) {
case *otlpcommon.AnyValue_KvlistValue:
kv, ok := dest.Value.(*otlpcommon.AnyValue_KvlistValue)
kv, ok := destOrig.Value.(*otlpcommon.AnyValue_KvlistValue)
if !ok {
kv = &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}
dest.Value = kv
destOrig.Value = kv
}
if ov.KvlistValue == nil {
kv.KvlistValue = nil
Expand All @@ -348,10 +349,10 @@ func (v Value) copyTo(dest *otlpcommon.AnyValue) {
// Deep copy to dest.
newMap(&ov.KvlistValue.Values).CopyTo(newMap(&kv.KvlistValue.Values))
case *otlpcommon.AnyValue_ArrayValue:
av, ok := dest.Value.(*otlpcommon.AnyValue_ArrayValue)
av, ok := destOrig.Value.(*otlpcommon.AnyValue_ArrayValue)
if !ok {
av = &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}
dest.Value = av
destOrig.Value = av
}
if ov.ArrayValue == nil {
av.ArrayValue = nil
Expand All @@ -360,24 +361,19 @@ 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)
bv, ok := destOrig.Value.(*otlpcommon.AnyValue_BytesValue)
if !ok {
bv = &otlpcommon.AnyValue_BytesValue{}
dest.Value = bv
destOrig.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.getOrig().Value
destOrig.Value = ov
}
}

// CopyTo copies the attribute to a destination.
func (v Value) CopyTo(dest Value) {
v.copyTo(dest.getOrig())
}

// Equal checks for equality, it returns true if the objects are equal otherwise false.
func (v Value) Equal(av Value) bool {
if v.getOrig() == av.getOrig() {
Expand Down Expand Up @@ -565,7 +561,7 @@ func newAttributeKeyValueNull(k string) otlpcommon.KeyValue {

func newAttributeKeyValue(k string, av Value) otlpcommon.KeyValue {
orig := otlpcommon.KeyValue{Key: k}
av.copyTo(&orig.Value)
av.CopyTo(newValue(&orig.Value))
return orig
}

Expand Down Expand Up @@ -1004,7 +1000,7 @@ func (m Map) CopyTo(dest Map) {
akv := &(*m.getOrig())[i]
destAkv := &(*dest.getOrig())[i]
destAkv.Key = akv.Key
newValue(&akv.Value).copyTo(&destAkv.Value)
newValue(&akv.Value).CopyTo(newValue(&destAkv.Value))
}
return
}
Expand All @@ -1014,7 +1010,7 @@ func (m Map) CopyTo(dest Map) {
for i := range *m.getOrig() {
akv := &(*m.getOrig())[i]
origs[i].Key = akv.Key
newValue(&akv.Value).copyTo(&origs[i].Value)
newValue(&akv.Value).CopyTo(newValue(&origs[i].Value))
}
*dest.getOrig() = origs
}
Expand Down
12 changes: 5 additions & 7 deletions pdata/pcommon/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ func TestValue_CopyTo(t *testing.T) {
orig = &otlpcommon.AnyValue{}
newValue(orig).CopyTo(dest)
assert.Nil(t, dest.getOrig().Value)

av := NewValueEmpty()
destVal := otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{}}
av.CopyTo(newValue(&destVal))
assert.EqualValues(t, nil, destVal.Value)
}

func TestMap_CopyTo(t *testing.T) {
Expand All @@ -761,13 +766,6 @@ func TestMap_CopyTo(t *testing.T) {
assert.EqualValues(t, Map(internal.GenerateTestMap()), dest)
}

func TestValue_copyTo(t *testing.T) {
av := NewValueEmpty()
destVal := otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{}}
av.copyTo(&destVal)
assert.EqualValues(t, nil, destVal.Value)
}

func TestMap_EnsureCapacity_Zero(t *testing.T) {
am := NewMap()
am.EnsureCapacity(0)
Expand Down
3 changes: 0 additions & 3 deletions pdata/plog/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

package plog // import "go.opentelemetry.io/collector/pdata/plog"

// Deprecated: [v0.60.0] use MarshalSizer.
type MarshalerSizer = MarshalSizer

// MarshalSizer is the interface that groups the basic Marshal and Size methods
type MarshalSizer interface {
Marshaler
Expand Down
3 changes: 0 additions & 3 deletions pdata/pmetric/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

package pmetric // import "go.opentelemetry.io/collector/pdata/pmetric"

// Deprecated: [v0.60.0] use MarshalSizer.
type MarshalerSizer = MarshalSizer

// MarshalSizer is the interface that groups the basic Marshal and Size methods
type MarshalSizer interface {
Marshaler
Expand Down
3 changes: 0 additions & 3 deletions pdata/ptrace/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

package ptrace // import "go.opentelemetry.io/collector/pdata/ptrace"

// Deprecated: [v0.60.0] use MarshalSizer.
type MarshalerSizer = MarshalSizer

// MarshalSizer is the interface that groups the basic Marshal and Size methods
type MarshalSizer interface {
Marshaler
Expand Down

0 comments on commit cd3e8de

Please sign in to comment.