From 2234e86838d23a0717d91d9e982ac6fdde5d8acb Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 13 Sep 2022 16:46:44 -0700 Subject: [PATCH] [pdata] Rename Map.Upsert* methods to Map.Put* --- CHANGELOG.md | 3 +- .../internal/persistent_queue_test.go | 18 +-- .../internal/otlptext/databuffer_test.go | 4 +- exporter/otlphttpexporter/otlp_test.go | 8 +- internal/testdata/common.go | 16 +-- internal/testdata/log.go | 8 +- pdata/pcommon/common.go | 87 +++++++++---- pdata/pcommon/common_test.go | 114 +++++++++--------- pdata/plog/json_test.go | 4 +- pdata/pmetric/json_test.go | 82 ++++++------- pdata/pmetric/metrics_test.go | 17 +-- pdata/ptrace/json_test.go | 44 +++---- receiver/otlpreceiver/otlp_test.go | 6 +- 13 files changed, 225 insertions(+), 186 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f3d97f7bc1..b71a766b099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,10 +36,11 @@ - `pcommon.ImmutableFloat64Slice` is deprecated in favor of `pcommon.Float64Slice` - `pcommon.ImmutableUInt64Slice` is deprecated in favor of `pcommon.UInt64Slice` - Temporarily deprecate `pcommon.NewValueBytes` that will be replaced with `pcommon.NewValueBytesEmpty` in 0.60.0 - - Deprecate `pcommon.Map.UpsertBytes` in favor of `pcommon.Map.UpsertEmptyBytes` + - Deprecate `pcommon.Map.UpsertBytes` in favor of `pcommon.Map.PutEmptyBytes` - Deprecate `pcommon.Value.SetBytesVal` in favor of `pcommon.Value.SetEmptyBytesVal` - 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*` (#6061) ### 💡 Enhancements 💡 diff --git a/exporter/exporterhelper/internal/persistent_queue_test.go b/exporter/exporterhelper/internal/persistent_queue_test.go index 4716529446c..ad9546eb48f 100644 --- a/exporter/exporterhelper/internal/persistent_queue_test.go +++ b/exporter/exporterhelper/internal/persistent_queue_test.go @@ -164,9 +164,9 @@ func TestPersistentQueue_ConsumersProducers(t *testing.T) { func newTraces(numTraces int, numSpans int) ptrace.Traces { traces := ptrace.NewTraces() batch := traces.ResourceSpans().AppendEmpty() - batch.Resource().Attributes().UpsertString("resource-attr", "some-resource") - batch.Resource().Attributes().UpsertInt("num-traces", int64(numTraces)) - batch.Resource().Attributes().UpsertInt("num-spans", int64(numSpans)) + batch.Resource().Attributes().PutString("resource-attr", "some-resource") + batch.Resource().Attributes().PutInt("num-traces", int64(numTraces)) + batch.Resource().Attributes().PutInt("num-spans", int64(numSpans)) for i := 0; i < numTraces; i++ { traceID := pcommon.TraceID([16]byte{1, 2, 3, byte(i)}) @@ -176,12 +176,12 @@ func newTraces(numTraces int, numSpans int) ptrace.Traces { span.SetTraceID(traceID) span.SetSpanID([8]byte{1, 2, 3, byte(j)}) span.SetName("should-not-be-changed") - span.Attributes().UpsertInt("int-attribute", int64(j)) - span.Attributes().UpsertString("str-attribute-1", "foobar") - span.Attributes().UpsertString("str-attribute-2", "fdslafjasdk12312312jkl") - span.Attributes().UpsertString("str-attribute-3", "AbcDefGeKKjkfdsafasdfsdasdf") - span.Attributes().UpsertString("str-attribute-4", "xxxxxx") - span.Attributes().UpsertString("str-attribute-5", "abcdef") + span.Attributes().PutInt("int-attribute", int64(j)) + span.Attributes().PutString("str-attribute-1", "foobar") + span.Attributes().PutString("str-attribute-2", "fdslafjasdk12312312jkl") + span.Attributes().PutString("str-attribute-3", "AbcDefGeKKjkfdsafasdfsdasdf") + span.Attributes().PutString("str-attribute-4", "xxxxxx") + span.Attributes().PutString("str-attribute-5", "abcdef") } } diff --git a/exporter/loggingexporter/internal/otlptext/databuffer_test.go b/exporter/loggingexporter/internal/otlptext/databuffer_test.go index d6d08d2f77a..7b5837a99a3 100644 --- a/exporter/loggingexporter/internal/otlptext/databuffer_test.go +++ b/exporter/loggingexporter/internal/otlptext/databuffer_test.go @@ -41,9 +41,9 @@ func TestNestedArraySerializesCorrectly(t *testing.T) { func TestNestedMapSerializesCorrectly(t *testing.T) { ava := pcommon.NewValueMap() av := ava.MapVal() - av.UpsertString("foo", "test") + av.PutString("foo", "test") - av.UpsertEmptyMap("zoo").UpsertInt("bar", 13) + av.PutEmptyMap("zoo").PutInt("bar", 13) expected := `{ -> foo: STRING(test) diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index d1d9e55c37a..be7897f3998 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -269,8 +269,8 @@ func TestIssue_4221(t *testing.T) { md := ptrace.NewTraces() rms := md.ResourceSpans().AppendEmpty() - rms.Resource().Attributes().UpsertString("service.name", "uop.stage-eu-1") - rms.Resource().Attributes().UpsertString("outsystems.module.version", "903386") + rms.Resource().Attributes().PutString("service.name", "uop.stage-eu-1") + rms.Resource().Attributes().PutString("outsystems.module.version", "903386") ils := rms.ScopeSpans().AppendEmpty() ils.Scope().SetName("uop_canaries") ils.Scope().SetVersion("1") @@ -291,8 +291,8 @@ func TestIssue_4221(t *testing.T) { assert.Equal(t, "e5513c32795c41b9", span.SpanID().HexString()) span.SetEndTimestamp(1634684637873000000) - span.Attributes().UpsertInt("span_index", 3) - span.Attributes().UpsertString("code.function", "myFunction36") + span.Attributes().PutInt("span_index", 3) + span.Attributes().PutString("code.function", "myFunction36") span.SetStartTimestamp(1634684637873000000) assert.NoError(t, exp.ConsumeTraces(context.Background(), md)) diff --git a/internal/testdata/common.go b/internal/testdata/common.go index 55327c9546f..3de15515654 100644 --- a/internal/testdata/common.go +++ b/internal/testdata/common.go @@ -25,40 +25,40 @@ const ( func initResourceAttributes1(dest pcommon.Map) { dest.Clear() - dest.UpsertString("resource-attr", "resource-attr-val-1") + dest.PutString("resource-attr", "resource-attr-val-1") } func initSpanEventAttributes(dest pcommon.Map) { dest.Clear() - dest.UpsertString("span-event-attr", "span-event-attr-val") + dest.PutString("span-event-attr", "span-event-attr-val") } func initSpanLinkAttributes(dest pcommon.Map) { dest.Clear() - dest.UpsertString("span-link-attr", "span-link-attr-val") + dest.PutString("span-link-attr", "span-link-attr-val") } func initMetricExemplarAttributes(dest pcommon.Map) { dest.Clear() - dest.UpsertString("exemplar-attachment", "exemplar-attachment-value") + dest.PutString("exemplar-attachment", "exemplar-attachment-value") } func initMetricAttributes1(dest pcommon.Map) { dest.Clear() - dest.UpsertString("label-1", "label-value-1") + dest.PutString("label-1", "label-value-1") } func initMetricAttributes12(dest pcommon.Map) { initMetricAttributes1(dest) - dest.UpsertString(testLabelKey2, testLabelValue2) + dest.PutString(testLabelKey2, testLabelValue2) } func initMetricAttributes13(dest pcommon.Map) { initMetricAttributes1(dest) - dest.UpsertString("label-3", "label-value-3") + dest.PutString("label-3", "label-value-3") } func initMetricAttributes2(dest pcommon.Map) { dest.Clear() - dest.UpsertString(testLabelKey2, testLabelValue2) + dest.PutString(testLabelKey2, testLabelValue2) } diff --git a/internal/testdata/log.go b/internal/testdata/log.go index a87c9dd84f0..3379cac89db 100644 --- a/internal/testdata/log.go +++ b/internal/testdata/log.go @@ -50,8 +50,8 @@ func fillLogOne(log plog.LogRecord) { log.SetTraceID([16]byte{0x08, 0x04, 0x02, 0x01}) attrs := log.Attributes() - attrs.UpsertString("app", "server") - attrs.UpsertInt("instance_num", 1) + attrs.PutString("app", "server") + attrs.PutInt("instance_num", 1) log.Body().SetStringVal("This is a log message") } @@ -63,8 +63,8 @@ func fillLogTwo(log plog.LogRecord) { log.SetSeverityText("Info") attrs := log.Attributes() - attrs.UpsertString("customer", "acme") - attrs.UpsertString("env", "dev") + attrs.PutString("customer", "acme") + attrs.PutString("env", "dev") log.Body().SetStringVal("something happened") } diff --git a/pdata/pcommon/common.go b/pdata/pcommon/common.go index 2be3024b32a..38bbc712c5f 100644 --- a/pdata/pcommon/common.go +++ b/pdata/pcommon/common.go @@ -681,7 +681,7 @@ func (m Map) RemoveIf(f func(string, Value) bool) { // // _, ok := m.Get(k) // if !ok { -// v.CopyTo(m.UpsertEmpty(k)) // or use m.UpsertEmpty for complex types. +// v.CopyTo(m.PutEmpty(k)) // or use m.PutEmpty for complex types. // } func (m Map) Insert(k string, v Value) { if _, existing := m.Get(k); !existing { @@ -693,11 +693,11 @@ func (m Map) Insert(k string, v Value) { // No action is applied to the map where the key already exists. // // Deprecated: [0.60.0] Replace it with the following function calls if you need to make sure that existing value is -// not overridden, otherwise just use UpsertString. +// not overridden, otherwise just use PutString. // // _, ok := m.Get(k) // if !ok { -// m.UpsertString(k) +// m.PutString(k) // } func (m Map) InsertString(k string, v string) { if _, existing := m.Get(k); !existing { @@ -709,11 +709,11 @@ func (m Map) InsertString(k string, v string) { // No action is applied to the map where the key already exists. // // Deprecated: [0.60.0] Replace it with the following function calls if you need to make sure that existing value is -// not overridden, otherwise just use UpsertInt. +// not overridden, otherwise just use PutInt. // // _, ok := m.Get(k) // if !ok { -// m.UpsertInt(k) +// m.PutInt(k) // } func (m Map) InsertInt(k string, v int64) { if _, existing := m.Get(k); !existing { @@ -725,11 +725,11 @@ func (m Map) InsertInt(k string, v int64) { // No action is applied to the map where the key already exists. // // Deprecated: [0.60.0] Replace it with the following function calls if you need to make sure that existing value is -// not overridden, otherwise just use UpsertDouble. +// not overridden, otherwise just use PutDouble. // // _, ok := m.Get(k) // if !ok { -// m.UpsertDouble(k) +// m.PutDouble(k) // } func (m Map) InsertDouble(k string, v float64) { if _, existing := m.Get(k); !existing { @@ -741,11 +741,11 @@ func (m Map) InsertDouble(k string, v float64) { // No action is applied to the map where the key already exists. // // Deprecated: [0.60.0] Replace it with the following function calls if you need to make sure that existing value is -// not overridden, otherwise just use UpsertBool. +// not overridden, otherwise just use PutBool. // // _, ok := m.Get(k) // if !ok { -// m.UpsertBool(k) +// m.PutBool(k) // } func (m Map) InsertBool(k string, v bool) { if _, existing := m.Get(k); !existing { @@ -822,9 +822,9 @@ func (m Map) UpdateBytes(k string, v ImmutableByteSlice) { } } -// UpsertEmpty inserts or updates an empty value to the map under given key +// PutEmpty inserts or updates an empty value to the map under given key // and return the updated/inserted value. -func (m Map) UpsertEmpty(k string) Value { +func (m Map) PutEmpty(k string) Value { if av, existing := m.Get(k); existing { av.getOrig().Value = nil return newValue(av.getOrig()) @@ -833,10 +833,10 @@ func (m Map) UpsertEmpty(k string) Value { return newValue(&(*m.getOrig())[len(*m.getOrig())-1].Value) } -// UpsertString performs the Insert or Update action. The Value is +// PutString performs the Insert or Update action. The 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. -func (m Map) UpsertString(k string, v string) { +func (m Map) PutString(k string, v string) { if av, existing := m.Get(k); existing { av.SetStringVal(v) } else { @@ -844,10 +844,10 @@ func (m Map) UpsertString(k string, v string) { } } -// UpsertInt performs the Insert or Update action. The int Value is +// PutInt performs the Insert or Update action. The int 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. -func (m Map) UpsertInt(k string, v int64) { +func (m Map) PutInt(k string, v int64) { if av, existing := m.Get(k); existing { av.SetIntVal(v) } else { @@ -855,10 +855,10 @@ func (m Map) UpsertInt(k string, v int64) { } } -// UpsertDouble performs the Insert or Update action. The double Value is +// PutDouble performs the Insert or Update action. The double 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. -func (m Map) UpsertDouble(k string, v float64) { +func (m Map) PutDouble(k string, v float64) { if av, existing := m.Get(k); existing { av.SetDoubleVal(v) } else { @@ -866,10 +866,10 @@ func (m Map) UpsertDouble(k string, v float64) { } } -// UpsertBool performs the Insert or Update action. The bool Value is +// PutBool performs the Insert or Update action. The bool 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. -func (m Map) UpsertBool(k string, v bool) { +func (m Map) PutBool(k string, v bool) { if av, existing := m.Get(k); existing { av.SetBoolVal(v) } else { @@ -880,7 +880,7 @@ func (m Map) UpsertBool(k string, v bool) { // UpsertBytes performs the Insert or Update action. The ImmutableByteSlice 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. -// Deprecated: [0.60.0] Use UpsertEmptyBytes().FromRaw(v) instead. +// Deprecated: [0.60.0] Use PutEmptyBytes().FromRaw(v) instead. func (m Map) UpsertBytes(k string, v ByteSlice) { if av, existing := m.Get(k); existing { av.SetBytesVal(v) @@ -889,8 +889,8 @@ func (m Map) UpsertBytes(k string, v ByteSlice) { } } -// UpsertEmptyBytes inserts or updates an empty byte slice under given key and returns it. -func (m Map) UpsertEmptyBytes(k string) ByteSlice { +// PutEmptyBytes inserts or updates an empty byte slice under given key and returns it. +func (m Map) PutEmptyBytes(k string) ByteSlice { bv := otlpcommon.AnyValue_BytesValue{} if av, existing := m.Get(k); existing { av.getOrig().Value = &bv @@ -900,8 +900,8 @@ func (m Map) UpsertEmptyBytes(k string) ByteSlice { return ByteSlice(internal.NewByteSlice(&bv.BytesValue)) } -// UpsertEmptyMap inserts or updates an empty map under given key and returns it. -func (m Map) UpsertEmptyMap(k string) Map { +// PutEmptyMap inserts or updates an empty map under given key and returns it. +func (m Map) PutEmptyMap(k string) Map { kvl := otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{Values: []otlpcommon.KeyValue(nil)}} if av, existing := m.Get(k); existing { av.getOrig().Value = &kvl @@ -911,8 +911,8 @@ func (m Map) UpsertEmptyMap(k string) Map { return Map(internal.NewMap(&kvl.KvlistValue.Values)) } -// UpsertEmptySlice inserts or updates an empty clice under given key and returns it. -func (m Map) UpsertEmptySlice(k string) Slice { +// PutEmptySlice inserts or updates an empty slice under given key and returns it. +func (m Map) PutEmptySlice(k string) Slice { vl := otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{Values: []otlpcommon.AnyValue(nil)}} if av, existing := m.Get(k); existing { av.getOrig().Value = &vl @@ -922,6 +922,41 @@ func (m Map) UpsertEmptySlice(k string) Slice { return Slice(internal.NewSlice(&vl.ArrayValue.Values)) } +// Deprecated: [0.60.0] Use PutEmpty instead. +func (m Map) UpsertEmpty(k string) Value { + return m.PutEmpty(k) +} + +// Deprecated: [0.60.0] Use PutString instead. +func (m Map) UpsertString(k string, v string) { + m.PutString(k, v) +} + +// Deprecated: [0.60.0] Use func PutInt instead. +func (m Map) UpsertInt(k string, v int64) { + m.PutInt(k, v) +} + +// Deprecated: [0.60.0] Use PutDouble instead. +func (m Map) UpsertDouble(k string, v float64) { + m.PutDouble(k, v) +} + +// Deprecated: [0.60.0] Use func (k instead. +func (m Map) UpsertBool(k string, v bool) { + m.PutBool(k, v) +} + +// Deprecated: [0.60.0] Use PutEmptyMap instead. +func (m Map) UpsertEmptyMap(k string) Map { + return m.PutEmptyMap(k) +} + +// Deprecated: [0.60.0] Use PutEmptySlice instead. +func (m Map) UpsertEmptySlice(k string) Slice { + return m.PutEmptySlice(k) +} + // Sort sorts the entries in the Map so two instances can be compared. // Returns the same instance to allow nicer code like: // diff --git a/pdata/pcommon/common_test.go b/pdata/pcommon/common_test.go index dd6bf140298..4899176df5e 100644 --- a/pdata/pcommon/common_test.go +++ b/pdata/pcommon/common_test.go @@ -85,7 +85,7 @@ func TestValueMap(t *testing.T) { assert.Equal(t, 0, m2.MapVal().Len()) // Modify the source map that was inserted. - m2.MapVal().UpsertString("key_in_child", "somestr") + m2.MapVal().PutString("key_in_child", "somestr") assert.Equal(t, 1, m2.MapVal().Len()) got, exists = m2.MapVal().Get("key_in_child") assert.True(t, exists) @@ -249,12 +249,12 @@ func TestValueEqual(t *testing.T) { assert.False(t, av1.Equal(av2)) av1 = NewValueMap() - av1.MapVal().UpsertString("foo", "bar") + av1.MapVal().PutString("foo", "bar") assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) av2 = NewValueMap() - av2.MapVal().UpsertString("foo", "bar") + av2.MapVal().PutString("foo", "bar") assert.True(t, av1.Equal(av2)) fooVal, ok := av2.MapVal().Get("foo") @@ -318,25 +318,25 @@ func TestMap(t *testing.T) { updateMapBytes.UpdateBytes("k", NewImmutableByteSlice([]byte{1, 2, 3})) assert.EqualValues(t, NewMap(), updateMapBytes) - upsertMapString := NewMap() - upsertMapString.UpsertString("k", "v") - assert.EqualValues(t, Map(internal.GenerateTestMap()), upsertMapString) + putMapString := NewMap() + putMapString.PutString("k", "v") + assert.EqualValues(t, Map(internal.GenerateTestMap()), putMapString) - upsertMapInt := NewMap() - upsertMapInt.UpsertInt("k", 123) - assert.EqualValues(t, generateTestIntMap(), upsertMapInt) + putMapInt := NewMap() + putMapInt.PutInt("k", 123) + assert.EqualValues(t, generateTestIntMap(), putMapInt) - upsertMapDouble := NewMap() - upsertMapDouble.UpsertDouble("k", 12.3) - assert.EqualValues(t, generateTestDoubleMap(), upsertMapDouble) + putMapDouble := NewMap() + putMapDouble.PutDouble("k", 12.3) + assert.EqualValues(t, generateTestDoubleMap(), putMapDouble) - upsertMapBool := NewMap() - upsertMapBool.UpsertBool("k", true) - assert.EqualValues(t, generateTestBoolMap(), upsertMapBool) + putMapBool := NewMap() + putMapBool.PutBool("k", true) + assert.EqualValues(t, generateTestBoolMap(), putMapBool) - upsertMapBytes := NewMap() - upsertMapBytes.UpsertBytes("k", NewImmutableByteSlice([]byte{1, 2, 3, 4, 5})) - assert.EqualValues(t, generateTestBytesMap(), upsertMapBytes) + putMapBytes := NewMap() + putMapBytes.PutEmptyBytes("k").FromRaw([]byte{1, 2, 3, 4, 5}) + assert.EqualValues(t, generateTestBytesMap(), putMapBytes) removeMap := NewMap() assert.False(t, removeMap.Remove("k")) @@ -346,9 +346,9 @@ func TestMap(t *testing.T) { assert.EqualValues(t, NewMap(), NewMap().Sort()) } -func TestMapUpsertEmpty(t *testing.T) { +func TestMapPutEmpty(t *testing.T) { m := NewMap() - v := m.UpsertEmpty("k1") + v := m.PutEmpty("k1") assert.EqualValues(t, map[string]interface{}{ "k1": nil, }, m.AsRaw()) @@ -358,27 +358,27 @@ func TestMapUpsertEmpty(t *testing.T) { "k1": true, }, m.AsRaw()) - v = m.UpsertEmpty("k1") + v = m.PutEmpty("k1") v.SetIntVal(1) v2, ok := m.Get("k1") assert.True(t, ok) assert.Equal(t, int64(1), v2.IntVal()) } -func TestMapUpsertEmptyMap(t *testing.T) { +func TestMapPutEmptyMap(t *testing.T) { m := NewMap() - childMap := m.UpsertEmptyMap("k1") + childMap := m.PutEmptyMap("k1") assert.EqualValues(t, map[string]interface{}{ "k1": map[string]interface{}{}, }, m.AsRaw()) - childMap.UpsertEmptySlice("k2").AppendEmpty().SetStringVal("val") + childMap.PutEmptySlice("k2").AppendEmpty().SetStringVal("val") assert.EqualValues(t, map[string]interface{}{ "k1": map[string]interface{}{ "k2": []interface{}{"val"}, }, }, m.AsRaw()) - childMap.UpsertEmptyMap("k2").UpsertInt("k3", 1) + childMap.PutEmptyMap("k2").PutInt("k3", 1) assert.EqualValues(t, map[string]interface{}{ "k1": map[string]interface{}{ "k2": map[string]interface{}{"k3": int64(1)}, @@ -386,9 +386,9 @@ func TestMapUpsertEmptyMap(t *testing.T) { }, m.AsRaw()) } -func TestMapUpsertEmptySlice(t *testing.T) { +func TestMapPutEmptySlice(t *testing.T) { m := NewMap() - childSlice := m.UpsertEmptySlice("k") + childSlice := m.PutEmptySlice("k") assert.EqualValues(t, map[string]interface{}{ "k": []interface{}{}, }, m.AsRaw()) @@ -397,7 +397,7 @@ func TestMapUpsertEmptySlice(t *testing.T) { "k": []interface{}{1.1}, }, m.AsRaw()) - m.UpsertEmptySlice("k") + m.PutEmptySlice("k") assert.EqualValues(t, map[string]interface{}{ "k": []interface{}{}, }, m.AsRaw()) @@ -409,9 +409,9 @@ func TestMapUpsertEmptySlice(t *testing.T) { }, m.AsRaw()) } -func TestMapUpsertEmptyBytes(t *testing.T) { +func TestMapPutEmptyBytes(t *testing.T) { m := NewMap() - b := m.UpsertEmptyBytes("k") + b := m.PutEmptyBytes("k") bv, ok := m.Get("k") assert.True(t, ok) assert.Equal(t, []byte(nil), bv.BytesVal().AsRaw()) @@ -420,7 +420,7 @@ func TestMapUpsertEmptyBytes(t *testing.T) { assert.True(t, ok) assert.Equal(t, []byte{1, 2, 3}, bv.BytesVal().AsRaw()) - m.UpsertEmptyBytes("k") + m.PutEmptyBytes("k") bv, ok = m.Get("k") assert.True(t, ok) assert.Equal(t, []byte(nil), bv.BytesVal().AsRaw()) @@ -519,61 +519,61 @@ func TestMapWithEmpty(t *testing.T) { assert.EqualValues(t, ValueTypeBytes, val.Type()) assert.EqualValues(t, []byte{4, 5, 6}, val.BytesVal().AsRaw()) - sm.UpsertString("other_key_string", "other_value") + sm.PutString("other_key_string", "other_value") val, exist = sm.Get("other_key") assert.True(t, exist) assert.EqualValues(t, ValueTypeString, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) - sm.UpsertInt("other_key_int", 123) + sm.PutInt("other_key_int", 123) val, exist = sm.Get("other_key_int") assert.True(t, exist) assert.EqualValues(t, ValueTypeInt, val.Type()) assert.EqualValues(t, 123, val.IntVal()) - sm.UpsertDouble("other_key_double", 1.23) + sm.PutDouble("other_key_double", 1.23) val, exist = sm.Get("other_key_double") assert.True(t, exist) assert.EqualValues(t, ValueTypeDouble, val.Type()) assert.EqualValues(t, 1.23, val.DoubleVal()) - sm.UpsertBool("other_key_bool", true) + sm.PutBool("other_key_bool", true) val, exist = sm.Get("other_key_bool") assert.True(t, exist) assert.EqualValues(t, ValueTypeBool, val.Type()) assert.True(t, val.BoolVal()) - sm.UpsertBytes("other_key_bytes", NewImmutableByteSlice([]byte{7, 8, 9})) + sm.PutEmptyBytes("other_key_bytes").FromRaw([]byte{7, 8, 9}) 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().AsRaw()) - sm.UpsertString("yet_another_key_string", "yet_another_value") + sm.PutString("yet_another_key_string", "yet_another_value") val, exist = sm.Get("yet_another_key_string") assert.True(t, exist) assert.EqualValues(t, ValueTypeString, val.Type()) assert.EqualValues(t, "yet_another_value", val.StringVal()) - sm.UpsertInt("yet_another_key_int", 456) + sm.PutInt("yet_another_key_int", 456) val, exist = sm.Get("yet_another_key_int") assert.True(t, exist) assert.EqualValues(t, ValueTypeInt, val.Type()) assert.EqualValues(t, 456, val.IntVal()) - sm.UpsertDouble("yet_another_key_double", 4.56) + sm.PutDouble("yet_another_key_double", 4.56) val, exist = sm.Get("yet_another_key_double") assert.True(t, exist) assert.EqualValues(t, ValueTypeDouble, val.Type()) assert.EqualValues(t, 4.56, val.DoubleVal()) - sm.UpsertBool("yet_another_key_bool", false) + sm.PutBool("yet_another_key_bool", false) val, exist = sm.Get("yet_another_key_bool") assert.True(t, exist) assert.EqualValues(t, ValueTypeBool, val.Type()) assert.False(t, val.BoolVal()) - sm.UpsertBytes("yet_another_key_bytes", NewImmutableByteSlice([]byte{1})) + sm.PutEmptyBytes("yet_another_key_bytes").FromRaw([]byte{1}) val, exist = sm.Get("yet_another_key_bytes") assert.True(t, exist) assert.EqualValues(t, ValueTypeBytes, val.Type()) @@ -674,12 +674,12 @@ func TestMap_FromRaw(t *testing.T) { am := NewMap() am.FromRaw(map[string]interface{}{}) assert.Equal(t, 0, am.Len()) - am.UpsertEmpty("k") + am.PutEmpty("k") assert.Equal(t, 1, am.Len()) am.FromRaw(nil) assert.Equal(t, 0, am.Len()) - am.UpsertEmpty("k") + am.PutEmpty("k") assert.Equal(t, 1, am.Len()) am.FromRaw(map[string]interface{}{ @@ -801,11 +801,11 @@ func TestMap_Clear(t *testing.T) { func TestMap_RemoveIf(t *testing.T) { am := NewMap() - am.UpsertString("k_string", "123") - am.UpsertInt("k_int", int64(123)) - am.UpsertDouble("k_double", float64(1.23)) - am.UpsertBool("k_bool", true) - am.UpsertEmpty("k_empty") + am.PutString("k_string", "123") + am.PutInt("k_int", int64(123)) + am.PutDouble("k_double", float64(1.23)) + am.PutBool("k_bool", true) + am.PutEmpty("k_empty") assert.Equal(t, 5, am.Len()) @@ -1217,17 +1217,17 @@ func TestNewValueFromRaw(t *testing.T) { func generateTestValueMap() Value { ret := NewValueMap() attrMap := ret.MapVal() - attrMap.UpsertString("strKey", "strVal") - attrMap.UpsertInt("intKey", 7) - attrMap.UpsertDouble("floatKey", 18.6) - attrMap.UpsertBool("boolKey", false) - attrMap.UpsertEmpty("nullKey") + attrMap.PutString("strKey", "strVal") + attrMap.PutInt("intKey", 7) + attrMap.PutDouble("floatKey", 18.6) + attrMap.PutBool("boolKey", false) + attrMap.PutEmpty("nullKey") - m := attrMap.UpsertEmptyMap("mapKey") - m.UpsertString("keyOne", "valOne") - m.UpsertString("keyTwo", "valTwo") + m := attrMap.PutEmptyMap("mapKey") + m.PutString("keyOne", "valOne") + m.PutString("keyTwo", "valTwo") - s := attrMap.UpsertEmptySlice("arrKey") + s := attrMap.PutEmptySlice("arrKey") s.AppendEmpty().SetStringVal("strOne") s.AppendEmpty().SetStringVal("strTwo") diff --git a/pdata/plog/json_test.go b/pdata/plog/json_test.go index 1bd83a2bad8..9212347a21c 100644 --- a/pdata/plog/json_test.go +++ b/pdata/plog/json_test.go @@ -28,7 +28,7 @@ import ( var logsOTLP = func() Logs { ld := NewLogs() rl := ld.ResourceLogs().AppendEmpty() - rl.Resource().Attributes().UpsertString("host.name", "testHost") + rl.Resource().Attributes().PutString("host.name", "testHost") rl.Resource().SetDroppedAttributesCount(1) rl.SetSchemaUrl("testSchemaURL") il := rl.ScopeLogs().AppendEmpty() @@ -49,7 +49,7 @@ var logsOTLP = func() Logs { t := pcommon.NewTimestampFromTime(time.Now()) lg.SetTimestamp(t) lg.SetObservedTimestamp(t) - lg.Attributes().UpsertString("sdkVersion", "1.0.1") + lg.Attributes().PutString("sdkVersion", "1.0.1") return ld } diff --git a/pdata/pmetric/json_test.go b/pdata/pmetric/json_test.go index 4beff7306cb..92d9f10c29a 100644 --- a/pdata/pmetric/json_test.go +++ b/pdata/pmetric/json_test.go @@ -27,7 +27,7 @@ import ( var metricsOTLP = func() Metrics { md := NewMetrics() rm := md.ResourceMetrics().AppendEmpty() - rm.Resource().Attributes().UpsertString("host.name", "testHost") + rm.Resource().Attributes().PutString("host.name", "testHost") il := rm.ScopeMetrics().AppendEmpty() il.Scope().SetName("name") il.Scope().SetVersion("version") @@ -62,14 +62,14 @@ var metricsSumOTLPFull = func() Metrics { rs := metric.ResourceMetrics().AppendEmpty() rs.SetSchemaUrl("schemaURL") // Add resource. - rs.Resource().Attributes().UpsertString("host.name", "testHost") - rs.Resource().Attributes().UpsertString("service.name", "testService") + rs.Resource().Attributes().PutString("host.name", "testHost") + rs.Resource().Attributes().PutString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) // Add InstrumentationLibraryMetrics. m := rs.ScopeMetrics().AppendEmpty() m.Scope().SetName("instrumentation name") m.Scope().SetVersion("instrumentation version") - m.Scope().Attributes().UpsertString("instrumentation.attribute", "test") + m.Scope().Attributes().PutString("instrumentation.attribute", "test") m.SetSchemaUrl("schemaURL") // Add Metric sumMetric := m.Metrics().AppendEmpty() @@ -82,11 +82,11 @@ var metricsSumOTLPFull = func() Metrics { datapoint := sum.DataPoints().AppendEmpty() datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) datapoint.SetIntVal(100) - datapoint.Attributes().UpsertString("string", "value") - datapoint.Attributes().UpsertBool("bool", true) - datapoint.Attributes().UpsertInt("int", 1) - datapoint.Attributes().UpsertDouble("double", 1.1) - datapoint.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + datapoint.Attributes().PutString("string", "value") + datapoint.Attributes().PutBool("bool", true) + datapoint.Attributes().PutInt("int", 1) + datapoint.Attributes().PutDouble("double", 1.1) + datapoint.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) exemplar := datapoint.Exemplars().AppendEmpty() exemplar.SetDoubleVal(99.3) exemplar.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) @@ -94,7 +94,7 @@ var metricsSumOTLPFull = func() Metrics { spanID := pcommon.SpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}) exemplar.SetSpanID(spanID) exemplar.SetTraceID(traceID) - exemplar.FilteredAttributes().UpsertString("service.name", "testService") + exemplar.FilteredAttributes().PutString("service.name", "testService") datapoint.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) return metric } @@ -104,8 +104,8 @@ var metricsGaugeOTLPFull = func() Metrics { rs := metric.ResourceMetrics().AppendEmpty() rs.SetSchemaUrl("schemaURL") // Add resource. - rs.Resource().Attributes().UpsertString("host.name", "testHost") - rs.Resource().Attributes().UpsertString("service.name", "testService") + rs.Resource().Attributes().PutString("host.name", "testHost") + rs.Resource().Attributes().PutString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) // Add InstrumentationLibraryMetrics. m := rs.ScopeMetrics().AppendEmpty() @@ -121,11 +121,11 @@ var metricsGaugeOTLPFull = func() Metrics { datapoint := gauge.DataPoints().AppendEmpty() datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) datapoint.SetDoubleVal(10.2) - datapoint.Attributes().UpsertString("string", "value") - datapoint.Attributes().UpsertBool("bool", true) - datapoint.Attributes().UpsertInt("int", 1) - datapoint.Attributes().UpsertDouble("double", 1.1) - datapoint.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + datapoint.Attributes().PutString("string", "value") + datapoint.Attributes().PutBool("bool", true) + datapoint.Attributes().PutInt("int", 1) + datapoint.Attributes().PutDouble("double", 1.1) + datapoint.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) exemplar := datapoint.Exemplars().AppendEmpty() exemplar.SetDoubleVal(99.3) exemplar.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) @@ -133,7 +133,7 @@ var metricsGaugeOTLPFull = func() Metrics { spanID := pcommon.SpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}) exemplar.SetSpanID(spanID) exemplar.SetTraceID(traceID) - exemplar.FilteredAttributes().UpsertString("service.name", "testService") + exemplar.FilteredAttributes().PutString("service.name", "testService") datapoint.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) return metric } @@ -143,8 +143,8 @@ var metricsHistogramOTLPFull = func() Metrics { rs := metric.ResourceMetrics().AppendEmpty() rs.SetSchemaUrl("schemaURL") // Add resource. - rs.Resource().Attributes().UpsertString("host.name", "testHost") - rs.Resource().Attributes().UpsertString("service.name", "testService") + rs.Resource().Attributes().PutString("host.name", "testHost") + rs.Resource().Attributes().PutString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) // Add InstrumentationLibraryMetrics. m := rs.ScopeMetrics().AppendEmpty() @@ -160,11 +160,11 @@ var metricsHistogramOTLPFull = func() Metrics { histogram.SetAggregationTemporality(MetricAggregationTemporalityCumulative) datapoint := histogram.DataPoints().AppendEmpty() datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) - datapoint.Attributes().UpsertString("string", "value") - datapoint.Attributes().UpsertBool("bool", true) - datapoint.Attributes().UpsertInt("int", 1) - datapoint.Attributes().UpsertDouble("double", 1.1) - datapoint.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + datapoint.Attributes().PutString("string", "value") + datapoint.Attributes().PutBool("bool", true) + datapoint.Attributes().PutInt("int", 1) + datapoint.Attributes().PutDouble("double", 1.1) + datapoint.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) datapoint.SetCount(4) datapoint.SetSum(345) datapoint.BucketCounts().FromRaw([]uint64{1, 1, 2}) @@ -177,7 +177,7 @@ var metricsHistogramOTLPFull = func() Metrics { spanID := pcommon.SpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}) exemplar.SetSpanID(spanID) exemplar.SetTraceID(traceID) - exemplar.FilteredAttributes().UpsertString("service.name", "testService") + exemplar.FilteredAttributes().PutString("service.name", "testService") datapoint.SetMax(float64(time.Now().Unix())) datapoint.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) return metric @@ -188,8 +188,8 @@ var metricsExponentialHistogramOTLPFull = func() Metrics { rs := metric.ResourceMetrics().AppendEmpty() rs.SetSchemaUrl("schemaURL") // Add resource. - rs.Resource().Attributes().UpsertString("host.name", "testHost") - rs.Resource().Attributes().UpsertString("service.name", "testService") + rs.Resource().Attributes().PutString("host.name", "testHost") + rs.Resource().Attributes().PutString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) // Add InstrumentationLibraryMetrics. m := rs.ScopeMetrics().AppendEmpty() @@ -206,11 +206,11 @@ var metricsExponentialHistogramOTLPFull = func() Metrics { datapoint := histogram.DataPoints().AppendEmpty() datapoint.SetScale(1) datapoint.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now())) - datapoint.Attributes().UpsertString("string", "value") - datapoint.Attributes().UpsertBool("bool", true) - datapoint.Attributes().UpsertInt("int", 1) - datapoint.Attributes().UpsertDouble("double", 1.1) - datapoint.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + datapoint.Attributes().PutString("string", "value") + datapoint.Attributes().PutBool("bool", true) + datapoint.Attributes().PutInt("int", 1) + datapoint.Attributes().PutDouble("double", 1.1) + datapoint.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) datapoint.SetCount(4) datapoint.SetSum(345) datapoint.Positive().BucketCounts().FromRaw([]uint64{1, 1, 2}) @@ -223,7 +223,7 @@ var metricsExponentialHistogramOTLPFull = func() Metrics { spanID := pcommon.SpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}) exemplar.SetSpanID(spanID) exemplar.SetTraceID(traceID) - exemplar.FilteredAttributes().UpsertString("service.name", "testService") + exemplar.FilteredAttributes().PutString("service.name", "testService") datapoint.SetMax(float64(time.Now().Unix())) datapoint.Negative().BucketCounts().FromRaw([]uint64{1, 1, 2}) datapoint.Negative().SetOffset(2) @@ -237,8 +237,8 @@ var metricsSummaryOTLPFull = func() Metrics { rs := metric.ResourceMetrics().AppendEmpty() rs.SetSchemaUrl("schemaURL") // Add resource. - rs.Resource().Attributes().UpsertString("host.name", "testHost") - rs.Resource().Attributes().UpsertString("service.name", "testService") + rs.Resource().Attributes().PutString("host.name", "testHost") + rs.Resource().Attributes().PutString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) // Add InstrumentationLibraryMetrics. m := rs.ScopeMetrics().AppendEmpty() @@ -258,11 +258,11 @@ var metricsSummaryOTLPFull = func() Metrics { quantile := datapoint.QuantileValues().AppendEmpty() quantile.SetQuantile(0.5) quantile.SetValue(1.2) - datapoint.Attributes().UpsertString("string", "value") - datapoint.Attributes().UpsertBool("bool", true) - datapoint.Attributes().UpsertInt("int", 1) - datapoint.Attributes().UpsertDouble("double", 1.1) - datapoint.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + datapoint.Attributes().PutString("string", "value") + datapoint.Attributes().PutBool("bool", true) + datapoint.Attributes().PutInt("int", 1) + datapoint.Attributes().PutDouble("double", 1.1) + datapoint.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) datapoint.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) return metric } diff --git a/pdata/pmetric/metrics_test.go b/pdata/pmetric/metrics_test.go index c9ab4e6dc5f..4e97d19e719 100644 --- a/pdata/pmetric/metrics_test.go +++ b/pdata/pmetric/metrics_test.go @@ -383,7 +383,7 @@ func TestOtlpToFromInternalGaugeMutating(t *testing.T) { gaugeDataPoints.At(0).SetDoubleVal(124.1) assert.EqualValues(t, 124.1, gaugeDataPoints.At(0).DoubleVal()) gaugeDataPoints.At(0).Attributes().Remove("key0") - gaugeDataPoints.At(0).Attributes().UpsertString("k", "v") + gaugeDataPoints.At(0).Attributes().PutString("k", "v") assert.EqualValues(t, newAttributes, gaugeDataPoints.At(0).Attributes().AsRaw()) // Test that everything is updated. @@ -466,7 +466,7 @@ func TestOtlpToFromInternalSumMutating(t *testing.T) { doubleDataPoints.At(0).SetDoubleVal(124.1) assert.EqualValues(t, 124.1, doubleDataPoints.At(0).DoubleVal()) doubleDataPoints.At(0).Attributes().Remove("key0") - doubleDataPoints.At(0).Attributes().UpsertString("k", "v") + doubleDataPoints.At(0).Attributes().PutString("k", "v") assert.EqualValues(t, newAttributes, doubleDataPoints.At(0).Attributes().AsRaw()) // Test that everything is updated. @@ -548,7 +548,7 @@ func TestOtlpToFromInternalHistogramMutating(t *testing.T) { histogramDataPoints.At(0).SetTimestamp(pcommon.Timestamp(endTime + 1)) assert.EqualValues(t, endTime+1, histogramDataPoints.At(0).Timestamp()) histogramDataPoints.At(0).Attributes().Remove("key0") - histogramDataPoints.At(0).Attributes().UpsertString("k", "v") + histogramDataPoints.At(0).Attributes().PutString("k", "v") assert.EqualValues(t, newAttributes, histogramDataPoints.At(0).Attributes().AsRaw()) histogramDataPoints.At(0).ExplicitBounds().FromRaw([]float64{1}) assert.EqualValues(t, []float64{1}, histogramDataPoints.At(0).ExplicitBounds().AsRaw()) @@ -631,7 +631,7 @@ func TestOtlpToFromInternalExponentialHistogramMutating(t *testing.T) { histogramDataPoints.At(0).SetTimestamp(pcommon.Timestamp(endTime + 1)) assert.EqualValues(t, endTime+1, histogramDataPoints.At(0).Timestamp()) histogramDataPoints.At(0).Attributes().Remove("key0") - histogramDataPoints.At(0).Attributes().UpsertString("k", "v") + histogramDataPoints.At(0).Attributes().PutString("k", "v") assert.EqualValues(t, newAttributes, histogramDataPoints.At(0).Attributes().AsRaw()) // Test that everything is updated. assert.EqualValues(t, &otlpmetrics.MetricsData{ @@ -733,7 +733,8 @@ func BenchmarkOtlpToFromInternal_Gauge_MutateOneLabel(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { md := newMetrics(req) - md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Gauge().DataPoints().At(0).Attributes().UpsertString("key0", "value2") + md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Gauge().DataPoints().At(0).Attributes(). + PutString("key0", "value2") newReq := md.getOrig() if len(req.ResourceMetrics) != len(newReq.ResourceMetrics) { b.Fail() @@ -759,7 +760,8 @@ func BenchmarkOtlpToFromInternal_Sum_MutateOneLabel(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { md := newMetrics(req) - md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().UpsertString("key0", "value2") + md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes(). + PutString("key0", "value2") newReq := md.getOrig() if len(req.ResourceMetrics) != len(newReq.ResourceMetrics) { b.Fail() @@ -785,7 +787,8 @@ func BenchmarkOtlpToFromInternal_HistogramPoints_MutateOneLabel(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { md := newMetrics(req) - md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Histogram().DataPoints().At(0).Attributes().UpsertString("key0", "value2") + md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Histogram().DataPoints().At(0).Attributes(). + PutString("key0", "value2") newReq := md.getOrig() if len(req.ResourceMetrics) != len(newReq.ResourceMetrics) { b.Fail() diff --git a/pdata/ptrace/json_test.go b/pdata/ptrace/json_test.go index 60a4f7db1dc..106e769c037 100644 --- a/pdata/ptrace/json_test.go +++ b/pdata/ptrace/json_test.go @@ -26,7 +26,7 @@ import ( var tracesOTLP = func() Traces { td := NewTraces() rs := td.ResourceSpans().AppendEmpty() - rs.Resource().Attributes().UpsertString("host.name", "testHost") + rs.Resource().Attributes().PutString("host.name", "testHost") il := rs.ScopeSpans().AppendEmpty() il.Scope().SetName("name") il.Scope().SetVersion("version") @@ -64,8 +64,8 @@ var tracesOTLPFull = func() Traces { rs := td.ResourceSpans().AppendEmpty() rs.SetSchemaUrl("schemaURL") // Add resource. - rs.Resource().Attributes().UpsertString("host.name", "testHost") - rs.Resource().Attributes().UpsertString("service.name", "testService") + rs.Resource().Attributes().PutString("host.name", "testHost") + rs.Resource().Attributes().PutString("service.name", "testService") rs.Resource().SetDroppedAttributesCount(1) // Add ScopeSpans. il := rs.ScopeSpans().AppendEmpty() @@ -88,38 +88,38 @@ var tracesOTLPFull = func() Traces { sp.Status().SetCode(StatusCodeOk) sp.Status().SetMessage("message") // Add attributes. - sp.Attributes().UpsertString("string", "value") - sp.Attributes().UpsertBool("bool", true) - sp.Attributes().UpsertInt("int", 1) - sp.Attributes().UpsertDouble("double", 1.1) - sp.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) - arr := sp.Attributes().UpsertEmptySlice("array") + sp.Attributes().PutString("string", "value") + sp.Attributes().PutBool("bool", true) + sp.Attributes().PutInt("int", 1) + sp.Attributes().PutDouble("double", 1.1) + sp.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) + arr := sp.Attributes().PutEmptySlice("array") arr.AppendEmpty().SetIntVal(1) arr.AppendEmpty().SetStringVal("str") - kvList := sp.Attributes().UpsertEmptyMap("kvList") - kvList.UpsertInt("int", 1) - kvList.UpsertString("string", "string") + kvList := sp.Attributes().PutEmptyMap("kvList") + kvList.PutInt("int", 1) + kvList.PutString("string", "string") // Add events. event := sp.Events().AppendEmpty() event.SetName("eventName") event.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) event.SetDroppedAttributesCount(1) - event.Attributes().UpsertString("string", "value") - event.Attributes().UpsertBool("bool", true) - event.Attributes().UpsertInt("int", 1) - event.Attributes().UpsertDouble("double", 1.1) - event.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + event.Attributes().PutString("string", "value") + event.Attributes().PutBool("bool", true) + event.Attributes().PutInt("int", 1) + event.Attributes().PutDouble("double", 1.1) + event.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) // Add links. link := sp.Links().AppendEmpty() link.TraceStateStruct().FromRaw("state") link.SetTraceID(traceID) link.SetSpanID(spanID) link.SetDroppedAttributesCount(1) - link.Attributes().UpsertString("string", "value") - link.Attributes().UpsertBool("bool", true) - link.Attributes().UpsertInt("int", 1) - link.Attributes().UpsertDouble("double", 1.1) - link.Attributes().UpsertEmptyBytes("bytes").FromRaw([]byte("foo")) + link.Attributes().PutString("string", "value") + link.Attributes().PutBool("bool", true) + link.Attributes().PutInt("int", 1) + link.Attributes().PutDouble("double", 1.1) + link.Attributes().PutEmptyBytes("bytes").FromRaw([]byte("foo")) // Add another span. sp2 := il.Spans().AppendEmpty() sp2.SetName("testSpan2") diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 35841f748af..897428917f4 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -112,7 +112,7 @@ var traceJSON = []byte(` var traceOtlp = func() ptrace.Traces { td := ptrace.NewTraces() rs := td.ResourceSpans().AppendEmpty() - rs.Resource().Attributes().UpsertString(semconv.AttributeHostName, "testHost") + rs.Resource().Attributes().PutString(semconv.AttributeHostName, "testHost") spans := rs.ScopeSpans().AppendEmpty().Spans() span1 := spans.AppendEmpty() span1.SetTraceID([16]byte{0x5B, 0x8E, 0xFF, 0xF7, 0x98, 0x3, 0x81, 0x3, 0xD2, 0x69, 0xB6, 0x33, 0x81, 0x3F, 0xC6, 0xC}) @@ -122,7 +122,7 @@ var traceOtlp = func() ptrace.Traces { span1.SetStartTimestamp(1544712660300000000) span1.SetEndTimestamp(1544712660600000000) span1.SetKind(ptrace.SpanKindServer) - span1.Attributes().UpsertInt("attr1", 55) + span1.Attributes().PutInt("attr1", 55) span2 := spans.AppendEmpty() span2.SetTraceID([16]byte{0x5B, 0x8E, 0xFF, 0xF7, 0x98, 0x3, 0x81, 0x3, 0xD2, 0x69, 0xB6, 0x33, 0x81, 0x3F, 0xC6, 0xC}) span2.SetSpanID([8]byte{0xEE, 0xE1, 0x9B, 0x7E, 0xC3, 0xC1, 0xB1, 0x73}) @@ -130,7 +130,7 @@ var traceOtlp = func() ptrace.Traces { span2.SetStartTimestamp(1544712660000000000) span2.SetEndTimestamp(1544712661000000000) span2.SetKind(ptrace.SpanKindClient) - span2.Attributes().UpsertInt("attr1", 55) + span2.Attributes().PutInt("attr1", 55) return td }()