diff --git a/CHANGELOG.md b/CHANGELOG.md index e4398ccf14a..102bb4d1bbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,16 @@ - Rename `pdata.AttributeMap.Delete` to `pdata.AttributeMap.Remove` (#4914) - pdata: deprecate funcs working with InternalRep (#4957) +### 🚩 Deprecations 🚩 + +- API related to `pdata.AttributeValue` is deprecated in favor of `pdata.AnyValue` (#4975) + - `pdata.AttributeValue` struct is deprecated in favor of `pdata.AnyValue` + - `pdata.AttributeValueType` type is deprecated in favor of `pdata.AnyValueType` + - `pdata.AttributeValueType...` constants are deprecated in favor of `pdata.AnyValueType...` + - `pdata.NewAttributeValue...` funcs are deprecated in favor `pdata.NewAnyValue...` + - `pdata.AttributeValueSlice` struct is deprecated in favor `pdata.AnyValueSlice` + - `pdata.NewAttributeValueSlice` func is deprecated in favor `pdata.NewAnyValueSlice` + ### 💡 Enhancements 💡 - Add `pdata.AttributeMap.RemoveIf`, which is a more performant way to remove multiple keys (#4914) @@ -1014,7 +1024,7 @@ This release is marked as "bad" since the metrics pipelines will produce bad dat - Remove NewAttributeValueSlice (#2028) and mark NewAttributeValue as deprecated (#2022) - Remove pdata.StringValue (#2021) - Remove pdata.InitFromAttributeMap, use CopyTo if needed (#2042) -- Remove SetMapVal and SetArrayVal for pdata.AttributeValue (#2039) +- Remove SetMapVal and SetArrayVal for pdata.AnyValue (#2039) ### 💡 Enhancements 💡 diff --git a/internal/otlptext/databuffer.go b/internal/otlptext/databuffer.go index 81849db3b6e..1d5b1d3e0f8 100644 --- a/internal/otlptext/databuffer.go +++ b/internal/otlptext/databuffer.go @@ -43,7 +43,7 @@ func (b *dataBuffer) logAttributeMap(label string, am pdata.AttributeMap) { } b.logEntry("%s:", label) - am.Range(func(k string, v pdata.AttributeValue) bool { + am.Range(func(k string, v pdata.AnyValue) bool { b.logEntry(" -> %s: %s(%s)", k, v.Type().String(), attributeValueToString(v)) return true }) @@ -221,7 +221,7 @@ func (b *dataBuffer) logEvents(description string, se pdata.SpanEventSlice) { continue } b.logEntry(" -> Attributes:") - e.Attributes().Range(func(k string, v pdata.AttributeValue) bool { + e.Attributes().Range(func(k string, v pdata.AnyValue) bool { b.logEntry(" -> %s: %s(%s)", k, v.Type().String(), attributeValueToString(v)) return true }) @@ -246,33 +246,33 @@ func (b *dataBuffer) logLinks(description string, sl pdata.SpanLinkSlice) { continue } b.logEntry(" -> Attributes:") - l.Attributes().Range(func(k string, v pdata.AttributeValue) bool { + l.Attributes().Range(func(k string, v pdata.AnyValue) bool { b.logEntry(" -> %s: %s(%s)", k, v.Type().String(), attributeValueToString(v)) return true }) } } -func attributeValueToString(av pdata.AttributeValue) string { +func attributeValueToString(av pdata.AnyValue) string { switch av.Type() { - case pdata.AttributeValueTypeString: + case pdata.AnyValueTypeString: return av.StringVal() - case pdata.AttributeValueTypeBool: + case pdata.AnyValueTypeBool: return strconv.FormatBool(av.BoolVal()) - case pdata.AttributeValueTypeDouble: + case pdata.AnyValueTypeDouble: return strconv.FormatFloat(av.DoubleVal(), 'f', -1, 64) - case pdata.AttributeValueTypeInt: + case pdata.AnyValueTypeInt: return strconv.FormatInt(av.IntVal(), 10) - case pdata.AttributeValueTypeArray: + case pdata.AnyValueTypeArray: return attributeValueSliceToString(av.SliceVal()) - case pdata.AttributeValueTypeMap: + case pdata.AnyValueTypeMap: return attributeMapToString(av.MapVal()) default: return fmt.Sprintf("", av.Type()) } } -func attributeValueSliceToString(av pdata.AttributeValueSlice) string { +func attributeValueSliceToString(av pdata.AnyValueSlice) string { var b strings.Builder b.WriteByte('[') for i := 0; i < av.Len(); i++ { @@ -291,7 +291,7 @@ func attributeMapToString(av pdata.AttributeMap) string { var b strings.Builder b.WriteString("{\n") - av.Sort().Range(func(k string, v pdata.AttributeValue) bool { + av.Sort().Range(func(k string, v pdata.AnyValue) bool { fmt.Fprintf(&b, " -> %s: %s(%s)\n", k, v.Type(), v.AsString()) return true }) diff --git a/internal/otlptext/databuffer_test.go b/internal/otlptext/databuffer_test.go index 1d509f73b6a..561807e3e77 100644 --- a/internal/otlptext/databuffer_test.go +++ b/internal/otlptext/databuffer_test.go @@ -23,11 +23,11 @@ import ( ) func TestNestedArraySerializesCorrectly(t *testing.T) { - ava := pdata.NewAttributeValueArray() + ava := pdata.NewAnyValueArray() ava.SliceVal().AppendEmpty().SetStringVal("foo") ava.SliceVal().AppendEmpty().SetIntVal(42) - ava2 := pdata.NewAttributeValueArray() + ava2 := pdata.NewAnyValueArray() ava2.SliceVal().AppendEmpty().SetStringVal("bar") ava2.CopyTo(ava.SliceVal().AppendEmpty()) @@ -39,11 +39,11 @@ func TestNestedArraySerializesCorrectly(t *testing.T) { } func TestNestedMapSerializesCorrectly(t *testing.T) { - ava := pdata.NewAttributeValueMap() + ava := pdata.NewAnyValueMap() av := ava.MapVal() - av.Insert("foo", pdata.NewAttributeValueString("test")) + av.Insert("foo", pdata.NewAnyValueString("test")) - ava2 := pdata.NewAttributeValueMap() + ava2 := pdata.NewAnyValueMap() av2 := ava2.MapVal() av2.InsertInt("bar", 13) av.Insert("zoo", ava2) diff --git a/internal/testdata/common.go b/internal/testdata/common.go index da6c95cd8f1..526dd54709a 100644 --- a/internal/testdata/common.go +++ b/internal/testdata/common.go @@ -19,12 +19,12 @@ import ( ) var ( - resourceAttributes1 = pdata.NewAttributeMapFromMap(map[string]pdata.AttributeValue{"resource-attr": pdata.NewAttributeValueString("resource-attr-val-1")}) - resourceAttributes2 = pdata.NewAttributeMapFromMap(map[string]pdata.AttributeValue{"resource-attr": pdata.NewAttributeValueString("resource-attr-val-2")}) - spanEventAttributes = pdata.NewAttributeMapFromMap(map[string]pdata.AttributeValue{"span-event-attr": pdata.NewAttributeValueString("span-event-attr-val")}) - spanLinkAttributes = pdata.NewAttributeMapFromMap(map[string]pdata.AttributeValue{"span-link-attr": pdata.NewAttributeValueString("span-link-attr-val")}) - spanAttributes = pdata.NewAttributeMapFromMap(map[string]pdata.AttributeValue{"span-attr": pdata.NewAttributeValueString("span-attr-val")}) - metricAttachment = pdata.NewAttributeMapFromMap(map[string]pdata.AttributeValue{"exemplar-attachment": pdata.NewAttributeValueString("exemplar-attachment-value")}) + resourceAttributes1 = pdata.NewAttributeMapFromMap(map[string]pdata.AnyValue{"resource-attr": pdata.NewAnyValueString("resource-attr-val-1")}) + resourceAttributes2 = pdata.NewAttributeMapFromMap(map[string]pdata.AnyValue{"resource-attr": pdata.NewAnyValueString("resource-attr-val-2")}) + spanEventAttributes = pdata.NewAttributeMapFromMap(map[string]pdata.AnyValue{"span-event-attr": pdata.NewAnyValueString("span-event-attr-val")}) + spanLinkAttributes = pdata.NewAttributeMapFromMap(map[string]pdata.AnyValue{"span-link-attr": pdata.NewAnyValueString("span-link-attr-val")}) + spanAttributes = pdata.NewAttributeMapFromMap(map[string]pdata.AnyValue{"span-attr": pdata.NewAnyValueString("span-attr-val")}) + metricAttachment = pdata.NewAttributeMapFromMap(map[string]pdata.AnyValue{"exemplar-attachment": pdata.NewAnyValueString("exemplar-attachment-value")}) ) const ( diff --git a/model/internal/cmd/pdatagen/internal/common_structs.go b/model/internal/cmd/pdatagen/internal/common_structs.go index 01716967df0..3d54e5189b8 100644 --- a/model/internal/cmd/pdatagen/internal/common_structs.go +++ b/model/internal/cmd/pdatagen/internal/common_structs.go @@ -28,7 +28,7 @@ var commonFile = &File{ }, structs: []baseStruct{ instrumentationLibrary, - attributeValueArray, + anyValueArray, }, } @@ -105,12 +105,12 @@ var nameField = &primitiveField{ } var anyValue = &messageValueStruct{ - structName: "AttributeValue", + structName: "AnyValue", originFullName: "otlpcommon.AnyValue", } -var attributeValueArray = &sliceOfValues{ - structName: "AttributeValueSlice", +var anyValueArray = &sliceOfValues{ + structName: "AnyValueSlice", element: anyValue, } diff --git a/model/internal/pdata/common.go b/model/internal/pdata/common.go index 700585edd5a..e02cb199029 100644 --- a/model/internal/pdata/common.go +++ b/model/internal/pdata/common.go @@ -28,168 +28,168 @@ import ( otlpcommon "go.opentelemetry.io/collector/model/internal/data/protogen/common/v1" ) -// AttributeValueType specifies the type of AttributeValue. -type AttributeValueType int32 +// AnyValueType specifies the type of AnyValue. +type AnyValueType int32 const ( - AttributeValueTypeEmpty AttributeValueType = iota - AttributeValueTypeString - AttributeValueTypeInt - AttributeValueTypeDouble - AttributeValueTypeBool - AttributeValueTypeMap - AttributeValueTypeArray - AttributeValueTypeBytes + AnyValueTypeEmpty AnyValueType = iota + AnyValueTypeString + AnyValueTypeInt + AnyValueTypeDouble + AnyValueTypeBool + AnyValueTypeMap + AnyValueTypeArray + AnyValueTypeBytes ) -// String returns the string representation of the AttributeValueType. -func (avt AttributeValueType) String() string { +// String returns the string representation of the AnyValueType. +func (avt AnyValueType) String() string { switch avt { - case AttributeValueTypeEmpty: + case AnyValueTypeEmpty: return "EMPTY" - case AttributeValueTypeString: + case AnyValueTypeString: return "STRING" - case AttributeValueTypeBool: + case AnyValueTypeBool: return "BOOL" - case AttributeValueTypeInt: + case AnyValueTypeInt: return "INT" - case AttributeValueTypeDouble: + case AnyValueTypeDouble: return "DOUBLE" - case AttributeValueTypeMap: + case AnyValueTypeMap: return "MAP" - case AttributeValueTypeArray: + case AnyValueTypeArray: return "ARRAY" - case AttributeValueTypeBytes: + case AnyValueTypeBytes: return "BYTES" } return "" } -// AttributeValue is a mutable cell containing the value of an attribute. Typically used in AttributeMap. +// AnyValue is a mutable cell containing the value of an attribute. Typically used in AttributeMap. // Must use one of NewAttributeValue+ functions below to create new instances. // // Intended to be passed by value since internally it is just a pointer to actual // value representation. For the same reason passing by value and calling setters // will modify the original, e.g.: // -// func f1(val AttributeValue) { val.SetIntVal(234) } +// func f1(val AnyValue) { val.SetIntVal(234) } // func f2() { -// v := NewAttributeValueString("a string") +// v := NewAnyValueString("a string") // f1(v) -// _ := v.Type() // this will return AttributeValueTypeInt +// _ := v.Type() // this will return AnyValueTypeInt // } // -// Important: zero-initialized instance is not valid for use. All AttributeValue functions below must +// Important: zero-initialized instance is not valid for use. All AnyValue functions below must // be called only on instances that are created via NewAttributeValue+ functions. -type AttributeValue struct { +type AnyValue struct { orig *otlpcommon.AnyValue } -func newAttributeValue(orig *otlpcommon.AnyValue) AttributeValue { - return AttributeValue{orig} +func newAnyValue(orig *otlpcommon.AnyValue) AnyValue { + return AnyValue{orig} } -// NewAttributeValueEmpty creates a new AttributeValue with an empty value. -func NewAttributeValueEmpty() AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{}} +// NewAnyValueEmpty creates a new AnyValue with an empty value. +func NewAnyValueEmpty() AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{}} } -// NewAttributeValueString creates a new AttributeValue with the given string value. -func NewAttributeValueString(v string) AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: v}}} +// NewAnyValueString creates a new AnyValue with the given string value. +func NewAnyValueString(v string) AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: v}}} } -// NewAttributeValueInt creates a new AttributeValue with the given int64 value. -func NewAttributeValueInt(v int64) AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: v}}} +// NewAnyValueInt creates a new AnyValue with the given int64 value. +func NewAnyValueInt(v int64) AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: v}}} } -// NewAttributeValueDouble creates a new AttributeValue with the given float64 value. -func NewAttributeValueDouble(v float64) AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: v}}} +// NewAnyValueDouble creates a new AnyValue with the given float64 value. +func NewAnyValueDouble(v float64) AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: v}}} } -// NewAttributeValueBool creates a new AttributeValue with the given bool value. -func NewAttributeValueBool(v bool) AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: v}}} +// NewAnyValueBool creates a new AnyValue with the given bool value. +func NewAnyValueBool(v bool) AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: v}}} } -// NewAttributeValueMap creates a new AttributeValue of map type. -func NewAttributeValueMap() AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}}} +// NewAnyValueMap creates a new AnyValue of map type. +func NewAnyValueMap() AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}}} } -// NewAttributeValueArray creates a new AttributeValue of array type. -func NewAttributeValueArray() AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}}} +// NewAnyValueArray creates a new AnyValue of array type. +func NewAnyValueArray() AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}}} } -// NewAttributeValueBytes creates a new AttributeValue with the given []byte value. +// NewAnyValueBytes creates a new AnyValue with the given []byte value. // The caller must ensure the []byte passed in is not modified after the call is made, sharing the data // across multiple attributes is forbidden. -func NewAttributeValueBytes(v []byte) AttributeValue { - return AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BytesValue{BytesValue: v}}} +func NewAnyValueBytes(v []byte) AnyValue { + return AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BytesValue{BytesValue: v}}} } -// Type returns the type of the value for this AttributeValue. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) Type() AttributeValueType { +// Type returns the type of the value for this AnyValue. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) Type() AnyValueType { if a.orig.Value == nil { - return AttributeValueTypeEmpty + return AnyValueTypeEmpty } switch a.orig.Value.(type) { case *otlpcommon.AnyValue_StringValue: - return AttributeValueTypeString + return AnyValueTypeString case *otlpcommon.AnyValue_BoolValue: - return AttributeValueTypeBool + return AnyValueTypeBool case *otlpcommon.AnyValue_IntValue: - return AttributeValueTypeInt + return AnyValueTypeInt case *otlpcommon.AnyValue_DoubleValue: - return AttributeValueTypeDouble + return AnyValueTypeDouble case *otlpcommon.AnyValue_KvlistValue: - return AttributeValueTypeMap + return AnyValueTypeMap case *otlpcommon.AnyValue_ArrayValue: - return AttributeValueTypeArray + return AnyValueTypeArray case *otlpcommon.AnyValue_BytesValue: - return AttributeValueTypeBytes + return AnyValueTypeBytes } - return AttributeValueTypeEmpty + return AnyValueTypeEmpty } -// StringVal returns the string value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeString then returns empty string. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) StringVal() string { +// StringVal returns the string value associated with this AnyValue. +// If the Type() is not AnyValueTypeString then returns empty string. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) StringVal() string { return a.orig.GetStringValue() } -// IntVal returns the int64 value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeInt then returns int64(0). -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) IntVal() int64 { +// IntVal returns the int64 value associated with this AnyValue. +// If the Type() is not AnyValueTypeInt then returns int64(0). +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) IntVal() int64 { return a.orig.GetIntValue() } -// DoubleVal returns the float64 value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeDouble then returns float64(0). -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) DoubleVal() float64 { +// DoubleVal returns the float64 value associated with this AnyValue. +// If the Type() is not AnyValueTypeDouble then returns float64(0). +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) DoubleVal() float64 { return a.orig.GetDoubleValue() } -// BoolVal returns the bool value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeBool then returns false. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) BoolVal() bool { +// BoolVal returns the bool value associated with this AnyValue. +// If the Type() is not AnyValueTypeBool then returns false. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) BoolVal() bool { return a.orig.GetBoolValue() } -// MapVal returns the map value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeMap then returns an empty map. Note that modifying -// such empty map has no effect on this AttributeValue. +// MapVal returns the map value associated with this AnyValue. +// If the Type() is not AnyValueTypeMap then returns an empty map. Note that modifying +// such empty map has no effect on this AnyValue. // -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) MapVal() AttributeMap { +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) MapVal() AttributeMap { kvlist := a.orig.GetKvlistValue() if kvlist == nil { return NewAttributeMap() @@ -197,66 +197,66 @@ func (a AttributeValue) MapVal() AttributeMap { return newAttributeMap(&kvlist.Values) } -// SliceVal returns the slice value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeArray then returns an empty slice. Note that modifying -// such empty slice has no effect on this AttributeValue. +// SliceVal returns the slice value associated with this AnyValue. +// If the Type() is not AnyValueTypeArray then returns an empty slice. Note that modifying +// such empty slice has no effect on this AnyValue. // -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) SliceVal() AttributeValueSlice { +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) SliceVal() AnyValueSlice { arr := a.orig.GetArrayValue() if arr == nil { - return NewAttributeValueSlice() + return NewAnyValueSlice() } - return newAttributeValueSlice(&arr.Values) + return newAnyValueSlice(&arr.Values) } -// BytesVal returns the []byte value associated with this AttributeValue. -// If the Type() is not AttributeValueTypeBytes then returns false. -// Calling this function on zero-initialized AttributeValue will cause a panic. +// BytesVal returns the []byte value associated with this AnyValue. +// If the Type() is not AnyValueTypeBytes then returns false. +// Calling this function on zero-initialized AnyValue will cause a panic. // Modifying the returned []byte in-place is forbidden. -func (a AttributeValue) BytesVal() []byte { +func (a AnyValue) BytesVal() []byte { return a.orig.GetBytesValue() } -// SetStringVal replaces the string value associated with this AttributeValue, -// it also changes the type to be AttributeValueTypeString. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) SetStringVal(v string) { +// SetStringVal replaces the string value associated with this AnyValue, +// it also changes the type to be AnyValueTypeString. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) SetStringVal(v string) { a.orig.Value = &otlpcommon.AnyValue_StringValue{StringValue: v} } -// SetIntVal replaces the int64 value associated with this AttributeValue, -// it also changes the type to be AttributeValueTypeInt. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) SetIntVal(v int64) { +// SetIntVal replaces the int64 value associated with this AnyValue, +// it also changes the type to be AnyValueTypeInt. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) SetIntVal(v int64) { a.orig.Value = &otlpcommon.AnyValue_IntValue{IntValue: v} } -// SetDoubleVal replaces the float64 value associated with this AttributeValue, -// it also changes the type to be AttributeValueTypeDouble. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) SetDoubleVal(v float64) { +// SetDoubleVal replaces the float64 value associated with this AnyValue, +// it also changes the type to be AnyValueTypeDouble. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) SetDoubleVal(v float64) { a.orig.Value = &otlpcommon.AnyValue_DoubleValue{DoubleValue: v} } -// SetBoolVal replaces the bool value associated with this AttributeValue, -// it also changes the type to be AttributeValueTypeBool. -// Calling this function on zero-initialized AttributeValue will cause a panic. -func (a AttributeValue) SetBoolVal(v bool) { +// SetBoolVal replaces the bool value associated with this AnyValue, +// it also changes the type to be AnyValueTypeBool. +// Calling this function on zero-initialized AnyValue will cause a panic. +func (a AnyValue) SetBoolVal(v bool) { a.orig.Value = &otlpcommon.AnyValue_BoolValue{BoolValue: v} } -// SetBytesVal replaces the []byte value associated with this AttributeValue, -// it also changes the type to be AttributeValueTypeBytes. -// Calling this function on zero-initialized AttributeValue will cause a panic. +// SetBytesVal replaces the []byte value associated with this AnyValue, +// it also changes the type to be AnyValueTypeBytes. +// Calling this function on zero-initialized AnyValue 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. -func (a AttributeValue) SetBytesVal(v []byte) { +func (a AnyValue) SetBytesVal(v []byte) { a.orig.Value = &otlpcommon.AnyValue_BytesValue{BytesValue: v} } // copyTo copies the value to AnyValue. Will panic if dest is nil. -func (a AttributeValue) copyTo(dest *otlpcommon.AnyValue) { +func (a AnyValue) copyTo(dest *otlpcommon.AnyValue) { switch v := a.orig.Value.(type) { case *otlpcommon.AnyValue_KvlistValue: kv, ok := dest.Value.(*otlpcommon.AnyValue_KvlistValue) @@ -281,7 +281,7 @@ func (a AttributeValue) copyTo(dest *otlpcommon.AnyValue) { return } // Deep copy to dest. - newAttributeValueSlice(&v.ArrayValue.Values).CopyTo(newAttributeValueSlice(&av.ArrayValue.Values)) + newAnyValueSlice(&v.ArrayValue.Values).CopyTo(newAnyValueSlice(&av.ArrayValue.Values)) default: // Primitive immutable type, no need for deep copy. dest.Value = a.orig.Value @@ -289,12 +289,12 @@ func (a AttributeValue) copyTo(dest *otlpcommon.AnyValue) { } // CopyTo copies the attribute to a destination. -func (a AttributeValue) CopyTo(dest AttributeValue) { +func (a AnyValue) CopyTo(dest AnyValue) { a.copyTo(dest.orig) } // Equal checks for equality, it returns true if the objects are equal otherwise false. -func (a AttributeValue) Equal(av AttributeValue) bool { +func (a AnyValue) Equal(av AnyValue) bool { if a.orig == av.orig { return true } @@ -325,14 +325,14 @@ func (a AttributeValue) Equal(av AttributeValue) bool { for i, val := range avv { val := val - newAv := newAttributeValue(&vv[i]) + newAv := newAnyValue(&vv[i]) // According to the specification, array values must be scalar. - if avType := newAv.Type(); avType == AttributeValueTypeArray || avType == AttributeValueTypeMap { + if avType := newAv.Type(); avType == AnyValueTypeArray || avType == AnyValueTypeMap { return false } - if !newAv.Equal(newAttributeValue(&val)) { + if !newAv.Equal(newAnyValue(&val)) { return false } } @@ -352,7 +352,7 @@ func (a AttributeValue) Equal(av AttributeValue) bool { return false } - if !newAv.Equal(newAttributeValue(&val.Value)) { + if !newAv.Equal(newAnyValue(&val.Value)) { return false } } @@ -364,34 +364,34 @@ func (a AttributeValue) Equal(av AttributeValue) bool { return false } -// AsString converts an OTLP AttributeValue object of any type to its equivalent string +// AsString converts an OTLP AnyValue object of any type to its equivalent string // representation. This differs from StringVal which only returns a non-empty value -// if the AttributeValueType is AttributeValueTypeString. -func (a AttributeValue) AsString() string { +// if the AnyValueType is AnyValueTypeString. +func (a AnyValue) AsString() string { switch a.Type() { - case AttributeValueTypeEmpty: + case AnyValueTypeEmpty: return "" - case AttributeValueTypeString: + case AnyValueTypeString: return a.StringVal() - case AttributeValueTypeBool: + case AnyValueTypeBool: return strconv.FormatBool(a.BoolVal()) - case AttributeValueTypeDouble: + case AnyValueTypeDouble: return strconv.FormatFloat(a.DoubleVal(), 'f', -1, 64) - case AttributeValueTypeInt: + case AnyValueTypeInt: return strconv.FormatInt(a.IntVal(), 10) - case AttributeValueTypeMap: + case AnyValueTypeMap: jsonStr, _ := json.Marshal(a.MapVal().AsRaw()) return string(jsonStr) - case AttributeValueTypeBytes: + case AnyValueTypeBytes: return base64.StdEncoding.EncodeToString(a.BytesVal()) - case AttributeValueTypeArray: + case AnyValueTypeArray: jsonStr, _ := json.Marshal(a.SliceVal().asRaw()) return string(jsonStr) @@ -402,28 +402,28 @@ func (a AttributeValue) AsString() string { func newAttributeKeyValueString(k string, v string) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := AttributeValue{&orig.Value} + akv := AnyValue{&orig.Value} akv.SetStringVal(v) return orig } func newAttributeKeyValueInt(k string, v int64) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := AttributeValue{&orig.Value} + akv := AnyValue{&orig.Value} akv.SetIntVal(v) return orig } func newAttributeKeyValueDouble(k string, v float64) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := AttributeValue{&orig.Value} + akv := AnyValue{&orig.Value} akv.SetDoubleVal(v) return orig } func newAttributeKeyValueBool(k string, v bool) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := AttributeValue{&orig.Value} + akv := AnyValue{&orig.Value} akv.SetBoolVal(v) return orig } @@ -433,7 +433,7 @@ func newAttributeKeyValueNull(k string) otlpcommon.KeyValue { return orig } -func newAttributeKeyValue(k string, av AttributeValue) otlpcommon.KeyValue { +func newAttributeKeyValue(k string, av AnyValue) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} av.copyTo(&orig.Value) return orig @@ -441,7 +441,7 @@ func newAttributeKeyValue(k string, av AttributeValue) otlpcommon.KeyValue { func newAttributeKeyValueBytes(k string, v []byte) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := AttributeValue{&orig.Value} + akv := AnyValue{&orig.Value} akv.SetBytesVal(v) return orig } @@ -458,8 +458,8 @@ func NewAttributeMap() AttributeMap { } // NewAttributeMapFromMap creates a AttributeMap with values -// from the given map[string]AttributeValue. -func NewAttributeMapFromMap(attrMap map[string]AttributeValue) AttributeMap { +// from the given map[string]AnyValue. +func NewAttributeMapFromMap(attrMap map[string]AnyValue) AttributeMap { if len(attrMap) == 0 { kv := []otlpcommon.KeyValue(nil) return AttributeMap{&kv} @@ -494,21 +494,21 @@ func (am AttributeMap) EnsureCapacity(capacity int) { copy(*am.orig, oldOrig) } -// Get returns the AttributeValue associated with the key and true. Returned -// AttributeValue is not a copy, it is a reference to the value stored in this map. -// It is allowed to modify the returned value using AttributeValue.Set* functions. +// Get returns the AnyValue associated with the key and true. Returned +// AnyValue is not a copy, it is a reference to the value stored in this map. +// It is allowed to modify the returned value using AnyValue.Set* functions. // Such modification will be applied to the value stored in this map. // // If the key does not exist returns an invalid instance of the KeyValue and false. // Calling any functions on the returned invalid instance will cause a panic. -func (am AttributeMap) Get(key string) (AttributeValue, bool) { +func (am AttributeMap) Get(key string) (AnyValue, bool) { for i := range *am.orig { akv := &(*am.orig)[i] if akv.Key == key { - return AttributeValue{&akv.Value}, true + return AnyValue{&akv.Value}, true } } - return AttributeValue{nil}, false + return AnyValue{nil}, false } // Delete deletes the entry associated with the key and returns true if the key @@ -533,11 +533,11 @@ func (am AttributeMap) Remove(key string) bool { } // RemoveIf removes the entries for which the function in question returns true -func (am AttributeMap) RemoveIf(f func(string, AttributeValue) bool) { +func (am AttributeMap) RemoveIf(f func(string, AnyValue) bool) { newLen := 0 for i := 0; i < len(*am.orig); i++ { akv := &(*am.orig)[i] - if f(akv.Key, AttributeValue{&akv.Value}) { + if f(akv.Key, AnyValue{&akv.Value}) { continue } if newLen == i { @@ -551,14 +551,14 @@ func (am AttributeMap) RemoveIf(f func(string, AttributeValue) bool) { *am.orig = (*am.orig)[:newLen] } -// Insert adds the AttributeValue to the map when the key does not exist. +// Insert adds the AnyValue to the map when the key does not exist. // No action is applied to the map where the key already exists. // -// Calling this function with a zero-initialized AttributeValue struct will cause a panic. +// Calling this function with a zero-initialized AnyValue struct will cause a panic. // // Important: this function should not be used if the caller has access to // the raw value to avoid an extra allocation. -func (am AttributeMap) Insert(k string, v AttributeValue) { +func (am AttributeMap) Insert(k string, v AnyValue) { if _, existing := am.Get(k); !existing { *am.orig = append(*am.orig, newAttributeKeyValue(k, v)) } @@ -614,14 +614,14 @@ func (am AttributeMap) InsertBytes(k string, v []byte) { } } -// Update updates an existing AttributeValue with a value. +// Update updates an existing AnyValue with a value. // No action is applied to the map where the key does not exist. // -// Calling this function with a zero-initialized AttributeValue struct will cause a panic. +// Calling this function with a zero-initialized AnyValue struct will cause a panic. // // Important: this function should not be used if the caller has access to // the raw value to avoid an extra allocation. -func (am AttributeMap) Update(k string, v AttributeValue) { +func (am AttributeMap) Update(k string, v AnyValue) { if av, existing := am.Get(k); existing { v.copyTo(av.orig) } @@ -669,15 +669,15 @@ func (am AttributeMap) UpdateBytes(k string, v []byte) { } } -// Upsert performs the Insert or Update action. The AttributeValue is +// Upsert performs the Insert or Update action. The AnyValue 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. // -// Calling this function with a zero-initialized AttributeValue struct will cause a panic. +// Calling this function with a zero-initialized AnyValue struct will cause a panic. // // Important: this function should not be used if the caller has access to // the raw value to avoid an extra allocation. -func (am AttributeMap) Upsert(k string, v AttributeValue) { +func (am AttributeMap) Upsert(k string, v AnyValue) { if av, existing := am.Get(k); existing { v.copyTo(av.orig) } else { @@ -685,7 +685,7 @@ func (am AttributeMap) Upsert(k string, v AttributeValue) { } } -// UpsertString performs the Insert or Update action. The AttributeValue is +// UpsertString performs the Insert or Update action. The AnyValue 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 (am AttributeMap) UpsertString(k string, v string) { @@ -765,13 +765,13 @@ func (am AttributeMap) Len() int { // // Example: // -// sm.Range(func(k string, v AttributeValue) bool { +// sm.Range(func(k string, v AnyValue) bool { // ... // }) -func (am AttributeMap) Range(f func(k string, v AttributeValue) bool) { +func (am AttributeMap) Range(f func(k string, v AnyValue) bool) { for i := range *am.orig { kv := &(*am.orig)[i] - if !f(kv.Key, AttributeValue{&kv.Value}) { + if !f(kv.Key, AnyValue{&kv.Value}) { break } } @@ -788,7 +788,7 @@ func (am AttributeMap) CopyTo(dest AttributeMap) { akv := &(*am.orig)[i] destAkv := &(*dest.orig)[i] destAkv.Key = akv.Key - AttributeValue{&akv.Value}.copyTo(&destAkv.Value) + AnyValue{&akv.Value}.copyTo(&destAkv.Value) } return } @@ -798,7 +798,7 @@ func (am AttributeMap) CopyTo(dest AttributeMap) { for i := range *am.orig { akv := &(*am.orig)[i] origs[i].Key = akv.Key - AttributeValue{&akv.Value}.copyTo(&origs[i].Value) + AnyValue{&akv.Value}.copyTo(&origs[i].Value) } *dest.orig = origs } @@ -806,23 +806,23 @@ func (am AttributeMap) CopyTo(dest AttributeMap) { // AsRaw converts an OTLP AttributeMap to a standard go map func (am AttributeMap) AsRaw() map[string]interface{} { rawMap := make(map[string]interface{}) - am.Range(func(k string, v AttributeValue) bool { + am.Range(func(k string, v AnyValue) bool { switch v.Type() { - case AttributeValueTypeString: + case AnyValueTypeString: rawMap[k] = v.StringVal() - case AttributeValueTypeInt: + case AnyValueTypeInt: rawMap[k] = v.IntVal() - case AttributeValueTypeDouble: + case AnyValueTypeDouble: rawMap[k] = v.DoubleVal() - case AttributeValueTypeBool: + case AnyValueTypeBool: rawMap[k] = v.BoolVal() - case AttributeValueTypeBytes: + case AnyValueTypeBytes: rawMap[k] = v.BytesVal() - case AttributeValueTypeEmpty: + case AnyValueTypeEmpty: rawMap[k] = nil - case AttributeValueTypeMap: + case AnyValueTypeMap: rawMap[k] = v.MapVal().AsRaw() - case AttributeValueTypeArray: + case AnyValueTypeArray: rawMap[k] = v.SliceVal().asRaw() } return true @@ -830,23 +830,23 @@ func (am AttributeMap) AsRaw() map[string]interface{} { return rawMap } -// asRaw creates a slice out of a AttributeValueSlice. -func (es AttributeValueSlice) asRaw() []interface{} { +// asRaw creates a slice out of a AnyValueSlice. +func (es AnyValueSlice) asRaw() []interface{} { rawSlice := make([]interface{}, 0, es.Len()) for i := 0; i < es.Len(); i++ { v := es.At(i) switch v.Type() { - case AttributeValueTypeString: + case AnyValueTypeString: rawSlice = append(rawSlice, v.StringVal()) - case AttributeValueTypeInt: + case AnyValueTypeInt: rawSlice = append(rawSlice, v.IntVal()) - case AttributeValueTypeDouble: + case AnyValueTypeDouble: rawSlice = append(rawSlice, v.DoubleVal()) - case AttributeValueTypeBool: + case AnyValueTypeBool: rawSlice = append(rawSlice, v.BoolVal()) - case AttributeValueTypeBytes: + case AnyValueTypeBytes: rawSlice = append(rawSlice, v.BytesVal()) - case AttributeValueTypeEmpty: + case AnyValueTypeEmpty: rawSlice = append(rawSlice, nil) default: rawSlice = append(rawSlice, "") diff --git a/model/internal/pdata/common_test.go b/model/internal/pdata/common_test.go index c1cfd772cf6..cb512afa2a8 100644 --- a/model/internal/pdata/common_test.go +++ b/model/internal/pdata/common_test.go @@ -27,61 +27,61 @@ import ( ) func TestAttributeValue(t *testing.T) { - v := NewAttributeValueString("abc") - assert.EqualValues(t, AttributeValueTypeString, v.Type()) + v := NewAnyValueString("abc") + assert.EqualValues(t, AnyValueTypeString, v.Type()) assert.EqualValues(t, "abc", v.StringVal()) - v = NewAttributeValueInt(123) - assert.EqualValues(t, AttributeValueTypeInt, v.Type()) + v = NewAnyValueInt(123) + assert.EqualValues(t, AnyValueTypeInt, v.Type()) assert.EqualValues(t, 123, v.IntVal()) - v = NewAttributeValueDouble(3.4) - assert.EqualValues(t, AttributeValueTypeDouble, v.Type()) + v = NewAnyValueDouble(3.4) + assert.EqualValues(t, AnyValueTypeDouble, v.Type()) assert.EqualValues(t, 3.4, v.DoubleVal()) - v = NewAttributeValueBool(true) - assert.EqualValues(t, AttributeValueTypeBool, v.Type()) + v = NewAnyValueBool(true) + assert.EqualValues(t, AnyValueTypeBool, v.Type()) assert.True(t, v.BoolVal()) - v = NewAttributeValueEmpty() - assert.EqualValues(t, AttributeValueTypeEmpty, v.Type()) + v = NewAnyValueEmpty() + assert.EqualValues(t, AnyValueTypeEmpty, v.Type()) v.SetStringVal("abc") - assert.EqualValues(t, AttributeValueTypeString, v.Type()) + assert.EqualValues(t, AnyValueTypeString, v.Type()) assert.EqualValues(t, "abc", v.StringVal()) v.SetIntVal(123) - assert.EqualValues(t, AttributeValueTypeInt, v.Type()) + assert.EqualValues(t, AnyValueTypeInt, v.Type()) assert.EqualValues(t, 123, v.IntVal()) v.SetDoubleVal(3.4) - assert.EqualValues(t, AttributeValueTypeDouble, v.Type()) + assert.EqualValues(t, AnyValueTypeDouble, v.Type()) assert.EqualValues(t, 3.4, v.DoubleVal()) v.SetBoolVal(true) - assert.EqualValues(t, AttributeValueTypeBool, v.Type()) + assert.EqualValues(t, AnyValueTypeBool, v.Type()) assert.True(t, v.BoolVal()) bytesValue := []byte{1, 2, 3, 4} - v = NewAttributeValueBytes(bytesValue) - assert.EqualValues(t, AttributeValueTypeBytes, v.Type()) + v = NewAnyValueBytes(bytesValue) + assert.EqualValues(t, AnyValueTypeBytes, v.Type()) assert.EqualValues(t, bytesValue, v.BytesVal()) } func TestAttributeValueType(t *testing.T) { - assert.EqualValues(t, "EMPTY", AttributeValueTypeEmpty.String()) - assert.EqualValues(t, "STRING", AttributeValueTypeString.String()) - assert.EqualValues(t, "BOOL", AttributeValueTypeBool.String()) - assert.EqualValues(t, "INT", AttributeValueTypeInt.String()) - assert.EqualValues(t, "DOUBLE", AttributeValueTypeDouble.String()) - assert.EqualValues(t, "MAP", AttributeValueTypeMap.String()) - assert.EqualValues(t, "ARRAY", AttributeValueTypeArray.String()) - assert.EqualValues(t, "BYTES", AttributeValueTypeBytes.String()) + assert.EqualValues(t, "EMPTY", AnyValueTypeEmpty.String()) + assert.EqualValues(t, "STRING", AnyValueTypeString.String()) + assert.EqualValues(t, "BOOL", AnyValueTypeBool.String()) + assert.EqualValues(t, "INT", AnyValueTypeInt.String()) + assert.EqualValues(t, "DOUBLE", AnyValueTypeDouble.String()) + assert.EqualValues(t, "MAP", AnyValueTypeMap.String()) + assert.EqualValues(t, "ARRAY", AnyValueTypeArray.String()) + assert.EqualValues(t, "BYTES", AnyValueTypeBytes.String()) } func TestAttributeValueMap(t *testing.T) { - m1 := NewAttributeValueMap() - assert.Equal(t, AttributeValueTypeMap, m1.Type()) + m1 := NewAnyValueMap() + assert.Equal(t, AnyValueTypeMap, m1.Type()) assert.Equal(t, NewAttributeMap(), m1.MapVal()) assert.Equal(t, 0, m1.MapVal().Len()) @@ -89,10 +89,10 @@ func TestAttributeValueMap(t *testing.T) { assert.Equal(t, 1, m1.MapVal().Len()) got, exists := m1.MapVal().Get("double_key") assert.True(t, exists) - assert.Equal(t, NewAttributeValueDouble(123), got) + assert.Equal(t, NewAnyValueDouble(123), got) // Create a second map. - m2 := NewAttributeValueMap() + m2 := NewAnyValueMap() assert.Equal(t, 0, m2.MapVal().Len()) // Modify the source map that was inserted. @@ -100,14 +100,14 @@ func TestAttributeValueMap(t *testing.T) { assert.Equal(t, 1, m2.MapVal().Len()) got, exists = m2.MapVal().Get("key_in_child") assert.True(t, exists) - assert.Equal(t, NewAttributeValueString("somestr"), got) + assert.Equal(t, NewAnyValueString("somestr"), got) // Insert the second map as a child. This should perform a deep copy. m1.MapVal().Insert("child_map", m2) assert.EqualValues(t, 2, m1.MapVal().Len()) got, exists = m1.MapVal().Get("double_key") assert.True(t, exists) - assert.Equal(t, NewAttributeValueDouble(123), got) + assert.Equal(t, NewAnyValueDouble(123), got) got, exists = m1.MapVal().Get("child_map") assert.True(t, exists) assert.Equal(t, m2, got) @@ -117,26 +117,26 @@ func TestAttributeValueMap(t *testing.T) { assert.EqualValues(t, 1, m2.MapVal().Len()) got, exists = m2.MapVal().Get("key_in_child") assert.True(t, exists) - assert.Equal(t, NewAttributeValueString("somestr2"), got) + assert.Equal(t, NewAnyValueString("somestr2"), got) // The child map inside m1 should not be modified. childMap, childMapExists := m1.MapVal().Get("child_map") require.True(t, childMapExists) got, exists = childMap.MapVal().Get("key_in_child") require.True(t, exists) - assert.Equal(t, NewAttributeValueString("somestr"), got) + assert.Equal(t, NewAnyValueString("somestr"), got) // Now modify the inserted map (not the source) childMap.MapVal().UpdateString("key_in_child", "somestr3") assert.EqualValues(t, 1, childMap.MapVal().Len()) got, exists = childMap.MapVal().Get("key_in_child") require.True(t, exists) - assert.Equal(t, NewAttributeValueString("somestr3"), got) + assert.Equal(t, NewAnyValueString("somestr3"), got) // The source child map should not be modified. got, exists = m2.MapVal().Get("key_in_child") require.True(t, exists) - assert.Equal(t, NewAttributeValueString("somestr2"), got) + assert.Equal(t, NewAnyValueString("somestr2"), got) removed := m1.MapVal().Remove("double_key") assert.True(t, removed) @@ -152,108 +152,108 @@ func TestAttributeValueMap(t *testing.T) { // Test nil KvlistValue case for MapVal() func. orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: nil}} - m1 = AttributeValue{orig: orig} + m1 = AnyValue{orig: orig} assert.EqualValues(t, NewAttributeMap(), m1.MapVal()) } func TestNilOrigSetAttributeValue(t *testing.T) { - av := NewAttributeValueEmpty() + av := NewAnyValueEmpty() av.SetStringVal("abc") assert.EqualValues(t, "abc", av.StringVal()) - av = NewAttributeValueEmpty() + av = NewAnyValueEmpty() av.SetIntVal(123) assert.EqualValues(t, 123, av.IntVal()) - av = NewAttributeValueEmpty() + av = NewAnyValueEmpty() av.SetBoolVal(true) assert.True(t, av.BoolVal()) - av = NewAttributeValueEmpty() + av = NewAnyValueEmpty() av.SetDoubleVal(1.23) assert.EqualValues(t, 1.23, av.DoubleVal()) - av = NewAttributeValueEmpty() + av = NewAnyValueEmpty() av.SetBytesVal([]byte{1, 2, 3}) assert.Equal(t, []byte{1, 2, 3}, av.BytesVal()) } func TestAttributeValueEqual(t *testing.T) { - av1 := NewAttributeValueEmpty() - av2 := NewAttributeValueEmpty() + av1 := NewAnyValueEmpty() + av2 := NewAnyValueEmpty() assert.True(t, av1.Equal(av2)) - av2 = NewAttributeValueString("abc") + av2 = NewAnyValueString("abc") assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av1 = NewAttributeValueString("abc") + av1 = NewAnyValueString("abc") assert.True(t, av1.Equal(av2)) - av2 = NewAttributeValueString("edf") + av2 = NewAnyValueString("edf") assert.False(t, av1.Equal(av2)) - av2 = NewAttributeValueInt(123) + av2 = NewAnyValueInt(123) assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av1 = NewAttributeValueInt(234) + av1 = NewAnyValueInt(234) assert.False(t, av1.Equal(av2)) - av1 = NewAttributeValueInt(123) + av1 = NewAnyValueInt(123) assert.True(t, av1.Equal(av2)) - av2 = NewAttributeValueDouble(123) + av2 = NewAnyValueDouble(123) assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av1 = NewAttributeValueDouble(234) + av1 = NewAnyValueDouble(234) assert.False(t, av1.Equal(av2)) - av1 = NewAttributeValueDouble(123) + av1 = NewAnyValueDouble(123) assert.True(t, av1.Equal(av2)) - av2 = NewAttributeValueBool(false) + av2 = NewAnyValueBool(false) assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av1 = NewAttributeValueBool(true) + av1 = NewAnyValueBool(true) assert.False(t, av1.Equal(av2)) - av1 = NewAttributeValueBool(false) + av1 = NewAnyValueBool(false) assert.True(t, av1.Equal(av2)) - av2 = NewAttributeValueBytes([]byte{1, 2, 3}) + av2 = NewAnyValueBytes([]byte{1, 2, 3}) assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av1 = NewAttributeValueBytes([]byte{1, 2, 4}) + av1 = NewAnyValueBytes([]byte{1, 2, 4}) assert.False(t, av1.Equal(av2)) - av1 = NewAttributeValueBytes([]byte{1, 2, 3}) + av1 = NewAnyValueBytes([]byte{1, 2, 3}) assert.True(t, av1.Equal(av2)) - av1 = NewAttributeValueArray() + av1 = NewAnyValueArray() av1.SliceVal().AppendEmpty().SetIntVal(123) assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av2 = NewAttributeValueArray() + av2 = NewAnyValueArray() av2.SliceVal().AppendEmpty().SetDoubleVal(123) assert.False(t, av1.Equal(av2)) - NewAttributeValueInt(123).CopyTo(av2.SliceVal().At(0)) + NewAnyValueInt(123).CopyTo(av2.SliceVal().At(0)) assert.True(t, av1.Equal(av2)) av1.CopyTo(av2.SliceVal().AppendEmpty()) assert.False(t, av1.Equal(av2)) - av1 = NewAttributeValueMap() + av1 = NewAnyValueMap() av1.MapVal().UpsertString("foo", "bar") assert.False(t, av1.Equal(av2)) assert.False(t, av2.Equal(av1)) - av2 = NewAttributeValueMap() + av2 = NewAnyValueMap() av2.MapVal().UpsertString("foo", "bar") assert.True(t, av1.Equal(av2)) @@ -270,10 +270,10 @@ func TestNilAttributeMap(t *testing.T) { val, exist := NewAttributeMap().Get("test_key") assert.False(t, exist) - assert.EqualValues(t, AttributeValue{nil}, val) + assert.EqualValues(t, AnyValue{nil}, val) insertMap := NewAttributeMap() - insertMap.Insert("k", NewAttributeValueString("v")) + insertMap.Insert("k", NewAnyValueString("v")) assert.EqualValues(t, generateTestAttributeMap(), insertMap) insertMapString := NewAttributeMap() @@ -301,7 +301,7 @@ func TestNilAttributeMap(t *testing.T) { assert.EqualValues(t, generateTestBytesAttributeMap(), insertMapBytes) updateMap := NewAttributeMap() - updateMap.Update("k", NewAttributeValueString("v")) + updateMap.Update("k", NewAnyValueString("v")) assert.EqualValues(t, NewAttributeMap(), updateMap) updateMapString := NewAttributeMap() @@ -325,7 +325,7 @@ func TestNilAttributeMap(t *testing.T) { assert.EqualValues(t, NewAttributeMap(), updateMapBytes) upsertMap := NewAttributeMap() - upsertMap.Upsert("k", NewAttributeValueString("v")) + upsertMap.Upsert("k", NewAnyValueString("v")) assert.EqualValues(t, generateTestAttributeMap(), upsertMap) upsertMapString := NewAttributeMap() @@ -373,156 +373,156 @@ func TestAttributeMapWithEmpty(t *testing.T) { } val, exist := sm.Get("test_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "test_value", val.StringVal()) val, exist = sm.Get("test_key2") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeEmpty, val.Type()) + assert.EqualValues(t, AnyValueTypeEmpty, val.Type()) assert.EqualValues(t, "", val.StringVal()) - sm.Insert("other_key", NewAttributeValueString("other_value")) + sm.Insert("other_key", NewAnyValueString("other_value")) val, exist = sm.Get("other_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) sm.InsertString("other_key_string", "other_value") val, exist = sm.Get("other_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) sm.InsertInt("other_key_int", 123) val, exist = sm.Get("other_key_int") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeInt, val.Type()) + assert.EqualValues(t, AnyValueTypeInt, val.Type()) assert.EqualValues(t, 123, val.IntVal()) sm.InsertDouble("other_key_double", 1.23) val, exist = sm.Get("other_key_double") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeDouble, val.Type()) + assert.EqualValues(t, AnyValueTypeDouble, val.Type()) assert.EqualValues(t, 1.23, val.DoubleVal()) sm.InsertBool("other_key_bool", true) val, exist = sm.Get("other_key_bool") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBool, val.Type()) + assert.EqualValues(t, AnyValueTypeBool, val.Type()) assert.True(t, val.BoolVal()) sm.InsertBytes("other_key_bytes", []byte{1, 2, 3}) val, exist = sm.Get("other_key_bytes") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBytes, val.Type()) + assert.EqualValues(t, AnyValueTypeBytes, val.Type()) assert.EqualValues(t, []byte{1, 2, 3}, val.BytesVal()) - sm.Update("other_key", NewAttributeValueString("yet_another_value")) + sm.Update("other_key", NewAnyValueString("yet_another_value")) val, exist = sm.Get("other_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "yet_another_value", val.StringVal()) sm.UpdateString("other_key_string", "yet_another_value") val, exist = sm.Get("other_key_string") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "yet_another_value", val.StringVal()) sm.UpdateInt("other_key_int", 456) val, exist = sm.Get("other_key_int") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeInt, val.Type()) + assert.EqualValues(t, AnyValueTypeInt, val.Type()) assert.EqualValues(t, 456, val.IntVal()) sm.UpdateDouble("other_key_double", 4.56) val, exist = sm.Get("other_key_double") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeDouble, val.Type()) + assert.EqualValues(t, AnyValueTypeDouble, val.Type()) assert.EqualValues(t, 4.56, val.DoubleVal()) sm.UpdateBool("other_key_bool", false) val, exist = sm.Get("other_key_bool") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBool, val.Type()) + assert.EqualValues(t, AnyValueTypeBool, val.Type()) assert.False(t, val.BoolVal()) sm.UpdateBytes("other_key_bytes", []byte{4, 5, 6}) val, exist = sm.Get("other_key_bytes") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBytes, val.Type()) + assert.EqualValues(t, AnyValueTypeBytes, val.Type()) assert.EqualValues(t, []byte{4, 5, 6}, val.BytesVal()) - sm.Upsert("other_key", NewAttributeValueString("other_value")) + sm.Upsert("other_key", NewAnyValueString("other_value")) val, exist = sm.Get("other_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) sm.UpsertString("other_key_string", "other_value") val, exist = sm.Get("other_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) sm.UpsertInt("other_key_int", 123) val, exist = sm.Get("other_key_int") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeInt, val.Type()) + assert.EqualValues(t, AnyValueTypeInt, val.Type()) assert.EqualValues(t, 123, val.IntVal()) sm.UpsertDouble("other_key_double", 1.23) val, exist = sm.Get("other_key_double") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeDouble, val.Type()) + assert.EqualValues(t, AnyValueTypeDouble, val.Type()) assert.EqualValues(t, 1.23, val.DoubleVal()) sm.UpsertBool("other_key_bool", true) val, exist = sm.Get("other_key_bool") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBool, val.Type()) + assert.EqualValues(t, AnyValueTypeBool, val.Type()) assert.True(t, val.BoolVal()) sm.UpsertBytes("other_key_bytes", []byte{7, 8, 9}) val, exist = sm.Get("other_key_bytes") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBytes, val.Type()) + assert.EqualValues(t, AnyValueTypeBytes, val.Type()) assert.EqualValues(t, []byte{7, 8, 9}, val.BytesVal()) - sm.Upsert("yet_another_key", NewAttributeValueString("yet_another_value")) + sm.Upsert("yet_another_key", NewAnyValueString("yet_another_value")) val, exist = sm.Get("yet_another_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "yet_another_value", val.StringVal()) sm.UpsertString("yet_another_key_string", "yet_another_value") val, exist = sm.Get("yet_another_key_string") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "yet_another_value", val.StringVal()) sm.UpsertInt("yet_another_key_int", 456) val, exist = sm.Get("yet_another_key_int") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeInt, val.Type()) + assert.EqualValues(t, AnyValueTypeInt, val.Type()) assert.EqualValues(t, 456, val.IntVal()) sm.UpsertDouble("yet_another_key_double", 4.56) val, exist = sm.Get("yet_another_key_double") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeDouble, val.Type()) + assert.EqualValues(t, AnyValueTypeDouble, val.Type()) assert.EqualValues(t, 4.56, val.DoubleVal()) sm.UpsertBool("yet_another_key_bool", false) val, exist = sm.Get("yet_another_key_bool") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBool, val.Type()) + assert.EqualValues(t, AnyValueTypeBool, val.Type()) assert.False(t, val.BoolVal()) sm.UpsertBytes("yet_another_key_bytes", []byte{1}) val, exist = sm.Get("yet_another_key_bytes") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeBytes, val.Type()) + assert.EqualValues(t, AnyValueTypeBytes, val.Type()) assert.EqualValues(t, []byte{1}, val.BytesVal()) assert.True(t, sm.Remove("other_key")) @@ -543,12 +543,12 @@ func TestAttributeMapWithEmpty(t *testing.T) { // Test that the initial key is still there. val, exist = sm.Get("test_key") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "test_value", val.StringVal()) val, exist = sm.Get("test_key2") assert.True(t, exist) - assert.EqualValues(t, AttributeValueTypeEmpty, val.Type()) + assert.EqualValues(t, AnyValueTypeEmpty, val.Type()) assert.EqualValues(t, "", val.StringVal()) _, exist = sm.Get("test_key3") @@ -559,7 +559,7 @@ func TestAttributeMapWithEmpty(t *testing.T) { } func TestAttributeMapIterationNil(t *testing.T) { - NewAttributeMap().Range(func(k string, v AttributeValue) bool { + NewAttributeMap().Range(func(k string, v AnyValue) bool { // Fail if any element is returned t.Fail() return true @@ -567,25 +567,25 @@ func TestAttributeMapIterationNil(t *testing.T) { } func TestAttributeMap_Range(t *testing.T) { - rawMap := map[string]AttributeValue{ - "k_string": NewAttributeValueString("123"), - "k_int": NewAttributeValueInt(123), - "k_double": NewAttributeValueDouble(1.23), - "k_bool": NewAttributeValueBool(true), - "k_empty": NewAttributeValueEmpty(), - "k_bytes": NewAttributeValueBytes([]byte{}), + rawMap := map[string]AnyValue{ + "k_string": NewAnyValueString("123"), + "k_int": NewAnyValueInt(123), + "k_double": NewAnyValueDouble(1.23), + "k_bool": NewAnyValueBool(true), + "k_empty": NewAnyValueEmpty(), + "k_bytes": NewAnyValueBytes([]byte{}), } am := NewAttributeMapFromMap(rawMap) assert.Equal(t, 6, am.Len()) calls := 0 - am.Range(func(k string, v AttributeValue) bool { + am.Range(func(k string, v AnyValue) bool { calls++ return false }) assert.Equal(t, 1, calls) - am.Range(func(k string, v AttributeValue) bool { + am.Range(func(k string, v AnyValue) bool { assert.True(t, v.Equal(rawMap[k])) delete(rawMap, k) return true @@ -594,16 +594,16 @@ func TestAttributeMap_Range(t *testing.T) { } func TestAttributeMap_InitFromMap(t *testing.T) { - am := NewAttributeMapFromMap(map[string]AttributeValue(nil)) + am := NewAttributeMapFromMap(map[string]AnyValue(nil)) assert.EqualValues(t, NewAttributeMap(), am) - rawMap := map[string]AttributeValue{ - "k_string": NewAttributeValueString("123"), - "k_int": NewAttributeValueInt(123), - "k_double": NewAttributeValueDouble(1.23), - "k_bool": NewAttributeValueBool(true), - "k_null": NewAttributeValueEmpty(), - "k_bytes": NewAttributeValueBytes([]byte{1, 2, 3}), + rawMap := map[string]AnyValue{ + "k_string": NewAnyValueString("123"), + "k_int": NewAnyValueInt(123), + "k_double": NewAnyValueDouble(1.23), + "k_bool": NewAnyValueBool(true), + "k_null": NewAnyValueEmpty(), + "k_bytes": NewAnyValueBytes([]byte{1, 2, 3}), } rawOrig := []otlpcommon.KeyValue{ newAttributeKeyValueString("k_string", "123"), @@ -619,19 +619,19 @@ func TestAttributeMap_InitFromMap(t *testing.T) { func TestAttributeValue_CopyTo(t *testing.T) { // Test nil KvlistValue case for MapVal() func. - dest := NewAttributeValueEmpty() + dest := NewAnyValueEmpty() orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: nil}} - AttributeValue{orig: orig}.CopyTo(dest) + AnyValue{orig: orig}.CopyTo(dest) assert.Nil(t, dest.orig.Value.(*otlpcommon.AnyValue_KvlistValue).KvlistValue) // Test nil ArrayValue case for SliceVal() func. - dest = NewAttributeValueEmpty() + dest = NewAnyValueEmpty() orig = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: nil}} - AttributeValue{orig: orig}.CopyTo(dest) + AnyValue{orig: orig}.CopyTo(dest) assert.Nil(t, dest.orig.Value.(*otlpcommon.AnyValue_ArrayValue).ArrayValue) // Test copy empty value. - AttributeValue{orig: &otlpcommon.AnyValue{}}.CopyTo(dest) + AnyValue{orig: &otlpcommon.AnyValue{}}.CopyTo(dest) assert.Nil(t, dest.orig.Value) } @@ -656,7 +656,7 @@ func TestAttributeMap_CopyTo(t *testing.T) { } func TestAttributeValue_copyTo(t *testing.T) { - av := NewAttributeValueEmpty() + av := NewAnyValueEmpty() destVal := otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{}} av.copyTo(&destVal) assert.EqualValues(t, nil, destVal.Value) @@ -679,24 +679,24 @@ func TestAttributeMap_Update(t *testing.T) { av, exists := sm.Get("test_key") assert.True(t, exists) - assert.EqualValues(t, AttributeValueTypeString, av.Type()) + assert.EqualValues(t, AnyValueTypeString, av.Type()) assert.EqualValues(t, "test_value", av.StringVal()) av.SetIntVal(123) av2, exists := sm.Get("test_key") assert.True(t, exists) - assert.EqualValues(t, AttributeValueTypeInt, av2.Type()) + assert.EqualValues(t, AnyValueTypeInt, av2.Type()) assert.EqualValues(t, 123, av2.IntVal()) av, exists = sm.Get("test_key2") assert.True(t, exists) - assert.EqualValues(t, AttributeValueTypeEmpty, av.Type()) + assert.EqualValues(t, AnyValueTypeEmpty, av.Type()) assert.EqualValues(t, "", av.StringVal()) av.SetIntVal(123) av2, exists = sm.Get("test_key2") assert.True(t, exists) - assert.EqualValues(t, AttributeValueTypeInt, av2.Type()) + assert.EqualValues(t, AnyValueTypeInt, av2.Type()) assert.EqualValues(t, 123, av2.IntVal()) } @@ -732,19 +732,19 @@ func TestAttributeMap_Clear(t *testing.T) { } func TestAttributeMap_RemoveIf(t *testing.T) { - rawMap := map[string]AttributeValue{ - "k_string": NewAttributeValueString("123"), - "k_int": NewAttributeValueInt(123), - "k_double": NewAttributeValueDouble(1.23), - "k_bool": NewAttributeValueBool(true), - "k_empty": NewAttributeValueEmpty(), - "k_bytes": NewAttributeValueBytes([]byte{}), + rawMap := map[string]AnyValue{ + "k_string": NewAnyValueString("123"), + "k_int": NewAnyValueInt(123), + "k_double": NewAnyValueDouble(1.23), + "k_bool": NewAnyValueBool(true), + "k_empty": NewAnyValueEmpty(), + "k_bytes": NewAnyValueBytes([]byte{}), } am := NewAttributeMapFromMap(rawMap) assert.Equal(t, 6, am.Len()) - am.RemoveIf(func(key string, val AttributeValue) bool { - return key == "k_int" || val.Type() == AttributeValueTypeBool + am.RemoveIf(func(key string, val AnyValue) bool { + return key == "k_int" || val.Type() == AnyValueTypeBool }) assert.Equal(t, 4, am.Len()) _, exists := am.Get("k_string") @@ -756,8 +756,8 @@ func TestAttributeMap_RemoveIf(t *testing.T) { } func BenchmarkAttributeValue_CopyTo(b *testing.B) { - av := NewAttributeValueString("k") - c := NewAttributeValueInt(123) + av := NewAnyValueString("k") + c := NewAnyValueInt(123) b.ResetTimer() for n := 0; n < b.N; n++ { @@ -769,7 +769,7 @@ func BenchmarkAttributeValue_CopyTo(b *testing.B) { } func BenchmarkAttributeValue_SetIntVal(b *testing.B) { - av := NewAttributeValueString("k") + av := NewAnyValueString("k") b.ResetTimer() for n := 0; n < b.N; n++ { @@ -795,7 +795,7 @@ func BenchmarkAttributeMap_Range(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { numEls := 0 - am.Range(func(k string, v AttributeValue) bool { + am.Range(func(k string, v AnyValue) bool { numEls++ return true }) @@ -807,10 +807,10 @@ func BenchmarkAttributeMap_Range(b *testing.B) { func BenchmarkAttributeMap_RangeOverMap(b *testing.B) { const numElements = 20 - rawOrig := make(map[string]AttributeValue, numElements) + rawOrig := make(map[string]AnyValue, numElements) for i := 0; i < numElements; i++ { key := "k" + strconv.Itoa(i) - rawOrig[key] = NewAttributeValueString("v" + strconv.Itoa(i)) + rawOrig[key] = NewAnyValueString("v" + strconv.Itoa(i)) } b.ResetTimer() for n := 0; n < b.N; n++ { @@ -860,7 +860,7 @@ func BenchmarkAttributeMap_RemoveIf(b *testing.B) { m.InsertString(fmt.Sprintf("%d", j), "string value") } b.StartTimer() - m.RemoveIf(func(key string, _ AttributeValue) bool { + m.RemoveIf(func(key string, _ AnyValue) bool { _, remove := keysToRemove[key] return remove }) @@ -891,13 +891,13 @@ func BenchmarkStringMap_RangeOverMap(b *testing.B) { } } -func fillTestAttributeValue(dest AttributeValue) { +func fillTestAnyValue(dest AnyValue) { dest.SetStringVal("v") } -func generateTestAttributeValue() AttributeValue { - av := NewAttributeValueEmpty() - fillTestAttributeValue(av) +func generateTestAnyValue() AnyValue { + av := NewAnyValueEmpty() + fillTestAnyValue(av) return av } @@ -908,75 +908,75 @@ func generateTestAttributeMap() AttributeMap { } func fillTestAttributeMap(dest AttributeMap) { - NewAttributeMapFromMap(map[string]AttributeValue{ - "k": NewAttributeValueString("v"), + NewAttributeMapFromMap(map[string]AnyValue{ + "k": NewAnyValueString("v"), }).CopyTo(dest) } func generateTestEmptyAttributeMap() AttributeMap { - return NewAttributeMapFromMap(map[string]AttributeValue{ - "k": NewAttributeValueEmpty(), + return NewAttributeMapFromMap(map[string]AnyValue{ + "k": NewAnyValueEmpty(), }) } func generateTestIntAttributeMap() AttributeMap { - return NewAttributeMapFromMap(map[string]AttributeValue{ - "k": NewAttributeValueInt(123), + return NewAttributeMapFromMap(map[string]AnyValue{ + "k": NewAnyValueInt(123), }) } func generateTestDoubleAttributeMap() AttributeMap { - return NewAttributeMapFromMap(map[string]AttributeValue{ - "k": NewAttributeValueDouble(12.3), + return NewAttributeMapFromMap(map[string]AnyValue{ + "k": NewAnyValueDouble(12.3), }) } func generateTestBoolAttributeMap() AttributeMap { - return NewAttributeMapFromMap(map[string]AttributeValue{ - "k": NewAttributeValueBool(true), + return NewAttributeMapFromMap(map[string]AnyValue{ + "k": NewAnyValueBool(true), }) } func generateTestBytesAttributeMap() AttributeMap { - return NewAttributeMapFromMap(map[string]AttributeValue{ - "k": NewAttributeValueBytes([]byte{1, 2, 3, 4, 5}), + return NewAttributeMapFromMap(map[string]AnyValue{ + "k": NewAnyValueBytes([]byte{1, 2, 3, 4, 5}), }) } func TestAttributeValueArray(t *testing.T) { - a1 := NewAttributeValueArray() - assert.EqualValues(t, AttributeValueTypeArray, a1.Type()) - assert.EqualValues(t, NewAttributeValueSlice(), a1.SliceVal()) + a1 := NewAnyValueArray() + assert.EqualValues(t, AnyValueTypeArray, a1.Type()) + assert.EqualValues(t, NewAnyValueSlice(), a1.SliceVal()) assert.EqualValues(t, 0, a1.SliceVal().Len()) a1.SliceVal().AppendEmpty().SetDoubleVal(123) assert.EqualValues(t, 1, a1.SliceVal().Len()) - assert.EqualValues(t, NewAttributeValueDouble(123), a1.SliceVal().At(0)) + assert.EqualValues(t, NewAnyValueDouble(123), a1.SliceVal().At(0)) // Create a second array. - a2 := NewAttributeValueArray() + a2 := NewAnyValueArray() assert.EqualValues(t, 0, a2.SliceVal().Len()) a2.SliceVal().AppendEmpty().SetStringVal("somestr") assert.EqualValues(t, 1, a2.SliceVal().Len()) - assert.EqualValues(t, NewAttributeValueString("somestr"), a2.SliceVal().At(0)) + assert.EqualValues(t, NewAnyValueString("somestr"), a2.SliceVal().At(0)) // Insert the second array as a child. a2.CopyTo(a1.SliceVal().AppendEmpty()) assert.EqualValues(t, 2, a1.SliceVal().Len()) - assert.EqualValues(t, NewAttributeValueDouble(123), a1.SliceVal().At(0)) + assert.EqualValues(t, NewAnyValueDouble(123), a1.SliceVal().At(0)) assert.EqualValues(t, a2, a1.SliceVal().At(1)) // Check that the array was correctly inserted. childArray := a1.SliceVal().At(1) - assert.EqualValues(t, AttributeValueTypeArray, childArray.Type()) + assert.EqualValues(t, AnyValueTypeArray, childArray.Type()) assert.EqualValues(t, 1, childArray.SliceVal().Len()) v := childArray.SliceVal().At(0) - assert.EqualValues(t, AttributeValueTypeString, v.Type()) + assert.EqualValues(t, AnyValueTypeString, v.Type()) assert.EqualValues(t, "somestr", v.StringVal()) // Test nil values case for SliceVal() func. - a1 = AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: nil}}} - assert.EqualValues(t, NewAttributeValueSlice(), a1.SliceVal()) + a1 = AnyValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: nil}}} + assert.EqualValues(t, NewAnyValueSlice(), a1.SliceVal()) } func TestAttributeSliceWithNilValues(t *testing.T) { @@ -984,53 +984,53 @@ func TestAttributeSliceWithNilValues(t *testing.T) { {}, {Value: &otlpcommon.AnyValue_StringValue{StringValue: "test_value"}}, } - sm := AttributeValueSlice{ + sm := AnyValueSlice{ orig: &origWithNil, } val := sm.At(0) - assert.EqualValues(t, AttributeValueTypeEmpty, val.Type()) + assert.EqualValues(t, AnyValueTypeEmpty, val.Type()) assert.EqualValues(t, "", val.StringVal()) val = sm.At(1) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "test_value", val.StringVal()) sm.AppendEmpty().SetStringVal("other_value") val = sm.At(2) - assert.EqualValues(t, AttributeValueTypeString, val.Type()) + assert.EqualValues(t, AnyValueTypeString, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) } func TestAsString(t *testing.T) { tests := []struct { name string - input AttributeValue + input AnyValue expected string }{ { name: "string", - input: NewAttributeValueString("string value"), + input: NewAnyValueString("string value"), expected: "string value", }, { name: "int64", - input: NewAttributeValueInt(42), + input: NewAnyValueInt(42), expected: "42", }, { name: "float64", - input: NewAttributeValueDouble(1.61803399), + input: NewAnyValueDouble(1.61803399), expected: "1.61803399", }, { name: "boolean", - input: NewAttributeValueBool(true), + input: NewAnyValueBool(true), expected: "true", }, { name: "empty_map", - input: NewAttributeValueMap(), + input: NewAnyValueMap(), expected: "{}", }, { @@ -1040,7 +1040,7 @@ func TestAsString(t *testing.T) { }, { name: "empty_array", - input: NewAttributeValueArray(), + input: NewAnyValueArray(), expected: "[]", }, { @@ -1050,12 +1050,12 @@ func TestAsString(t *testing.T) { }, { name: "empty", - input: NewAttributeValueEmpty(), + input: NewAnyValueEmpty(), expected: "", }, { name: "bytes", - input: NewAttributeValueBytes([]byte("String bytes")), + input: NewAnyValueBytes([]byte("String bytes")), expected: base64.StdEncoding.EncodeToString([]byte("String bytes")), }, } @@ -1068,7 +1068,7 @@ func TestAsString(t *testing.T) { } func TestAsRaw(t *testing.T) { - arr := NewAttributeValueArray() + arr := NewAnyValueArray() arr.SliceVal().AppendEmpty().SetBoolVal(false) arr.SliceVal().AppendEmpty().SetBytesVal([]byte("test")) arr.SliceVal().AppendEmpty().SetDoubleVal(12.9) @@ -1083,15 +1083,15 @@ func TestAsRaw(t *testing.T) { { name: "asraw", input: NewAttributeMapFromMap( - map[string]AttributeValue{ + map[string]AnyValue{ "array": arr, - "bool": NewAttributeValueBool(true), - "bytes": NewAttributeValueBytes([]byte("bytes value")), - "double": NewAttributeValueDouble(1.2), - "empty": NewAttributeValueEmpty(), - "int": NewAttributeValueInt(900), - "map": NewAttributeValueMap(), - "string": NewAttributeValueString("string value"), + "bool": NewAnyValueBool(true), + "bytes": NewAnyValueBytes([]byte("bytes value")), + "double": NewAnyValueDouble(1.2), + "empty": NewAnyValueEmpty(), + "int": NewAnyValueInt(900), + "map": NewAnyValueMap(), + "string": NewAnyValueString("string value"), }, ), expected: map[string]interface{}{ @@ -1114,21 +1114,21 @@ func TestAsRaw(t *testing.T) { } } -func simpleAttributeValueMap() AttributeValue { - ret := NewAttributeValueMap() +func simpleAttributeValueMap() AnyValue { + ret := NewAnyValueMap() attrMap := ret.MapVal() attrMap.UpsertString("strKey", "strVal") attrMap.UpsertInt("intKey", 7) attrMap.UpsertDouble("floatKey", 18.6) attrMap.UpsertBool("boolKey", false) - attrMap.Upsert("nullKey", NewAttributeValueEmpty()) + attrMap.Upsert("nullKey", NewAnyValueEmpty()) attrMap.Upsert("mapKey", constructTestAttributeSubmap()) attrMap.Upsert("arrKey", constructTestAttributeSubarray()) return ret } -func simpleAttributeValueArray() AttributeValue { - ret := NewAttributeValueArray() +func simpleAttributeValueArray() AnyValue { + ret := NewAnyValueArray() attrArr := ret.SliceVal() attrArr.AppendEmpty().SetStringVal("strVal") attrArr.AppendEmpty().SetIntVal(7) @@ -1138,15 +1138,15 @@ func simpleAttributeValueArray() AttributeValue { return ret } -func constructTestAttributeSubmap() AttributeValue { - value := NewAttributeValueMap() +func constructTestAttributeSubmap() AnyValue { + value := NewAnyValueMap() value.MapVal().UpsertString("keyOne", "valOne") value.MapVal().UpsertString("keyTwo", "valTwo") return value } -func constructTestAttributeSubarray() AttributeValue { - value := NewAttributeValueArray() +func constructTestAttributeSubarray() AnyValue { + value := NewAnyValueArray() value.SliceVal().AppendEmpty().SetStringVal("strOne") value.SliceVal().AppendEmpty().SetStringVal("strTwo") return value diff --git a/model/internal/pdata/generated_common.go b/model/internal/pdata/generated_common.go index 7bf1eed43f6..611df4499da 100644 --- a/model/internal/pdata/generated_common.go +++ b/model/internal/pdata/generated_common.go @@ -77,34 +77,34 @@ func (ms InstrumentationLibrary) CopyTo(dest InstrumentationLibrary) { dest.SetVersion(ms.Version()) } -// AttributeValueSlice logically represents a slice of AttributeValue. +// AnyValueSlice logically represents a slice of AnyValue. // // This is a reference type. If passed by value and callee modifies it, the // caller will see the modification. // -// Must use NewAttributeValueSlice function to create new instances. +// Must use NewAnyValueSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type AttributeValueSlice struct { +type AnyValueSlice struct { // orig points to the slice otlpcommon.AnyValue field contained somewhere else. // We use pointer-to-slice to be able to modify it in functions like EnsureCapacity. orig *[]otlpcommon.AnyValue } -func newAttributeValueSlice(orig *[]otlpcommon.AnyValue) AttributeValueSlice { - return AttributeValueSlice{orig} +func newAnyValueSlice(orig *[]otlpcommon.AnyValue) AnyValueSlice { + return AnyValueSlice{orig} } -// NewAttributeValueSlice creates a AttributeValueSlice with 0 elements. +// NewAnyValueSlice creates a AnyValueSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewAttributeValueSlice() AttributeValueSlice { +func NewAnyValueSlice() AnyValueSlice { orig := []otlpcommon.AnyValue(nil) - return AttributeValueSlice{&orig} + return AnyValueSlice{&orig} } // Len returns the number of elements in the slice. // -// Returns "0" for a newly instance created with "NewAttributeValueSlice()". -func (es AttributeValueSlice) Len() int { +// Returns "0" for a newly instance created with "NewAnyValueSlice()". +func (es AnyValueSlice) Len() int { return len(*es.orig) } @@ -115,12 +115,12 @@ func (es AttributeValueSlice) Len() int { // e := es.At(i) // ... // Do something with the element // } -func (es AttributeValueSlice) At(ix int) AttributeValue { - return newAttributeValue(&(*es.orig)[ix]) +func (es AnyValueSlice) At(ix int) AnyValue { + return newAnyValue(&(*es.orig)[ix]) } // CopyTo copies all elements from the current slice to the dest. -func (es AttributeValueSlice) CopyTo(dest AttributeValueSlice) { +func (es AnyValueSlice) CopyTo(dest AnyValueSlice) { srcLen := es.Len() destCap := cap(*dest.orig) if srcLen <= destCap { @@ -130,7 +130,7 @@ func (es AttributeValueSlice) CopyTo(dest AttributeValueSlice) { } for i := range *es.orig { - newAttributeValue(&(*es.orig)[i]).CopyTo(newAttributeValue(&(*dest.orig)[i])) + newAnyValue(&(*es.orig)[i]).CopyTo(newAnyValue(&(*dest.orig)[i])) } } @@ -138,14 +138,14 @@ func (es AttributeValueSlice) CopyTo(dest AttributeValueSlice) { // 1. If the newCap <= cap then no change in capacity. // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // -// Here is how a new AttributeValueSlice can be initialized: -// es := NewAttributeValueSlice() +// Here is how a new AnyValueSlice can be initialized: +// es := NewAnyValueSlice() // es.EnsureCapacity(4) // for i := 0; i < 4; i++ { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es AttributeValueSlice) EnsureCapacity(newCap int) { +func (es AnyValueSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { return @@ -156,16 +156,16 @@ func (es AttributeValueSlice) EnsureCapacity(newCap int) { *es.orig = newOrig } -// AppendEmpty will append to the end of the slice an empty AttributeValue. -// It returns the newly added AttributeValue. -func (es AttributeValueSlice) AppendEmpty() AttributeValue { +// AppendEmpty will append to the end of the slice an empty AnyValue. +// It returns the newly added AnyValue. +func (es AnyValueSlice) AppendEmpty() AnyValue { *es.orig = append(*es.orig, otlpcommon.AnyValue{}) return es.At(es.Len() - 1) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. -func (es AttributeValueSlice) MoveAndAppendTo(dest AttributeValueSlice) { +func (es AnyValueSlice) MoveAndAppendTo(dest AnyValueSlice) { if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. *dest.orig = *es.orig @@ -177,7 +177,7 @@ func (es AttributeValueSlice) MoveAndAppendTo(dest AttributeValueSlice) { // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. -func (es AttributeValueSlice) RemoveIf(f func(AttributeValue) bool) { +func (es AnyValueSlice) RemoveIf(f func(AnyValue) bool) { newLen := 0 for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { diff --git a/model/internal/pdata/generated_common_test.go b/model/internal/pdata/generated_common_test.go index 990bdffd844..d4e0f6ec3f2 100644 --- a/model/internal/pdata/generated_common_test.go +++ b/model/internal/pdata/generated_common_test.go @@ -55,41 +55,41 @@ func TestInstrumentationLibrary_Version(t *testing.T) { assert.EqualValues(t, testValVersion, ms.Version()) } -func TestAttributeValueSlice(t *testing.T) { - es := NewAttributeValueSlice() +func TestAnyValueSlice(t *testing.T) { + es := NewAnyValueSlice() assert.EqualValues(t, 0, es.Len()) - es = newAttributeValueSlice(&[]otlpcommon.AnyValue{}) + es = newAnyValueSlice(&[]otlpcommon.AnyValue{}) assert.EqualValues(t, 0, es.Len()) es.EnsureCapacity(7) - emptyVal := newAttributeValue(&otlpcommon.AnyValue{}) - testVal := generateTestAttributeValue() + emptyVal := newAnyValue(&otlpcommon.AnyValue{}) + testVal := generateTestAnyValue() assert.EqualValues(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.EqualValues(t, emptyVal, el) - fillTestAttributeValue(el) + fillTestAnyValue(el) assert.EqualValues(t, testVal, el) } } -func TestAttributeValueSlice_CopyTo(t *testing.T) { - dest := NewAttributeValueSlice() +func TestAnyValueSlice_CopyTo(t *testing.T) { + dest := NewAnyValueSlice() // Test CopyTo to empty - NewAttributeValueSlice().CopyTo(dest) - assert.EqualValues(t, NewAttributeValueSlice(), dest) + NewAnyValueSlice().CopyTo(dest) + assert.EqualValues(t, NewAnyValueSlice(), dest) // Test CopyTo larger slice - generateTestAttributeValueSlice().CopyTo(dest) - assert.EqualValues(t, generateTestAttributeValueSlice(), dest) + generateTestAnyValueSlice().CopyTo(dest) + assert.EqualValues(t, generateTestAnyValueSlice(), dest) // Test CopyTo same size slice - generateTestAttributeValueSlice().CopyTo(dest) - assert.EqualValues(t, generateTestAttributeValueSlice(), dest) + generateTestAnyValueSlice().CopyTo(dest) + assert.EqualValues(t, generateTestAnyValueSlice(), dest) } -func TestAttributeValueSlice_EnsureCapacity(t *testing.T) { - es := generateTestAttributeValueSlice() +func TestAnyValueSlice_EnsureCapacity(t *testing.T) { + es := generateTestAnyValueSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpcommon.AnyValue]bool) @@ -113,24 +113,24 @@ func TestAttributeValueSlice_EnsureCapacity(t *testing.T) { assert.Equal(t, ensureLargeLen, cap(*es.orig)) } -func TestAttributeValueSlice_MoveAndAppendTo(t *testing.T) { +func TestAnyValueSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := generateTestAttributeValueSlice() - dest := NewAttributeValueSlice() - src := generateTestAttributeValueSlice() + expectedSlice := generateTestAnyValueSlice() + dest := NewAnyValueSlice() + src := generateTestAnyValueSlice() src.MoveAndAppendTo(dest) - assert.EqualValues(t, generateTestAttributeValueSlice(), dest) + assert.EqualValues(t, generateTestAnyValueSlice(), dest) assert.EqualValues(t, 0, src.Len()) assert.EqualValues(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.EqualValues(t, generateTestAttributeValueSlice(), dest) + assert.EqualValues(t, generateTestAnyValueSlice(), dest) assert.EqualValues(t, 0, src.Len()) assert.EqualValues(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - generateTestAttributeValueSlice().MoveAndAppendTo(dest) + generateTestAnyValueSlice().MoveAndAppendTo(dest) assert.EqualValues(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.EqualValues(t, expectedSlice.At(i), dest.At(i)) @@ -138,18 +138,18 @@ func TestAttributeValueSlice_MoveAndAppendTo(t *testing.T) { } } -func TestAttributeValueSlice_RemoveIf(t *testing.T) { +func TestAnyValueSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice - emptySlice := NewAttributeValueSlice() - emptySlice.RemoveIf(func(el AttributeValue) bool { + emptySlice := NewAnyValueSlice() + emptySlice.RemoveIf(func(el AnyValue) bool { t.Fail() return false }) // Test RemoveIf - filtered := generateTestAttributeValueSlice() + filtered := generateTestAnyValueSlice() pos := 0 - filtered.RemoveIf(func(el AttributeValue) bool { + filtered.RemoveIf(func(el AnyValue) bool { pos++ return pos%3 == 0 }) @@ -167,16 +167,16 @@ func fillTestInstrumentationLibrary(tv InstrumentationLibrary) { tv.SetVersion("test_version") } -func generateTestAttributeValueSlice() AttributeValueSlice { - tv := NewAttributeValueSlice() - fillTestAttributeValueSlice(tv) +func generateTestAnyValueSlice() AnyValueSlice { + tv := NewAnyValueSlice() + fillTestAnyValueSlice(tv) return tv } -func fillTestAttributeValueSlice(tv AttributeValueSlice) { +func fillTestAnyValueSlice(tv AnyValueSlice) { l := 7 tv.EnsureCapacity(l) for i := 0; i < l; i++ { - fillTestAttributeValue(tv.AppendEmpty()) + fillTestAnyValue(tv.AppendEmpty()) } } diff --git a/model/internal/pdata/generated_log.go b/model/internal/pdata/generated_log.go index ead9611de71..7bcd256ddd0 100644 --- a/model/internal/pdata/generated_log.go +++ b/model/internal/pdata/generated_log.go @@ -650,8 +650,8 @@ func (ms LogRecord) SetName(v string) { } // Body returns the body associated with this LogRecord. -func (ms LogRecord) Body() AttributeValue { - return newAttributeValue(&(*ms.orig).Body) +func (ms LogRecord) Body() AnyValue { + return newAnyValue(&(*ms.orig).Body) } // Attributes returns the Attributes associated with this LogRecord. diff --git a/model/internal/pdata/generated_log_test.go b/model/internal/pdata/generated_log_test.go index 26444c73157..90877a54471 100644 --- a/model/internal/pdata/generated_log_test.go +++ b/model/internal/pdata/generated_log_test.go @@ -499,8 +499,8 @@ func TestLogRecord_Name(t *testing.T) { func TestLogRecord_Body(t *testing.T) { ms := NewLogRecord() - fillTestAttributeValue(ms.Body()) - assert.EqualValues(t, generateTestAttributeValue(), ms.Body()) + fillTestAnyValue(ms.Body()) + assert.EqualValues(t, generateTestAnyValue(), ms.Body()) } func TestLogRecord_Attributes(t *testing.T) { @@ -599,7 +599,7 @@ func fillTestLogRecord(tv LogRecord) { tv.SetSeverityText("INFO") tv.SetSeverityNumber(SeverityNumberINFO) tv.SetName("test_name") - fillTestAttributeValue(tv.Body()) + fillTestAnyValue(tv.Body()) fillTestAttributeMap(tv.Attributes()) tv.SetDroppedAttributesCount(uint32(17)) } diff --git a/model/internal/pdata/metrics_test.go b/model/internal/pdata/metrics_test.go index 7efea71517c..90faaa00941 100644 --- a/model/internal/pdata/metrics_test.go +++ b/model/internal/pdata/metrics_test.go @@ -218,8 +218,8 @@ func TestOtlpToInternalReadOnly(t *testing.T) { assert.EqualValues(t, 1, resourceMetrics.Len()) resourceMetric := resourceMetrics.At(0) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{ - "string": NewAttributeValueString("string-resource"), + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{ + "string": NewAnyValueString("string-resource"), }), resourceMetric.Resource().Attributes()) metrics := resourceMetric.InstrumentationLibraryMetrics().At(0).Metrics() assert.EqualValues(t, 3, metrics.Len()) @@ -236,12 +236,12 @@ func TestOtlpToInternalReadOnly(t *testing.T) { assert.EqualValues(t, startTime, gaugeDataPoints.At(0).StartTimestamp()) assert.EqualValues(t, endTime, gaugeDataPoints.At(0).Timestamp()) assert.EqualValues(t, 123.1, gaugeDataPoints.At(0).DoubleVal()) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{"key0": NewAttributeValueString("value0")}), gaugeDataPoints.At(0).Attributes()) + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{"key0": NewAnyValueString("value0")}), gaugeDataPoints.At(0).Attributes()) // Second point assert.EqualValues(t, startTime, gaugeDataPoints.At(1).StartTimestamp()) assert.EqualValues(t, endTime, gaugeDataPoints.At(1).Timestamp()) assert.EqualValues(t, 456.1, gaugeDataPoints.At(1).DoubleVal()) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{"key1": NewAttributeValueString("value1")}), gaugeDataPoints.At(1).Attributes()) + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{"key1": NewAnyValueString("value1")}), gaugeDataPoints.At(1).Attributes()) // Check double metric metricDouble := metrics.At(1) @@ -257,12 +257,12 @@ func TestOtlpToInternalReadOnly(t *testing.T) { assert.EqualValues(t, startTime, sumDataPoints.At(0).StartTimestamp()) assert.EqualValues(t, endTime, sumDataPoints.At(0).Timestamp()) assert.EqualValues(t, 123.1, sumDataPoints.At(0).DoubleVal()) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{"key0": NewAttributeValueString("value0")}), sumDataPoints.At(0).Attributes()) + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{"key0": NewAnyValueString("value0")}), sumDataPoints.At(0).Attributes()) // Second point assert.EqualValues(t, startTime, sumDataPoints.At(1).StartTimestamp()) assert.EqualValues(t, endTime, sumDataPoints.At(1).Timestamp()) assert.EqualValues(t, 456.1, sumDataPoints.At(1).DoubleVal()) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{"key1": NewAttributeValueString("value1")}), sumDataPoints.At(1).Attributes()) + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{"key1": NewAnyValueString("value1")}), sumDataPoints.At(1).Attributes()) // Check histogram metric metricHistogram := metrics.At(2) @@ -278,13 +278,13 @@ func TestOtlpToInternalReadOnly(t *testing.T) { assert.EqualValues(t, startTime, histogramDataPoints.At(0).StartTimestamp()) assert.EqualValues(t, endTime, histogramDataPoints.At(0).Timestamp()) assert.EqualValues(t, []float64{1, 2}, histogramDataPoints.At(0).ExplicitBounds()) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{"key0": NewAttributeValueString("value0")}), histogramDataPoints.At(0).Attributes()) + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{"key0": NewAnyValueString("value0")}), histogramDataPoints.At(0).Attributes()) assert.EqualValues(t, []uint64{10, 15, 1}, histogramDataPoints.At(0).BucketCounts()) // Second point assert.EqualValues(t, startTime, histogramDataPoints.At(1).StartTimestamp()) assert.EqualValues(t, endTime, histogramDataPoints.At(1).Timestamp()) assert.EqualValues(t, []float64{1}, histogramDataPoints.At(1).ExplicitBounds()) - assert.EqualValues(t, NewAttributeMapFromMap(map[string]AttributeValue{"key1": NewAttributeValueString("value1")}), histogramDataPoints.At(1).Attributes()) + assert.EqualValues(t, NewAttributeMapFromMap(map[string]AnyValue{"key1": NewAnyValueString("value1")}), histogramDataPoints.At(1).Attributes()) assert.EqualValues(t, []uint64{10, 1}, histogramDataPoints.At(1).BucketCounts()) } @@ -319,7 +319,7 @@ func TestOtlpToFromInternalReadOnly(t *testing.T) { } func TestOtlpToFromInternalGaugeMutating(t *testing.T) { - newAttributes := NewAttributeMapFromMap(map[string]AttributeValue{"k": NewAttributeValueString("v")}) + newAttributes := NewAttributeMapFromMap(map[string]AnyValue{"k": NewAnyValueString("v")}) md := MetricsFromOtlp(&otlpmetrics.MetricsData{ ResourceMetrics: []*otlpmetrics.ResourceMetrics{ @@ -402,7 +402,7 @@ func TestOtlpToFromInternalGaugeMutating(t *testing.T) { } func TestOtlpToFromInternalSumMutating(t *testing.T) { - newAttributes := NewAttributeMapFromMap(map[string]AttributeValue{"k": NewAttributeValueString("v")}) + newAttributes := NewAttributeMapFromMap(map[string]AnyValue{"k": NewAnyValueString("v")}) md := MetricsFromOtlp(&otlpmetrics.MetricsData{ ResourceMetrics: []*otlpmetrics.ResourceMetrics{ @@ -487,7 +487,7 @@ func TestOtlpToFromInternalSumMutating(t *testing.T) { } func TestOtlpToFromInternalHistogramMutating(t *testing.T) { - newAttributes := NewAttributeMapFromMap(map[string]AttributeValue{"k": NewAttributeValueString("v")}) + newAttributes := NewAttributeMapFromMap(map[string]AnyValue{"k": NewAnyValueString("v")}) md := MetricsFromOtlp(&otlpmetrics.MetricsData{ ResourceMetrics: []*otlpmetrics.ResourceMetrics{ @@ -571,7 +571,7 @@ func TestOtlpToFromInternalHistogramMutating(t *testing.T) { } func TestOtlpToFromInternalExponentialHistogramMutating(t *testing.T) { - newAttributes := NewAttributeMapFromMap(map[string]AttributeValue{"k": NewAttributeValueString("v")}) + newAttributes := NewAttributeMapFromMap(map[string]AnyValue{"k": NewAnyValueString("v")}) md := MetricsFromOtlp(&otlpmetrics.MetricsData{ ResourceMetrics: []*otlpmetrics.ResourceMetrics{ diff --git a/model/pdata/common_alias.go b/model/pdata/common_alias.go index 34cd423dd1f..665052bb4e6 100644 --- a/model/pdata/common_alias.go +++ b/model/pdata/common_alias.go @@ -19,35 +19,97 @@ package pdata // import "go.opentelemetry.io/collector/model/pdata" import "go.opentelemetry.io/collector/model/internal/pdata" -// AttributeValueType is an alias for pdata.AttributeValueType type. -type AttributeValueType = pdata.AttributeValueType +// AnyValueType is an alias for pdata.AnyValueType type. +type AnyValueType = pdata.AnyValueType + +// AttributeValueType is an alias for pdata.AnyValueType type. +// Deprecated: [v0.47.0] Use AnyValueType instead +type AttributeValueType = pdata.AnyValueType const ( - AttributeValueTypeEmpty = pdata.AttributeValueTypeEmpty - AttributeValueTypeString = pdata.AttributeValueTypeString - AttributeValueTypeInt = pdata.AttributeValueTypeInt - AttributeValueTypeDouble = pdata.AttributeValueTypeDouble - AttributeValueTypeBool = pdata.AttributeValueTypeBool - AttributeValueTypeMap = pdata.AttributeValueTypeMap - AttributeValueTypeArray = pdata.AttributeValueTypeArray - AttributeValueTypeBytes = pdata.AttributeValueTypeBytes + AnyValueTypeEmpty = pdata.AnyValueTypeEmpty + AnyValueTypeString = pdata.AnyValueTypeString + AnyValueTypeInt = pdata.AnyValueTypeInt + AnyValueTypeDouble = pdata.AnyValueTypeDouble + AnyValueTypeBool = pdata.AnyValueTypeBool + AnyValueTypeMap = pdata.AnyValueTypeMap + AnyValueTypeArray = pdata.AnyValueTypeArray + AnyValueTypeBytes = pdata.AnyValueTypeBytes + + // Deprecated: [v0.47.0] Use AnyValueTypeEmpty instead + AttributeValueTypeEmpty = pdata.AnyValueTypeEmpty + + // Deprecated: [v0.47.0] Use AnyValueTypeString instead + AttributeValueTypeString = pdata.AnyValueTypeString + + // Deprecated: [v0.47.0] Use AnyValueTypeInt instead + AttributeValueTypeInt = pdata.AnyValueTypeInt + + // Deprecated: [v0.47.0] Use AnyValueTypeDouble instead + AttributeValueTypeDouble = pdata.AnyValueTypeDouble + + // Deprecated: [v0.47.0] Use AnyValueTypeBool instead + AttributeValueTypeBool = pdata.AnyValueTypeBool + + // Deprecated: [v0.47.0] Use AnyValueTypeMap instead + AttributeValueTypeMap = pdata.AnyValueTypeMap + + // Deprecated: [v0.47.0] Use AnyValueTypeArray instead + AttributeValueTypeArray = pdata.AnyValueTypeArray + + // Deprecated: [v0.47.0] Use AnyValueTypeBytes instead + AttributeValueTypeBytes = pdata.AnyValueTypeBytes ) -// AttributeValue is an alias for pdata.AttributeValue struct. -type AttributeValue = pdata.AttributeValue +// AnyValue is an alias for pdata.AnyValue struct. +type AnyValue = pdata.AnyValue + +// AttributeValue is an alias for pdata.AnyValue struct. +// Deprecated: [v0.47.0] Use AnyValue instead +type AttributeValue = pdata.AnyValue -// Aliases for functions to create pdata.AttributeValue. +// Aliases for functions to create pdata.AnyValue. var ( - NewAttributeValueEmpty = pdata.NewAttributeValueEmpty - NewAttributeValueString = pdata.NewAttributeValueString - NewAttributeValueInt = pdata.NewAttributeValueInt - NewAttributeValueDouble = pdata.NewAttributeValueDouble - NewAttributeValueBool = pdata.NewAttributeValueBool - NewAttributeValueMap = pdata.NewAttributeValueMap - NewAttributeValueArray = pdata.NewAttributeValueArray - NewAttributeValueBytes = pdata.NewAttributeValueBytes + NewAnyValueEmpty = pdata.NewAnyValueEmpty + NewAnyValueString = pdata.NewAnyValueString + NewAnyValueInt = pdata.NewAnyValueInt + NewAnyValueDouble = pdata.NewAnyValueDouble + NewAnyValueBool = pdata.NewAnyValueBool + NewAnyValueMap = pdata.NewAnyValueMap + NewAnyValueArray = pdata.NewAnyValueArray + NewAnyValueBytes = pdata.NewAnyValueBytes + + // Deprecated: [v0.47.0] Use NewAnyValueEmpty instead + NewAttributeValueEmpty = pdata.NewAnyValueEmpty + + // Deprecated: [v0.47.0] Use NewAnyValueString instead + NewAttributeValueString = pdata.NewAnyValueString + + // Deprecated: [v0.47.0] Use NewAnyValueInt instead + NewAttributeValueInt = pdata.NewAnyValueInt + + // Deprecated: [v0.47.0] Use NewAnyValueDouble instead + NewAttributeValueDouble = pdata.NewAnyValueDouble + + // Deprecated: [v0.47.0] Use NewAnyValueBool instead + NewAttributeValueBool = pdata.NewAnyValueBool + + // Deprecated: [v0.47.0] Use NewAnyValueMap instead + NewAttributeValueMap = pdata.NewAnyValueMap + + // Deprecated: [v0.47.0] Use NewAnyValueArray instead + NewAttributeValueArray = pdata.NewAnyValueArray + + // Deprecated: [v0.47.0] Use NewAnyValueBytes instead + NewAttributeValueBytes = pdata.NewAnyValueBytes ) +// AttributeValueSlice is an alias for pdata.AnyValueSlice struct. +type AttributeValueSlice = pdata.AnyValueSlice + +// NewAttributeValueSlice is an alias for a function to create AnyValueSlice. +var NewAttributeValueSlice = pdata.NewAnyValueSlice + // AttributeMap is an alias for pdata.AttributeMap struct. type AttributeMap = pdata.AttributeMap diff --git a/model/pdata/generated_common_alias.go b/model/pdata/generated_common_alias.go index 309ca05036a..4b2236d1462 100644 --- a/model/pdata/generated_common_alias.go +++ b/model/pdata/generated_common_alias.go @@ -25,8 +25,8 @@ type InstrumentationLibrary = pdata.InstrumentationLibrary // NewInstrumentationLibrary is an alias for a function to create a new empty InstrumentationLibrary. var NewInstrumentationLibrary = pdata.NewInstrumentationLibrary -// AttributeValueSlice is an alias for pdata.AttributeValueSlice struct. -type AttributeValueSlice = pdata.AttributeValueSlice +// AnyValueSlice is an alias for pdata.AnyValueSlice struct. +type AnyValueSlice = pdata.AnyValueSlice -// NewAttributeValueSlice is an alias for a function to create AttributeValueSlice. -var NewAttributeValueSlice = pdata.NewAttributeValueSlice +// NewAnyValueSlice is an alias for a function to create AnyValueSlice. +var NewAnyValueSlice = pdata.NewAnyValueSlice