diff --git a/cmd/pdatagen/internal/base_fields.go b/cmd/pdatagen/internal/base_fields.go index dbdae03ea3c..3a487491d33 100644 --- a/cmd/pdatagen/internal/base_fields.go +++ b/cmd/pdatagen/internal/base_fields.go @@ -126,7 +126,7 @@ type baseField interface { type sliceField struct { fieldName string originFieldName string - returnSlice *sliceStruct + returnSlice baseSlice } func (sf *sliceField) generateAccessors(ms baseStruct, sb *strings.Builder) { @@ -137,7 +137,7 @@ func (sf *sliceField) generateAccessors(ms baseStruct, sb *strings.Builder) { case "fieldName": return sf.fieldName case "returnType": - return sf.returnSlice.structName + return sf.returnSlice.getName() case "originFieldName": return sf.originFieldName default: @@ -154,7 +154,7 @@ func (sf *sliceField) generateAccessorsTest(ms baseStruct, sb *strings.Builder) case "fieldName": return sf.fieldName case "returnType": - return sf.returnSlice.structName + return sf.returnSlice.getName() default: panic(name) } @@ -162,7 +162,7 @@ func (sf *sliceField) generateAccessorsTest(ms baseStruct, sb *strings.Builder) } func (sf *sliceField) generateSetWithTestValue(sb *strings.Builder) { - sb.WriteString("\tfillTest" + sf.returnSlice.structName + "(tv." + sf.fieldName + "())") + sb.WriteString("\tfillTest" + sf.returnSlice.getName() + "(tv." + sf.fieldName + "())") } func (sf *sliceField) generateCopyToValue(sb *strings.Builder) { diff --git a/cmd/pdatagen/internal/base_slices.go b/cmd/pdatagen/internal/base_slices.go new file mode 100644 index 00000000000..47be3ebd7e3 --- /dev/null +++ b/cmd/pdatagen/internal/base_slices.go @@ -0,0 +1,619 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package internal + +import ( + "os" + "strings" +) + +const slicePtrTemplate = `// ${structName} logically represents a slice of ${elementName}. +// +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use New${structName} function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ${structName} struct { + // orig points to the slice ${originName} field contained somewhere else. + // We use pointer-to-slice to be able to modify it in functions like Resize. + orig *[]*${originName} +} + +func new${structName}(orig *[]*${originName}) ${structName} { + return ${structName}{orig} +} + +// New${structName} creates a ${structName} with 0 elements. +// Can use "Resize" to initialize with a given length. +func New${structName}() ${structName} { + orig := []*${originName}(nil) + return ${structName}{&orig} +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "New${structName}()". +func (es ${structName}) Len() int { + return len(*es.orig) +} + +// At returns the element at the given index. +// +// This function is used mostly for iterating over all the values in the slice: +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } +func (es ${structName}) At(ix int) ${elementName} { + return new${elementName}(&(*es.orig)[ix]) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es ${structName}) MoveAndAppendTo(dest ${structName}) { + if *dest.orig == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.orig = *es.orig + } else { + *dest.orig = append(*dest.orig, *es.orig...) + } + *es.orig = nil +} + +// CopyTo copies all elements from the current slice to the dest. +func (es ${structName}) CopyTo(dest ${structName}) { + srcLen := es.Len() + destCap := cap(*dest.orig) + if srcLen <= destCap { + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&(*dest.orig)[i])) + } + return + } + origs := make([]${originName}, srcLen) + wrappers := make([]*${originName}, srcLen) + for i := range *es.orig { + wrappers[i] = &origs[i] + new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&wrappers[i])) + } + *dest.orig = wrappers +} + +// Resize is an operation that resizes the slice: +// 1. If the newLen <= len then equivalent with slice[0:newLen:cap]. +// 2. If the newLen > len then (newLen - cap) empty elements will be appended to the slice. +// +// Here is how a new ${structName} can be initialized: +// es := New${structName}() +// es.Resize(4) +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// // Here should set all the values for e. +// } +func (es ${structName}) Resize(newLen int) { + oldLen := len(*es.orig) + oldCap := cap(*es.orig) + if newLen <= oldLen { + *es.orig = (*es.orig)[:newLen:oldCap] + return + } + + if newLen > oldCap { + newOrig := make([]*${originName}, oldLen, newLen) + copy(newOrig, *es.orig) + *es.orig = newOrig + } + + // Add extra empty elements to the array. + extraOrigs := make([]${originName}, newLen-oldLen) + for i := range extraOrigs { + *es.orig = append(*es.orig, &extraOrigs[i]) + } +} + +// Append will increase the length of the ${structName} by one and set the +// given ${elementName} at that new position. The original ${elementName} +// could still be referenced so do not reuse it after passing it to this +// method. +func (es ${structName}) Append(e ${elementName}) { + *es.orig = append(*es.orig, *e.orig) +}` + +const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { + es := New${structName}() + assert.EqualValues(t, 0, es.Len()) + es = new${structName}(&[]*${originName}{}) + assert.EqualValues(t, 0, es.Len()) + + es.Resize(7) + emptyVal := New${elementName}() + emptyVal.InitEmpty() + testVal := generateTest${elementName}() + assert.EqualValues(t, 7, es.Len()) + for i := 0; i < es.Len(); i++ { + assert.EqualValues(t, emptyVal, es.At(i)) + fillTest${elementName}(es.At(i)) + assert.EqualValues(t, testVal, es.At(i)) + } +} + +func Test${structName}_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := generateTest${structName}() + dest := New${structName}() + src := generateTest${structName}() + src.MoveAndAppendTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) + assert.EqualValues(t, 0, src.Len()) + assert.EqualValues(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) + assert.EqualValues(t, 0, src.Len()) + assert.EqualValues(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + generateTest${structName}().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)) + assert.EqualValues(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func Test${structName}_CopyTo(t *testing.T) { + dest := New${structName}() + // Test CopyTo to empty + New${structName}().CopyTo(dest) + assert.EqualValues(t, New${structName}(), dest) + + // Test CopyTo larger slice + generateTest${structName}().CopyTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) + + // Test CopyTo same size slice + generateTest${structName}().CopyTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) +} + +func Test${structName}_Resize(t *testing.T) { + es := generateTest${structName}() + emptyVal := New${elementName}() + emptyVal.InitEmpty() + // Test Resize less elements. + const resizeSmallLen = 4 + expectedEs := make(map[*${originName}]bool, resizeSmallLen) + for i := 0; i < resizeSmallLen; i++ { + expectedEs[*(es.At(i).orig)] = true + } + assert.Equal(t, resizeSmallLen, len(expectedEs)) + es.Resize(resizeSmallLen) + assert.Equal(t, resizeSmallLen, es.Len()) + foundEs := make(map[*${originName}]bool, resizeSmallLen) + for i := 0; i < es.Len(); i++ { + foundEs[*(es.At(i).orig)] = true + } + assert.EqualValues(t, expectedEs, foundEs) + + // Test Resize more elements. + const resizeLargeLen = 7 + oldLen := es.Len() + expectedEs = make(map[*${originName}]bool, oldLen) + for i := 0; i < oldLen; i++ { + expectedEs[*(es.At(i).orig)] = true + } + assert.Equal(t, oldLen, len(expectedEs)) + es.Resize(resizeLargeLen) + assert.Equal(t, resizeLargeLen, es.Len()) + foundEs = make(map[*${originName}]bool, oldLen) + for i := 0; i < oldLen; i++ { + foundEs[*(es.At(i).orig)] = true + } + assert.EqualValues(t, expectedEs, foundEs) + for i := oldLen; i < resizeLargeLen; i++ { + assert.EqualValues(t, emptyVal, es.At(i)) + } + + // Test Resize 0 elements. + es.Resize(0) + assert.Equal(t, 0, es.Len()) +} + +func Test${structName}_Append(t *testing.T) { + es := generateTest${structName}() + emptyVal := New${elementName}() + emptyVal.InitEmpty() + + es.Append(emptyVal) + assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + + emptyVal2 := New${elementName}() + emptyVal2.InitEmpty() + + es.Append(emptyVal2) + assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + + assert.Equal(t, 9, es.Len()) +}` + +const slicePtrGenerateTest = `func generateTest${structName}() ${structName} { + tv := New${structName}() + fillTest${structName}(tv) + return tv +} + +func fillTest${structName}(tv ${structName}) { + tv.Resize(7) + for i := 0; i < tv.Len(); i++ { + fillTest${elementName}(tv.At(i)) + } +}` + +const sliceValueTemplate = `// ${structName} logically represents a slice of ${elementName}. +// +// This is a reference type, if passed by value and callee modifies it the +// caller will see the modification. +// +// Must use New${structName} function to create new instances. +// Important: zero-initialized instance is not valid for use. +type ${structName} struct { + // orig points to the slice ${originName} field contained somewhere else. + // We use pointer-to-slice to be able to modify it in functions like Resize. + orig *[]${originName} +} + +func new${structName}(orig *[]${originName}) ${structName} { + return ${structName}{orig} +} + +// New${structName} creates a ${structName} with 0 elements. +// Can use "Resize" to initialize with a given length. +func New${structName}() ${structName} { + orig := []${originName}(nil) + return ${structName}{&orig} +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "New${structName}()". +func (es ${structName}) Len() int { + return len(*es.orig) +} + +// At returns the element at the given index. +// +// This function is used mostly for iterating over all the values in the slice: +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } +func (es ${structName}) At(ix int) ${elementName} { + return new${elementName}(&(*es.orig)[ix]) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es ${structName}) MoveAndAppendTo(dest ${structName}) { + if *dest.orig == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.orig = *es.orig + } else { + *dest.orig = append(*dest.orig, *es.orig...) + } + *es.orig = nil +} + +// CopyTo copies all elements from the current slice to the dest. +func (es ${structName}) CopyTo(dest ${structName}) { + srcLen := es.Len() + destCap := cap(*dest.orig) + if srcLen <= destCap { + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + } else { + (*dest.orig) = make([]${originName}, srcLen) + } + + for i := range *es.orig { + new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&(*dest.orig)[i])) + } +} + +// Resize is an operation that resizes the slice: +// 1. If the newLen <= len then equivalent with slice[0:newLen:cap]. +// 2. If the newLen > len then (newLen - cap) empty elements will be appended to the slice. +// +// Here is how a new ${structName} can be initialized: +// es := New${structName}() +// es.Resize(4) +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// // Here should set all the values for e. +// } +func (es ${structName}) Resize(newLen int) { + oldLen := len(*es.orig) + oldCap := cap(*es.orig) + if newLen <= oldLen { + *es.orig = (*es.orig)[:newLen:oldCap] + return + } + + if newLen > oldCap { + newOrig := make([]${originName}, oldLen, newLen) + copy(newOrig, *es.orig) + *es.orig = newOrig + } + + // Add extra empty elements to the array. + empty := otlpcommon.AnyValue{} + for i := oldLen; i < newLen; i++ { + *es.orig = append(*es.orig, empty) + } +} + +// Append will increase the length of the ${structName} by one and set the +// given ${elementName} at that new position. The original ${elementName} +// could still be referenced so do not reuse it after passing it to this +// method. +func (es ${structName}) Append(e ${elementName}) { + *es.orig = append(*es.orig, *e.orig) +}` + +const sliceValueTestTemplate = `func Test${structName}(t *testing.T) { + es := New${structName}() + assert.EqualValues(t, 0, es.Len()) + es = new${structName}(&[]${originName}{}) + assert.EqualValues(t, 0, es.Len()) + + es.Resize(7) + emptyVal := New${elementName}() + emptyVal.InitEmpty() + testVal := generateTest${elementName}() + assert.EqualValues(t, 7, es.Len()) + for i := 0; i < es.Len(); i++ { + assert.EqualValues(t, emptyVal, es.At(i)) + fillTest${elementName}(es.At(i)) + assert.EqualValues(t, testVal, es.At(i)) + } +} + +func Test${structName}_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := generateTest${structName}() + dest := New${structName}() + src := generateTest${structName}() + src.MoveAndAppendTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) + assert.EqualValues(t, 0, src.Len()) + assert.EqualValues(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) + assert.EqualValues(t, 0, src.Len()) + assert.EqualValues(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + generateTest${structName}().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)) + assert.EqualValues(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func Test${structName}_CopyTo(t *testing.T) { + dest := New${structName}() + // Test CopyTo to empty + New${structName}().CopyTo(dest) + assert.EqualValues(t, New${structName}(), dest) + + // Test CopyTo larger slice + generateTest${structName}().CopyTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) + + // Test CopyTo same size slice + generateTest${structName}().CopyTo(dest) + assert.EqualValues(t, generateTest${structName}(), dest) +} + +func Test${structName}_Resize(t *testing.T) { + es := generateTest${structName}() + emptyVal := New${elementName}() + emptyVal.InitEmpty() + // Test Resize less elements. + const resizeSmallLen = 4 + expectedEs := make(map[*${originName}]bool, resizeSmallLen) + for i := 0; i < resizeSmallLen; i++ { + expectedEs[es.At(i).orig] = true + } + assert.Equal(t, resizeSmallLen, len(expectedEs)) + es.Resize(resizeSmallLen) + assert.Equal(t, resizeSmallLen, es.Len()) + foundEs := make(map[*${originName}]bool, resizeSmallLen) + for i := 0; i < es.Len(); i++ { + foundEs[es.At(i).orig] = true + } + assert.EqualValues(t, expectedEs, foundEs) + + // Test Resize more elements. + const resizeLargeLen = 7 + oldLen := es.Len() + expectedEs = make(map[*${originName}]bool, oldLen) + for i := 0; i < oldLen; i++ { + expectedEs[es.At(i).orig] = true + } + assert.Equal(t, oldLen, len(expectedEs)) + es.Resize(resizeLargeLen) + assert.Equal(t, resizeLargeLen, es.Len()) + foundEs = make(map[*${originName}]bool, oldLen) + for i := 0; i < oldLen; i++ { + foundEs[es.At(i).orig] = true + } + assert.EqualValues(t, expectedEs, foundEs) + for i := oldLen; i < resizeLargeLen; i++ { + assert.EqualValues(t, emptyVal, es.At(i)) + } + + // Test Resize 0 elements. + es.Resize(0) + assert.Equal(t, 0, es.Len()) +} + +func Test${structName}_Append(t *testing.T) { + es := generateTest${structName}() + emptyVal := New${elementName}() + emptyVal.InitEmpty() + + es.Append(emptyVal) + assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + + emptyVal2 := New${elementName}() + emptyVal2.InitEmpty() + + es.Append(emptyVal2) + assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + + assert.Equal(t, 9, es.Len()) +}` + +const sliceValueGenerateTest = `func generateTest${structName}() ${structName} { + tv := New${structName}() + fillTest${structName}(tv) + return tv +} + +func fillTest${structName}(tv ${structName}) { + tv.Resize(7) + for i := 0; i < tv.Len(); i++ { + fillTest${elementName}(tv.At(i)) + } +}` + +type baseSlice interface { + getName() string +} + +// Will generate code only for a slice of pointer fields. +type sliceOfPtrs struct { + structName string + element *messagePtrStruct +} + +func (ss *sliceOfPtrs) getName() string { + return ss.structName +} + +func (ss *sliceOfPtrs) generateStruct(sb *strings.Builder) { + sb.WriteString(os.Expand(slicePtrTemplate, func(name string) string { + switch name { + case "structName": + return ss.structName + case "elementName": + return ss.element.structName + case "originName": + return ss.element.originFullName + default: + panic(name) + } + })) +} + +func (ss *sliceOfPtrs) generateTests(sb *strings.Builder) { + sb.WriteString(os.Expand(slicePtrTestTemplate, func(name string) string { + switch name { + case "structName": + return ss.structName + case "elementName": + return ss.element.structName + case "originName": + return ss.element.originFullName + default: + panic(name) + } + })) +} + +func (ss *sliceOfPtrs) generateTestValueHelpers(sb *strings.Builder) { + sb.WriteString(os.Expand(slicePtrGenerateTest, func(name string) string { + switch name { + case "structName": + return ss.structName + case "elementName": + return ss.element.structName + default: + panic(name) + } + })) +} + +var _ baseStruct = (*sliceOfPtrs)(nil) + +// Will generate code only for a slice of value fields. +type sliceOfValues struct { + structName string + element *messageValueStruct +} + +func (ss *sliceOfValues) getName() string { + return ss.structName +} + +func (ss *sliceOfValues) generateStruct(sb *strings.Builder) { + sb.WriteString(os.Expand(sliceValueTemplate, func(name string) string { + switch name { + case "structName": + return ss.structName + case "elementName": + return ss.element.structName + case "originName": + return ss.element.originFullName + default: + panic(name) + } + })) +} + +func (ss *sliceOfValues) generateTests(sb *strings.Builder) { + sb.WriteString(os.Expand(sliceValueTestTemplate, func(name string) string { + switch name { + case "structName": + return ss.structName + case "elementName": + return ss.element.structName + case "originName": + return ss.element.originFullName + default: + panic(name) + } + })) +} + +func (ss *sliceOfValues) generateTestValueHelpers(sb *strings.Builder) { + sb.WriteString(os.Expand(sliceValueGenerateTest, func(name string) string { + switch name { + case "structName": + return ss.structName + case "elementName": + return ss.element.structName + default: + panic(name) + } + })) +} + +var _ baseStruct = (*sliceOfValues)(nil) diff --git a/cmd/pdatagen/internal/base_structs.go b/cmd/pdatagen/internal/base_structs.go index 8d753d584b1..15aa1c858c2 100644 --- a/cmd/pdatagen/internal/base_structs.go +++ b/cmd/pdatagen/internal/base_structs.go @@ -19,251 +19,6 @@ import ( "strings" ) -const sliceTemplate = `// ${structName} logically represents a slice of ${elementName}. -// -// This is a reference type, if passed by value and callee modifies it the -// caller will see the modification. -// -// Must use New${structName} function to create new instances. -// Important: zero-initialized instance is not valid for use. -type ${structName} struct { - // orig points to the slice ${originName} field contained somewhere else. - // We use pointer-to-slice to be able to modify it in functions like Resize. - orig *[]*${originName} -} - -func new${structName}(orig *[]*${originName}) ${structName} { - return ${structName}{orig} -} - -// New${structName} creates a ${structName} with 0 elements. -// Can use "Resize" to initialize with a given length. -func New${structName}() ${structName} { - orig := []*${originName}(nil) - return ${structName}{&orig} -} - -// Len returns the number of elements in the slice. -// -// Returns "0" for a newly instance created with "New${structName}()". -func (es ${structName}) Len() int { - return len(*es.orig) -} - -// At returns the element at the given index. -// -// This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } -func (es ${structName}) At(ix int) ${elementName} { - return new${elementName}(&(*es.orig)[ix]) -} - -// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. -// The current slice will be cleared. -func (es ${structName}) MoveAndAppendTo(dest ${structName}) { - if *dest.orig == nil { - // We can simply move the entire vector and avoid any allocations. - *dest.orig = *es.orig - } else { - *dest.orig = append(*dest.orig, *es.orig...) - } - *es.orig = nil -} - -// CopyTo copies all elements from the current slice to the dest. -func (es ${structName}) CopyTo(dest ${structName}) { - srcLen := es.Len() - destCap := cap(*dest.orig) - if srcLen <= destCap { - (*dest.orig) = (*dest.orig)[:srcLen:destCap] - for i := range *es.orig { - new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&(*dest.orig)[i])) - } - return - } - origs := make([]${originName}, srcLen) - wrappers := make([]*${originName}, srcLen) - for i := range *es.orig { - wrappers[i] = &origs[i] - new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&wrappers[i])) - } - *dest.orig = wrappers -} - -// Resize is an operation that resizes the slice: -// 1. If the newLen <= len then equivalent with slice[0:newLen:cap]. -// 2. If the newLen > len then (newLen - cap) empty elements will be appended to the slice. -// -// Here is how a new ${structName} can be initialized: -// es := New${structName}() -// es.Resize(4) -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// // Here should set all the values for e. -// } -func (es ${structName}) Resize(newLen int) { - oldLen := len(*es.orig) - oldCap := cap(*es.orig) - if newLen <= oldLen { - *es.orig = (*es.orig)[:newLen:oldCap] - return - } - - if newLen > oldCap { - newOrig := make([]*${originName}, oldLen, newLen) - copy(newOrig, *es.orig) - *es.orig = newOrig - } - - // Add extra empty elements to the array. - extraOrigs := make([]${originName}, newLen-oldLen) - for i := range extraOrigs { - *es.orig = append(*es.orig, &extraOrigs[i]) - } -} - -// Append will increase the length of the ${structName} by one and set the -// given ${elementName} at that new position. The original ${elementName} -// could still be referenced so do not reuse it after passing it to this -// method. -func (es ${structName}) Append(e ${elementName}) { - *es.orig = append(*es.orig, *e.orig) -}` - -const sliceTestTemplate = `func Test${structName}(t *testing.T) { - es := New${structName}() - assert.EqualValues(t, 0, es.Len()) - es = new${structName}(&[]*${originName}{}) - assert.EqualValues(t, 0, es.Len()) - - es.Resize(7) - emptyVal := New${elementName}() - emptyVal.InitEmpty() - testVal := generateTest${elementName}() - assert.EqualValues(t, 7, es.Len()) - for i := 0; i < es.Len(); i++ { - assert.EqualValues(t, emptyVal, es.At(i)) - fillTest${elementName}(es.At(i)) - assert.EqualValues(t, testVal, es.At(i)) - } -} - -func Test${structName}_MoveAndAppendTo(t *testing.T) { - // Test MoveAndAppendTo to empty - expectedSlice := generateTest${structName}() - dest := New${structName}() - src := generateTest${structName}() - src.MoveAndAppendTo(dest) - assert.EqualValues(t, generateTest${structName}(), dest) - assert.EqualValues(t, 0, src.Len()) - assert.EqualValues(t, expectedSlice.Len(), dest.Len()) - - // Test MoveAndAppendTo empty slice - src.MoveAndAppendTo(dest) - assert.EqualValues(t, generateTest${structName}(), dest) - assert.EqualValues(t, 0, src.Len()) - assert.EqualValues(t, expectedSlice.Len(), dest.Len()) - - // Test MoveAndAppendTo not empty slice - generateTest${structName}().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)) - assert.EqualValues(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) - } -} - -func Test${structName}_CopyTo(t *testing.T) { - dest := New${structName}() - // Test CopyTo to empty - New${structName}().CopyTo(dest) - assert.EqualValues(t, New${structName}(), dest) - - // Test CopyTo larger slice - generateTest${structName}().CopyTo(dest) - assert.EqualValues(t, generateTest${structName}(), dest) - - // Test CopyTo same size slice - generateTest${structName}().CopyTo(dest) - assert.EqualValues(t, generateTest${structName}(), dest) -} - -func Test${structName}_Resize(t *testing.T) { - es := generateTest${structName}() - emptyVal := New${elementName}() - emptyVal.InitEmpty() - // Test Resize less elements. - const resizeSmallLen = 4 - expectedEs := make(map[*${originName}]bool, resizeSmallLen) - for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true - } - assert.Equal(t, resizeSmallLen, len(expectedEs)) - es.Resize(resizeSmallLen) - assert.Equal(t, resizeSmallLen, es.Len()) - foundEs := make(map[*${originName}]bool, resizeSmallLen) - for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true - } - assert.EqualValues(t, expectedEs, foundEs) - - // Test Resize more elements. - const resizeLargeLen = 7 - oldLen := es.Len() - expectedEs = make(map[*${originName}]bool, oldLen) - for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true - } - assert.Equal(t, oldLen, len(expectedEs)) - es.Resize(resizeLargeLen) - assert.Equal(t, resizeLargeLen, es.Len()) - foundEs = make(map[*${originName}]bool, oldLen) - for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true - } - assert.EqualValues(t, expectedEs, foundEs) - for i := oldLen; i < resizeLargeLen; i++ { - assert.EqualValues(t, emptyVal, es.At(i)) - } - - // Test Resize 0 elements. - es.Resize(0) - assert.Equal(t, 0, es.Len()) -} - -func Test${structName}_Append(t *testing.T) { - es := generateTest${structName}() - emptyVal := New${elementName}() - emptyVal.InitEmpty() - - es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) - - emptyVal2 := New${elementName}() - emptyVal2.InitEmpty() - - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) - - assert.Equal(t, 9, es.Len()) -}` - -const sliceGenerateTest = `func generateTest${structName}() ${structName} { - tv := New${structName}() - fillTest${structName}(tv) - return tv -} - -func fillTest${structName}(tv ${structName}) { - tv.Resize(7) - for i := 0; i < tv.Len(); i++ { - fillTest${elementName}(tv.At(i)) - } -}` - const messagePtrTemplate = `${description} // // This is a reference type, if passed by value and callee modifies it the @@ -400,61 +155,6 @@ type baseStruct interface { generateTestValueHelpers(sb *strings.Builder) } -// Will generate code only for the slice struct. -type sliceStruct struct { - structName string - element *messagePtrStruct -} - -func (ss *sliceStruct) getName() string { - return ss.structName -} - -func (ss *sliceStruct) generateStruct(sb *strings.Builder) { - sb.WriteString(os.Expand(sliceTemplate, func(name string) string { - switch name { - case "structName": - return ss.structName - case "elementName": - return ss.element.structName - case "originName": - return ss.element.originFullName - default: - panic(name) - } - })) -} - -func (ss *sliceStruct) generateTests(sb *strings.Builder) { - sb.WriteString(os.Expand(sliceTestTemplate, func(name string) string { - switch name { - case "structName": - return ss.structName - case "elementName": - return ss.element.structName - case "originName": - return ss.element.originFullName - default: - panic(name) - } - })) -} - -func (ss *sliceStruct) generateTestValueHelpers(sb *strings.Builder) { - sb.WriteString(os.Expand(sliceGenerateTest, func(name string) string { - switch name { - case "structName": - return ss.structName - case "elementName": - return ss.element.structName - default: - panic(name) - } - })) -} - -var _ baseStruct = (*sliceStruct)(nil) - type messagePtrStruct struct { structName string description string diff --git a/cmd/pdatagen/internal/common_structs.go b/cmd/pdatagen/internal/common_structs.go index 94097e7fe6d..8f88d23f4ad 100644 --- a/cmd/pdatagen/internal/common_structs.go +++ b/cmd/pdatagen/internal/common_structs.go @@ -50,7 +50,7 @@ var instrumentationLibrary = &messageValueStruct{ // This will not be generated by this class. // Defined here just to be available as returned message for the fields. -var stringMap = &sliceStruct{ +var stringMap = &sliceOfPtrs{ structName: "StringMap", element: stringKeyValue, } @@ -59,7 +59,7 @@ var stringKeyValue = &messagePtrStruct{} // This will not be generated by this class. // Defined here just to be available as returned message for the fields. -var attributeMap = &sliceStruct{ +var attributeMap = &sliceOfPtrs{ structName: "AttributeMap", element: attributeKeyValue, } @@ -113,12 +113,12 @@ var nameField = &primitiveField{ testVal: `"test_name"`, } -var anyValue = &messagePtrStruct{ +var anyValue = &messageValueStruct{ structName: "AttributeValue", originFullName: "otlpcommon.AnyValue", } -var anyValueArray = &sliceStruct{ +var anyValueArray = &sliceOfValues{ structName: "AnyValueArray", element: anyValue, } diff --git a/cmd/pdatagen/internal/files.go b/cmd/pdatagen/internal/files.go index b23c6744d02..4971e1187ef 100644 --- a/cmd/pdatagen/internal/files.go +++ b/cmd/pdatagen/internal/files.go @@ -49,7 +49,7 @@ type File struct { Name string imports []string testImports []string - // Can be any of sliceStruct or messagePtrStruct + // Can be any of sliceOfPtrs, sliceOfValues, messageValueStruct, or messagePtrStruct structs []baseStruct } diff --git a/cmd/pdatagen/internal/log_structs.go b/cmd/pdatagen/internal/log_structs.go index 282ea72df8f..7f3acded7fa 100644 --- a/cmd/pdatagen/internal/log_structs.go +++ b/cmd/pdatagen/internal/log_structs.go @@ -37,7 +37,7 @@ var logFile = &File{ }, } -var resourceLogsSlice = &sliceStruct{ +var resourceLogsSlice = &sliceOfPtrs{ structName: "ResourceLogsSlice", element: resourceLogs, } @@ -56,7 +56,7 @@ var resourceLogs = &messagePtrStruct{ }, } -var instrumentationLibraryLogsSlice = &sliceStruct{ +var instrumentationLibraryLogsSlice = &sliceOfPtrs{ structName: "InstrumentationLibraryLogsSlice", element: instrumentationLibraryLogs, } @@ -75,7 +75,7 @@ var instrumentationLibraryLogs = &messagePtrStruct{ }, } -var logSlice = &sliceStruct{ +var logSlice = &sliceOfPtrs{ structName: "LogSlice", element: logRecord, } @@ -131,7 +131,7 @@ var logRecord = &messagePtrStruct{ }, } -var bodyField = &messagePtrField{ +var bodyField = &messageValueField{ fieldName: "Body", originFieldName: "Body", returnMessage: anyValue, diff --git a/cmd/pdatagen/internal/metrics_structs.go b/cmd/pdatagen/internal/metrics_structs.go index 142b02f0c8c..b44f71ce0f3 100644 --- a/cmd/pdatagen/internal/metrics_structs.go +++ b/cmd/pdatagen/internal/metrics_structs.go @@ -59,7 +59,7 @@ var metricsFile = &File{ }, } -var resourceMetricsSlice = &sliceStruct{ +var resourceMetricsSlice = &sliceOfPtrs{ structName: "ResourceMetricsSlice", element: resourceMetrics, } @@ -78,7 +78,7 @@ var resourceMetrics = &messagePtrStruct{ }, } -var instrumentationLibraryMetricsSlice = &sliceStruct{ +var instrumentationLibraryMetricsSlice = &sliceOfPtrs{ structName: "InstrumentationLibraryMetricsSlice", element: instrumentationLibraryMetrics, } @@ -97,7 +97,7 @@ var instrumentationLibraryMetrics = &messagePtrStruct{ }, } -var metricSlice = &sliceStruct{ +var metricSlice = &sliceOfPtrs{ structName: "MetricSlice", element: metric, } @@ -224,7 +224,7 @@ var doubleSummary = &messageValueStruct{ }, } -var intDataPointSlice = &sliceStruct{ +var intDataPointSlice = &sliceOfPtrs{ structName: "IntDataPointSlice", element: intDataPoint, } @@ -242,7 +242,7 @@ var intDataPoint = &messagePtrStruct{ }, } -var doubleDataPointSlice = &sliceStruct{ +var doubleDataPointSlice = &sliceOfPtrs{ structName: "DoubleDataPointSlice", element: doubleDataPoint, } @@ -260,7 +260,7 @@ var doubleDataPoint = &messagePtrStruct{ }, } -var intHistogramDataPointSlice = &sliceStruct{ +var intHistogramDataPointSlice = &sliceOfPtrs{ structName: "IntHistogramDataPointSlice", element: intHistogramDataPoint, } @@ -281,7 +281,7 @@ var intHistogramDataPoint = &messagePtrStruct{ }, } -var doubleHistogramDataPointSlice = &sliceStruct{ +var doubleHistogramDataPointSlice = &sliceOfPtrs{ structName: "DoubleHistogramDataPointSlice", element: doubleHistogramDataPoint, } @@ -302,7 +302,7 @@ var doubleHistogramDataPoint = &messagePtrStruct{ }, } -var doubleSummaryDataPointSlice = &sliceStruct{ +var doubleSummaryDataPointSlice = &sliceOfPtrs{ structName: "DoubleSummaryDataPointSlice", element: doubleSummaryDataPoint, } @@ -325,7 +325,7 @@ var doubleSummaryDataPoint = &messagePtrStruct{ }, } -var quantileValuesSlice = &sliceStruct{ +var quantileValuesSlice = &sliceOfPtrs{ structName: "ValueAtQuantileSlice", element: quantileValues, } @@ -340,7 +340,7 @@ var quantileValues = &messagePtrStruct{ }, } -var intExemplarSlice = &sliceStruct{ +var intExemplarSlice = &sliceOfPtrs{ structName: "IntExemplarSlice", element: intExemplar, } @@ -363,7 +363,7 @@ var intExemplar = &messagePtrStruct{ }, } -var doubleExemplarSlice = &sliceStruct{ +var doubleExemplarSlice = &sliceOfPtrs{ structName: "DoubleExemplarSlice", element: doubleExemplar, } diff --git a/cmd/pdatagen/internal/trace_structs.go b/cmd/pdatagen/internal/trace_structs.go index 3b70231cb2e..36ada96c408 100644 --- a/cmd/pdatagen/internal/trace_structs.go +++ b/cmd/pdatagen/internal/trace_structs.go @@ -43,7 +43,7 @@ var traceFile = &File{ }, } -var resourceSpansSlice = &sliceStruct{ +var resourceSpansSlice = &sliceOfPtrs{ structName: "ResourceSpansSlice", element: resourceSpans, } @@ -62,7 +62,7 @@ var resourceSpans = &messagePtrStruct{ }, } -var instrumentationLibrarySpansSlice = &sliceStruct{ +var instrumentationLibrarySpansSlice = &sliceOfPtrs{ structName: "InstrumentationLibrarySpansSlice", element: instrumentationLibrarySpans, } @@ -81,7 +81,7 @@ var instrumentationLibrarySpans = &messagePtrStruct{ }, } -var spanSlice = &sliceStruct{ +var spanSlice = &sliceOfPtrs{ structName: "SpanSlice", element: span, } @@ -141,7 +141,7 @@ var span = &messagePtrStruct{ }, } -var spanEventSlice = &sliceStruct{ +var spanEventSlice = &sliceOfPtrs{ structName: "SpanEventSlice", element: spanEvent, } @@ -159,7 +159,7 @@ var spanEvent = &messagePtrStruct{ }, } -var spanLinkSlice = &sliceStruct{ +var spanLinkSlice = &sliceOfPtrs{ structName: "SpanLinkSlice", element: spanLink, } diff --git a/consumer/pdata/common.go b/consumer/pdata/common.go index 235c321b535..7e5476867af 100644 --- a/consumer/pdata/common.go +++ b/consumer/pdata/common.go @@ -82,23 +82,17 @@ func (avt AttributeValueType) String() string { // Important: zero-initialized instance is not valid for use. All AttributeValue functions bellow must // be called only on instances that are created via NewAttributeValue+ functions. type AttributeValue struct { - // Double pointer is required so that in the Setters we can update the pointer if - // it is nil. This double pointer can be eliminated in the future if we embed AnyValue - // using Gogoproto `(gogoproto.nullable) = false` annotation. - // - // orig cannot be nil (it is an invalid instance if orig is nil). - // (*orig) may be nil. - orig **otlpcommon.AnyValue + orig *otlpcommon.AnyValue } -func newAttributeValue(orig **otlpcommon.AnyValue) AttributeValue { +func newAttributeValue(orig *otlpcommon.AnyValue) AttributeValue { return AttributeValue{orig} } // NewAttributeValueNull creates a new AttributeValue with a null value. func NewAttributeValueNull() AttributeValue { orig := &otlpcommon.AnyValue{} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } // Deprecated: Use NewAttributeValueNull() @@ -109,55 +103,50 @@ func NewAttributeValue() AttributeValue { // NewAttributeValueString creates a new AttributeValue with the given string value. func NewAttributeValueString(v string) AttributeValue { orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: v}} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } // NewAttributeValueInt creates a new AttributeValue with the given int64 value. func NewAttributeValueInt(v int64) AttributeValue { orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: v}} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } // NewAttributeValueDouble creates a new AttributeValue with the given float64 value. func NewAttributeValueDouble(v float64) AttributeValue { orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: v}} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } // NewAttributeValueBool creates a new AttributeValue with the given bool value. func NewAttributeValueBool(v bool) AttributeValue { orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: v}} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } // NewAttributeValueMap creates a new AttributeValue of map type. func NewAttributeValueMap() AttributeValue { orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } // NewAttributeValueArray creates a new AttributeValue of array type. func NewAttributeValueArray() AttributeValue { orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}} - return AttributeValue{orig: &orig} + return AttributeValue{orig: orig} } func (a AttributeValue) InitEmpty() { - *a.orig = &otlpcommon.AnyValue{} -} - -// IsNil returns true if the underlying data are nil. -func (a AttributeValue) IsNil() bool { - return *a.orig == nil + *a.orig = otlpcommon.AnyValue{} } // 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 { - if *a.orig == nil || (*a.orig).Value == nil { + if a.orig.Value == nil { return AttributeValueNULL } - switch (*a.orig).Value.(type) { + switch a.orig.Value.(type) { case *otlpcommon.AnyValue_StringValue: return AttributeValueSTRING case *otlpcommon.AnyValue_BoolValue: @@ -178,28 +167,28 @@ func (a AttributeValue) Type() AttributeValueType { // If the Type() is not AttributeValueSTRING then returns empty string. // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) StringVal() string { - return (*a.orig).GetStringValue() + return a.orig.GetStringValue() } // IntVal returns the int64 value associated with this AttributeValue. // If the Type() is not AttributeValueINT then returns int64(0). // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) IntVal() int64 { - return (*a.orig).GetIntValue() + return a.orig.GetIntValue() } // DoubleVal returns the float64 value associated with this AttributeValue. // If the Type() is not AttributeValueDOUBLE then returns float64(0). // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) DoubleVal() float64 { - return (*a.orig).GetDoubleValue() + return a.orig.GetDoubleValue() } // BoolVal returns the bool value associated with this AttributeValue. // If the Type() is not AttributeValueBOOL then returns false. // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) BoolVal() bool { - return (*a.orig).GetBoolValue() + return a.orig.GetBoolValue() } // MapVal returns the map value associated with this AttributeValue. @@ -208,7 +197,7 @@ func (a AttributeValue) BoolVal() bool { // // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) MapVal() AttributeMap { - kvlist := (*a.orig).GetKvlistValue() + kvlist := a.orig.GetKvlistValue() if kvlist == nil { return NewAttributeMap() } @@ -221,7 +210,7 @@ func (a AttributeValue) MapVal() AttributeMap { // // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) ArrayVal() AnyValueArray { - arr := (*a.orig).GetArrayValue() + arr := a.orig.GetArrayValue() if arr == nil { return NewAnyValueArray() } @@ -232,51 +221,33 @@ func (a AttributeValue) ArrayVal() AnyValueArray { // it also changes the type to be AttributeValueSTRING. // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) SetStringVal(v string) { - if *a.orig == nil { - // This may be nil if it was received/Unmarshaled from the wire. - *a.orig = &otlpcommon.AnyValue{} - } - (*a.orig).Value = &otlpcommon.AnyValue_StringValue{StringValue: v} + a.orig.Value = &otlpcommon.AnyValue_StringValue{StringValue: v} } // SetIntVal replaces the int64 value associated with this AttributeValue, // it also changes the type to be AttributeValueINT. // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) SetIntVal(v int64) { - if *a.orig == nil { - *a.orig = &otlpcommon.AnyValue{} - } - (*a.orig).Value = &otlpcommon.AnyValue_IntValue{IntValue: v} + a.orig.Value = &otlpcommon.AnyValue_IntValue{IntValue: v} } // SetDoubleVal replaces the float64 value associated with this AttributeValue, // it also changes the type to be AttributeValueDOUBLE. // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) SetDoubleVal(v float64) { - if *a.orig == nil { - *a.orig = &otlpcommon.AnyValue{} - } - (*a.orig).Value = &otlpcommon.AnyValue_DoubleValue{DoubleValue: v} + a.orig.Value = &otlpcommon.AnyValue_DoubleValue{DoubleValue: v} } // SetBoolVal replaces the bool value associated with this AttributeValue, // it also changes the type to be AttributeValueBOOL. // Calling this function on zero-initialized AttributeValue will cause a panic. func (a AttributeValue) SetBoolVal(v bool) { - if *a.orig == nil { - *a.orig = &otlpcommon.AnyValue{} - } - (*a.orig).Value = &otlpcommon.AnyValue_BoolValue{BoolValue: v} + a.orig.Value = &otlpcommon.AnyValue_BoolValue{BoolValue: v} } // copyTo copies the value to AnyValue. Will panic if dest is nil. func (a AttributeValue) copyTo(dest *otlpcommon.AnyValue) { - if *a.orig == nil { - // This is a null value. Make the dest null too. - dest.Value = nil - return - } - switch v := (*a.orig).Value.(type) { + switch v := a.orig.Value.(type) { case *otlpcommon.AnyValue_KvlistValue: kv, ok := dest.Value.(*otlpcommon.AnyValue_KvlistValue) if !ok { @@ -303,80 +274,70 @@ func (a AttributeValue) copyTo(dest *otlpcommon.AnyValue) { newAnyValueArray(&v.ArrayValue.Values).CopyTo(newAnyValueArray(&av.ArrayValue.Values)) default: // Primitive immutable type, no need for deep copy. - dest.Value = (*a.orig).Value + dest.Value = a.orig.Value } } func (a AttributeValue) CopyTo(dest AttributeValue) { - if *a.orig == nil { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } - a.copyTo(*dest.orig) + 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 { - if (*a.orig) == nil || (*a.orig).Value == nil { - return (*av.orig) == nil || (*av.orig).Value == nil - } - if (*av.orig) == nil || (*av.orig).Value == nil { - return false + if a.orig.Value == nil || av.orig.Value == nil { + return a.orig.Value == av.orig.Value } - switch v := (*a.orig).Value.(type) { + switch v := a.orig.Value.(type) { case *otlpcommon.AnyValue_StringValue: - return v.StringValue == (*av.orig).GetStringValue() + return v.StringValue == av.orig.GetStringValue() case *otlpcommon.AnyValue_BoolValue: - return v.BoolValue == (*av.orig).GetBoolValue() + return v.BoolValue == av.orig.GetBoolValue() case *otlpcommon.AnyValue_IntValue: - return v.IntValue == (*av.orig).GetIntValue() + return v.IntValue == av.orig.GetIntValue() case *otlpcommon.AnyValue_DoubleValue: - return v.DoubleValue == (*av.orig).GetDoubleValue() + return v.DoubleValue == av.orig.GetDoubleValue() } // TODO: handle MAP and ARRAY data types. return false } func newAttributeKeyValueString(k string, v string) otlpcommon.KeyValue { - orig := otlpcommon.KeyValue{Key: k, Value: &otlpcommon.AnyValue{}} + orig := otlpcommon.KeyValue{Key: k} akv := AttributeValue{&orig.Value} akv.SetStringVal(v) return orig } func newAttributeKeyValueInt(k string, v int64) otlpcommon.KeyValue { - orig := otlpcommon.KeyValue{Key: k, Value: &otlpcommon.AnyValue{}} + orig := otlpcommon.KeyValue{Key: k} akv := AttributeValue{&orig.Value} akv.SetIntVal(v) return orig } func newAttributeKeyValueDouble(k string, v float64) otlpcommon.KeyValue { - orig := otlpcommon.KeyValue{Key: k, Value: &otlpcommon.AnyValue{}} + orig := otlpcommon.KeyValue{Key: k} akv := AttributeValue{&orig.Value} akv.SetDoubleVal(v) return orig } func newAttributeKeyValueBool(k string, v bool) otlpcommon.KeyValue { - orig := otlpcommon.KeyValue{Key: k, Value: &otlpcommon.AnyValue{}} + orig := otlpcommon.KeyValue{Key: k} akv := AttributeValue{&orig.Value} akv.SetBoolVal(v) return orig } func newAttributeKeyValueNull(k string) otlpcommon.KeyValue { - orig := otlpcommon.KeyValue{Key: k, Value: &otlpcommon.AnyValue{}} + orig := otlpcommon.KeyValue{Key: k} return orig } func newAttributeKeyValue(k string, av AttributeValue) otlpcommon.KeyValue { - orig := otlpcommon.KeyValue{Key: k, Value: &otlpcommon.AnyValue{}} - av.copyTo(orig.Value) + orig := otlpcommon.KeyValue{Key: k} + av.copyTo(&orig.Value) return orig } @@ -405,13 +366,11 @@ func (am AttributeMap) InitFromMap(attrMap map[string]AttributeValue) AttributeM *am.orig = []otlpcommon.KeyValue(nil) return am } - anyVals := make([]otlpcommon.AnyValue, len(attrMap)) origs := make([]otlpcommon.KeyValue, len(attrMap)) ix := 0 for k, v := range attrMap { origs[ix].Key = k - origs[ix].Value = &anyVals[ix] - v.copyTo(&anyVals[ix]) + v.copyTo(&origs[ix].Value) ix++ } *am.orig = origs @@ -520,7 +479,7 @@ func (am AttributeMap) InsertBool(k string, v bool) { // the raw value to avoid an extra allocation. func (am AttributeMap) Update(k string, v AttributeValue) { if av, existing := am.Get(k); existing { - v.copyTo(*av.orig) + v.copyTo(av.orig) } } @@ -566,7 +525,7 @@ func (am AttributeMap) UpdateBool(k string, v bool) { // the raw value to avoid an extra allocation. func (am AttributeMap) Upsert(k string, v AttributeValue) { if av, existing := am.Get(k); existing { - v.copyTo(*av.orig) + v.copyTo(av.orig) } else { *am.orig = append(*am.orig, newAttributeKeyValue(k, v)) } @@ -660,22 +619,17 @@ func (am AttributeMap) CopyTo(dest AttributeMap) { akv := &(*am.orig)[i] destAkv := &(*dest.orig)[i] destAkv.Key = akv.Key - if destAkv.Value == nil { - destAkv.Value = &otlpcommon.AnyValue{} - } - AttributeValue{&akv.Value}.copyTo(destAkv.Value) + AttributeValue{&akv.Value}.copyTo(&destAkv.Value) } return } // New slice is bigger than exist slice. Allocate new space. - anyVals := make([]otlpcommon.AnyValue, len(*am.orig)) origs := make([]otlpcommon.KeyValue, len(*am.orig)) for i := range *am.orig { akv := &(*am.orig)[i] origs[i].Key = akv.Key - origs[i].Value = &anyVals[i] - AttributeValue{&akv.Value}.copyTo(&anyVals[i]) + AttributeValue{&akv.Value}.copyTo(&origs[i].Value) } *dest.orig = origs } diff --git a/consumer/pdata/common_test.go b/consumer/pdata/common_test.go index ecb25e62dcd..0f6b744d1b0 100644 --- a/consumer/pdata/common_test.go +++ b/consumer/pdata/common_test.go @@ -198,36 +198,31 @@ 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 = AttributeValue{orig: orig} assert.EqualValues(t, NewAttributeMap(), m1.MapVal()) } -func createNilOrigSetAttributeValue() AttributeValue { - var orig *otlpcommon.AnyValue - return AttributeValue{orig: &orig} -} - func TestNilOrigSetAttributeValue(t *testing.T) { - av := createNilOrigSetAttributeValue() + av := NewAttributeValueNull() av.SetStringVal("abc") assert.EqualValues(t, "abc", av.StringVal()) - av = createNilOrigSetAttributeValue() + av = NewAttributeValueNull() av.SetIntVal(123) assert.EqualValues(t, 123, av.IntVal()) - av = createNilOrigSetAttributeValue() + av = NewAttributeValueNull() av.SetBoolVal(true) assert.True(t, av.BoolVal()) - av = createNilOrigSetAttributeValue() + av = NewAttributeValueNull() av.SetDoubleVal(1.23) assert.EqualValues(t, 1.23, av.DoubleVal()) } func TestAttributeValueEqual(t *testing.T) { - av1 := createNilOrigSetAttributeValue() - av2 := createNilOrigSetAttributeValue() + av1 := NewAttributeValueNull() + av2 := NewAttributeValueNull() assert.True(t, av1.Equal(av2)) av2 = NewAttributeValueString("abc") @@ -355,15 +350,11 @@ func TestAttributeMapWithEmpty(t *testing.T) { {}, { Key: "test_key", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "test_value"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "test_value"}}, }, { Key: "test_key2", - Value: nil, - }, - { - Key: "test_key3", - Value: &otlpcommon.AnyValue{Value: nil}, + Value: otlpcommon.AnyValue{Value: nil}, }, } sm := AttributeMap{ @@ -379,11 +370,6 @@ func TestAttributeMapWithEmpty(t *testing.T) { assert.EqualValues(t, AttributeValueNULL, val.Type()) assert.EqualValues(t, "", val.StringVal()) - val, exist = sm.Get("test_key3") - assert.True(t, exist) - assert.EqualValues(t, AttributeValueNULL, val.Type()) - assert.EqualValues(t, "", val.StringVal()) - sm.Insert("other_key", NewAttributeValueString("other_value")) val, exist = sm.Get("other_key") assert.True(t, exist) @@ -528,10 +514,8 @@ func TestAttributeMapWithEmpty(t *testing.T) { assert.EqualValues(t, AttributeValueNULL, val.Type()) assert.EqualValues(t, "", val.StringVal()) - val, exist = sm.Get("test_key3") - assert.True(t, exist) - assert.EqualValues(t, AttributeValueNULL, val.Type()) - assert.EqualValues(t, "", val.StringVal()) + _, exist = sm.Get("test_key3") + assert.False(t, exist) // Test Sort assert.EqualValues(t, AttributeMap{orig: &origWithNil}, sm.Sort()) @@ -588,19 +572,18 @@ func TestAttributeValue_CopyTo(t *testing.T) { // Test nil KvlistValue case for MapVal() func. dest := NewAttributeValueNull() orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: nil}} - AttributeValue{orig: &orig}.CopyTo(dest) - assert.Nil(t, (*dest.orig).Value.(*otlpcommon.AnyValue_KvlistValue).KvlistValue) + AttributeValue{orig: orig}.CopyTo(dest) + assert.Nil(t, dest.orig.Value.(*otlpcommon.AnyValue_KvlistValue).KvlistValue) // Test nil ArrayValue case for ArrayVal() func. dest = NewAttributeValueNull() orig = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: nil}} - AttributeValue{orig: &orig}.CopyTo(dest) - assert.Nil(t, (*dest.orig).Value.(*otlpcommon.AnyValue_ArrayValue).ArrayValue) + AttributeValue{orig: orig}.CopyTo(dest) + assert.Nil(t, dest.orig.Value.(*otlpcommon.AnyValue_ArrayValue).ArrayValue) - // Test copy nil value. - var origNil *otlpcommon.AnyValue - AttributeValue{orig: &origNil}.CopyTo(dest) - assert.Nil(t, *dest.orig) + // Test copy empty value. + AttributeValue{orig: &otlpcommon.AnyValue{}}.CopyTo(dest) + assert.Nil(t, dest.orig.Value) } func TestAttributeMap_CopyTo(t *testing.T) { @@ -617,14 +600,14 @@ func TestAttributeMap_CopyTo(t *testing.T) { generateTestAttributeMap().CopyTo(dest) assert.EqualValues(t, generateTestAttributeMap(), dest) - // Test CopyTo with a nil Value in the destination - (*dest.orig)[0].Value = nil + // Test CopyTo with an empty Value in the destination + (*dest.orig)[0].Value = otlpcommon.AnyValue{} generateTestAttributeMap().CopyTo(dest) assert.EqualValues(t, generateTestAttributeMap(), dest) } func TestAttributeValue_copyTo(t *testing.T) { - av := createNilOrigSetAttributeValue() + av := NewAttributeValueNull() destVal := otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{}} av.copyTo(&destVal) assert.EqualValues(t, nil, destVal.Value) @@ -634,15 +617,11 @@ func TestAttributeMap_Update(t *testing.T) { origWithNil := []otlpcommon.KeyValue{ { Key: "test_key", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "test_value"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "test_value"}}, }, { Key: "test_key2", - Value: nil, - }, - { - Key: "test_key3", - Value: &otlpcommon.AnyValue{Value: nil}, + Value: otlpcommon.AnyValue{Value: nil}, }, } sm := AttributeMap{ @@ -670,17 +649,6 @@ func TestAttributeMap_Update(t *testing.T) { assert.True(t, exists) assert.EqualValues(t, AttributeValueINT, av2.Type()) assert.EqualValues(t, 123, av2.IntVal()) - - av, exists = sm.Get("test_key3") - assert.True(t, exists) - assert.EqualValues(t, AttributeValueNULL, av.Type()) - assert.EqualValues(t, "", av.StringVal()) - av.SetBoolVal(true) - - av2, exists = sm.Get("test_key3") - assert.True(t, exists) - assert.EqualValues(t, AttributeValueBOOL, av2.Type()) - assert.True(t, av2.BoolVal()) } func TestAttributeMap_InitEmptyWithCapacity(t *testing.T) { @@ -896,7 +864,7 @@ func BenchmarkAttributeValue_CopyTo(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - c.copyTo(*av.orig) + c.copyTo(av.orig) } if av.IntVal() != 123 { b.Fail() @@ -921,7 +889,7 @@ func BenchmarkAttributeMap_ForEach(b *testing.B) { for i := 0; i < numElements; i++ { rawOrig[i] = otlpcommon.KeyValue{ Key: "k" + strconv.Itoa(i), - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "v" + strconv.Itoa(i)}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "v" + strconv.Itoa(i)}}, } } am := AttributeMap{ @@ -1134,35 +1102,29 @@ func TestAttributeValueArray(t *testing.T) { assert.EqualValues(t, "somestr", v.StringVal()) // Test nil values case for ArrayVal() func. - orig := &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: nil}} - a1 = AttributeValue{orig: &orig} + a1 = AttributeValue{orig: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: nil}}} assert.EqualValues(t, NewAnyValueArray(), a1.ArrayVal()) } func TestAnyValueArrayWithNilValues(t *testing.T) { - origWithNil := []*otlpcommon.AnyValue{ - nil, + origWithNil := []otlpcommon.AnyValue{ + {}, {Value: &otlpcommon.AnyValue_StringValue{StringValue: "test_value"}}, - nil, - {Value: nil}, } sm := AnyValueArray{ orig: &origWithNil, } - val := sm.At(1) - assert.EqualValues(t, AttributeValueSTRING, val.Type()) - assert.EqualValues(t, "test_value", val.StringVal()) - val = sm.At(3) + val := sm.At(0) assert.EqualValues(t, AttributeValueNULL, val.Type()) assert.EqualValues(t, "", val.StringVal()) - val = sm.At(0) - assert.EqualValues(t, AttributeValueNULL, val.Type()) - assert.EqualValues(t, "", val.StringVal()) + val = sm.At(1) + assert.EqualValues(t, AttributeValueSTRING, val.Type()) + assert.EqualValues(t, "test_value", val.StringVal()) sm.Append(NewAttributeValueString("other_value")) - val = sm.At(4) + val = sm.At(2) assert.EqualValues(t, AttributeValueSTRING, val.Type()) assert.EqualValues(t, "other_value", val.StringVal()) } diff --git a/consumer/pdata/generated_common.go b/consumer/pdata/generated_common.go index 45ff2b07b32..3e5cf2b64d4 100644 --- a/consumer/pdata/generated_common.go +++ b/consumer/pdata/generated_common.go @@ -93,17 +93,17 @@ func (ms InstrumentationLibrary) CopyTo(dest InstrumentationLibrary) { type AnyValueArray 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 Resize. - orig *[]*otlpcommon.AnyValue + orig *[]otlpcommon.AnyValue } -func newAnyValueArray(orig *[]*otlpcommon.AnyValue) AnyValueArray { +func newAnyValueArray(orig *[]otlpcommon.AnyValue) AnyValueArray { return AnyValueArray{orig} } // NewAnyValueArray creates a AnyValueArray with 0 elements. // Can use "Resize" to initialize with a given length. func NewAnyValueArray() AnyValueArray { - orig := []*otlpcommon.AnyValue(nil) + orig := []otlpcommon.AnyValue(nil) return AnyValueArray{&orig} } @@ -143,18 +143,13 @@ func (es AnyValueArray) CopyTo(dest AnyValueArray) { destCap := cap(*dest.orig) if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] - for i := range *es.orig { - newAttributeValue(&(*es.orig)[i]).CopyTo(newAttributeValue(&(*dest.orig)[i])) - } - return + } else { + (*dest.orig) = make([]otlpcommon.AnyValue, srcLen) } - origs := make([]otlpcommon.AnyValue, srcLen) - wrappers := make([]*otlpcommon.AnyValue, srcLen) + for i := range *es.orig { - wrappers[i] = &origs[i] - newAttributeValue(&(*es.orig)[i]).CopyTo(newAttributeValue(&wrappers[i])) + newAttributeValue(&(*es.orig)[i]).CopyTo(newAttributeValue(&(*dest.orig)[i])) } - *dest.orig = wrappers } // Resize is an operation that resizes the slice: @@ -177,15 +172,15 @@ func (es AnyValueArray) Resize(newLen int) { } if newLen > oldCap { - newOrig := make([]*otlpcommon.AnyValue, oldLen, newLen) + newOrig := make([]otlpcommon.AnyValue, oldLen, newLen) copy(newOrig, *es.orig) *es.orig = newOrig } // Add extra empty elements to the array. - extraOrigs := make([]otlpcommon.AnyValue, newLen-oldLen) - for i := range extraOrigs { - *es.orig = append(*es.orig, &extraOrigs[i]) + empty := otlpcommon.AnyValue{} + for i := oldLen; i < newLen; i++ { + *es.orig = append(*es.orig, empty) } } diff --git a/consumer/pdata/generated_common_test.go b/consumer/pdata/generated_common_test.go index e8deabe406b..7cb778c1e68 100644 --- a/consumer/pdata/generated_common_test.go +++ b/consumer/pdata/generated_common_test.go @@ -52,7 +52,7 @@ func TestInstrumentationLibrary_Version(t *testing.T) { func TestAnyValueArray(t *testing.T) { es := NewAnyValueArray() assert.EqualValues(t, 0, es.Len()) - es = newAnyValueArray(&[]*otlpcommon.AnyValue{}) + es = newAnyValueArray(&[]otlpcommon.AnyValue{}) assert.EqualValues(t, 0, es.Len()) es.Resize(7) @@ -115,14 +115,14 @@ func TestAnyValueArray_Resize(t *testing.T) { const resizeSmallLen = 4 expectedEs := make(map[*otlpcommon.AnyValue]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpcommon.AnyValue]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -131,14 +131,14 @@ func TestAnyValueArray_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpcommon.AnyValue]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpcommon.AnyValue]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { diff --git a/consumer/pdata/generated_log.go b/consumer/pdata/generated_log.go index 4efff33d6cf..8b558459565 100644 --- a/consumer/pdata/generated_log.go +++ b/consumer/pdata/generated_log.go @@ -632,9 +632,6 @@ func (ms LogRecord) SetName(v string) { } // Body returns the body associated with this LogRecord. -// If no body available, it creates an empty message and associates it with this LogRecord. -// -// Empty initialized LogRecord will return "nil" AttributeValue. // // Important: This causes a runtime error if IsNil() returns "true". func (ms LogRecord) Body() AttributeValue { diff --git a/consumer/pdata/generated_log_test.go b/consumer/pdata/generated_log_test.go index e9360a7f6c5..5f6f55d3de4 100644 --- a/consumer/pdata/generated_log_test.go +++ b/consumer/pdata/generated_log_test.go @@ -522,9 +522,6 @@ func TestLogRecord_Name(t *testing.T) { func TestLogRecord_Body(t *testing.T) { ms := NewLogRecord() ms.InitEmpty() - assert.True(t, ms.Body().IsNil()) - ms.Body().InitEmpty() - assert.False(t, ms.Body().IsNil()) fillTestAttributeValue(ms.Body()) assert.EqualValues(t, generateTestAttributeValue(), ms.Body()) } @@ -625,7 +622,6 @@ func fillTestLogRecord(tv LogRecord) { tv.SetSeverityText("INFO") tv.SetSeverityNumber(SeverityNumberINFO) tv.SetName("test_name") - tv.Body().InitEmpty() fillTestAttributeValue(tv.Body()) fillTestAttributeMap(tv.Attributes()) tv.SetDroppedAttributesCount(uint32(17)) diff --git a/consumer/pdata/metric_test.go b/consumer/pdata/metric_test.go index cceac7743d0..d302abad2f2 100644 --- a/consumer/pdata/metric_test.go +++ b/consumer/pdata/metric_test.go @@ -876,7 +876,7 @@ func generateTestProtoResource() otlpresource.Resource { Attributes: []otlpcommon.KeyValue{ { Key: "string", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "string-resource"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "string-resource"}}, }, }, } diff --git a/exporter/fileexporter/file_exporter_test.go b/exporter/fileexporter/file_exporter_test.go index 2b572420937..a5093147613 100644 --- a/exporter/fileexporter/file_exporter_test.go +++ b/exporter/fileexporter/file_exporter_test.go @@ -79,7 +79,7 @@ func TestFileLogsExporterNoErrors(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: "attr1", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value1"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value1"}}, }, }, }, @@ -103,7 +103,7 @@ func TestFileLogsExporterNoErrors(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: "attr2", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value2"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value2"}}, }, }, }, @@ -138,7 +138,7 @@ func TestFileLogsExporterErrors(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: "attr1", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value1"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value1"}}, }, }, }, @@ -162,7 +162,7 @@ func TestFileLogsExporterErrors(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: "attr2", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value2"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "value2"}}, }, }, }, diff --git a/internal/data/opentelemetry-proto-gen/common/v1/common.pb.go b/internal/data/opentelemetry-proto-gen/common/v1/common.pb.go index a0f60dafee6..3b362407449 100644 --- a/internal/data/opentelemetry-proto-gen/common/v1/common.pb.go +++ b/internal/data/opentelemetry-proto-gen/common/v1/common.pb.go @@ -172,7 +172,7 @@ func (*AnyValue) XXX_OneofWrappers() []interface{} { // since oneof in AnyValue does not allow repeated fields. type ArrayValue struct { // Array of values. The array may be empty (contain 0 elements). - Values []*AnyValue `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"` + Values []AnyValue `protobuf:"bytes,1,rep,name=values,proto3" json:"values"` } func (m *ArrayValue) Reset() { *m = ArrayValue{} } @@ -208,7 +208,7 @@ func (m *ArrayValue) XXX_DiscardUnknown() { var xxx_messageInfo_ArrayValue proto.InternalMessageInfo -func (m *ArrayValue) GetValues() []*AnyValue { +func (m *ArrayValue) GetValues() []AnyValue { if m != nil { return m.Values } @@ -269,8 +269,8 @@ func (m *KeyValueList) GetValues() []KeyValue { // KeyValue is a key-value pair that is used to store Span attributes, Link // attributes, etc. type KeyValue struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value *AnyValue `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value AnyValue `protobuf:"bytes,2,opt,name=value,proto3" json:"value"` } func (m *KeyValue) Reset() { *m = KeyValue{} } @@ -313,11 +313,11 @@ func (m *KeyValue) GetKey() string { return "" } -func (m *KeyValue) GetValue() *AnyValue { +func (m *KeyValue) GetValue() AnyValue { if m != nil { return m.Value } - return nil + return AnyValue{} } // StringKeyValue is a pair of key/value strings. This is the simpler (and faster) version @@ -442,37 +442,37 @@ func init() { } var fileDescriptor_62ba46dcb97aa817 = []byte{ - // 471 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x4d, 0x6b, 0x13, 0x41, - 0x18, 0xde, 0x69, 0xd2, 0x34, 0x79, 0x37, 0x88, 0x0c, 0x45, 0x82, 0xd0, 0xed, 0x12, 0x0f, 0xae, - 0x4a, 0xb3, 0xb4, 0x5e, 0xbc, 0x88, 0x34, 0xa2, 0x44, 0x4c, 0x21, 0xac, 0xe8, 0x41, 0x0f, 0x32, - 0x69, 0x87, 0x65, 0xe8, 0xec, 0x4c, 0x99, 0x9d, 0x2c, 0xec, 0xbf, 0xf0, 0xe8, 0x9f, 0xf1, 0xde, - 0x63, 0x8f, 0x9e, 0x44, 0x92, 0x3f, 0x22, 0xf3, 0xb1, 0x69, 0xeb, 0x21, 0xa5, 0xb7, 0x77, 0x9e, - 0x79, 0x3e, 0xde, 0x77, 0x3e, 0xe0, 0xb9, 0xbc, 0xa0, 0x42, 0x53, 0x4e, 0x0b, 0xaa, 0x55, 0x9d, - 0x5e, 0x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00, 0xff, 0xff, 0x39, - 0xfb, 0x71, 0x25, 0xc9, 0x03, 0x00, 0x00, + // 467 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x4d, 0x6b, 0xdb, 0x30, + 0x18, 0xb6, 0x9a, 0x34, 0x4d, 0x5e, 0x87, 0x31, 0x44, 0x19, 0x61, 0x50, 0xd7, 0x64, 0x87, 0x79, + 0x1b, 0x8d, 0x69, 0x77, 0xd9, 0xb5, 0x29, 0x1b, 0x19, 0xcb, 0x20, 0xb8, 0x6c, 0x87, 0x5d, 0x86, + 0xd2, 0x0a, 0x23, 0x2a, 0x4b, 0x45, 0x56, 0x0c, 0xfe, 0x17, 0x3b, 0xee, 0xcf, 0xec, 0xde, 0x63, + 0x8f, 0x3b, 0x8d, 0x91, 0xfc, 0x91, 0xa2, 0x0f, 0xf7, 0xeb, 0x90, 0x92, 0xdb, 0xab, 0x47, 0xcf, + 0xc7, 0xfb, 0xea, 0x03, 0xde, 0xca, 0x4b, 0x2a, 0x34, 0xe5, 0xb4, 0xa0, 0x5a, 0xd5, 0xe9, 0xa5, + 0x92, 0x5a, 0xa6, 0x67, 0xb2, 0x28, 0xa4, 0x48, 0xab, 0x43, 0x5f, 0x8d, 0x2c, 0x8c, 0xf7, 0x1e, + 0x70, 0x1d, 0x38, 0xf2, 0x8c, 0xea, 0xf0, 0xe5, 0x6e, 0x2e, 0x73, 0xe9, 0x0c, 0x4c, 0xe5, 0xf6, + 0x87, 0x7f, 0xb6, 0xa0, 0x7b, 0x2c, 0xea, 0xef, 0x84, 0x2f, 0x28, 0x7e, 0x05, 0xfd, 0x52, 0x2b, + 0x26, 0xf2, 0x9f, 0x95, 0x59, 0x0f, 0x50, 0x8c, 0x92, 0xde, 0x24, 0xc8, 0x42, 0x87, 0x3a, 0xd2, + 0x3e, 0xc0, 0x5c, 0x4a, 0xee, 0x29, 0x5b, 0x31, 0x4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 0x0a, + 0x4d, 0x34, 0x93, 0x62, 0xca, 0xe6, 0x8a, 0xa8, 0x1a, 0x63, 0x68, 0x0b, 0x52, 0xf8, 0xd7, 0x98, + 0xd9, 0x1a, 0x0f, 0x60, 0xa7, 0xa2, 0xaa, 0x64, 0x52, 0x78, 0x97, 0x66, 0x39, 0xfe, 0x8d, 0xae, + 0x96, 0x11, 0xba, 0x5e, 0x46, 0xe8, 0xff, 0x32, 0x42, 0xbf, 0x56, 0x51, 0x70, 0xbd, 0x8a, 0x82, + 0xbf, 0xab, 0x28, 0x80, 0x98, 0xc9, 0xf5, 0x43, 0x8d, 0xc3, 0x13, 0x5b, 0xce, 0x0c, 0x3c, 0x43, + 0x3f, 0xbe, 0xe6, 0x8f, 0x05, 0xcc, 0xfc, 0x3e, 0xce, 0xe9, 0x99, 0x96, 0x2a, 0x65, 0x42, 0x53, + 0x25, 0x08, 0x4f, 0xcf, 0x89, 0x26, 0xe9, 0x03, 0xe2, 0x81, 0x75, 0x3e, 0xc8, 0xa9, 0xb8, 0xfb, + 0xad, 0xf3, 0x8e, 0x05, 0xdf, 0xdf, 0x04, 0x00, 0x00, 0xff, 0xff, 0x70, 0x0b, 0x4b, 0xbe, 0xd5, + 0x03, 0x00, 0x00, } func (m *AnyValue) Marshal() (dAtA []byte, err error) { @@ -699,18 +699,16 @@ func (m *KeyValue) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Value != nil { - { - size, err := m.Value.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCommon(dAtA, i, uint64(size)) + { + size, err := m.Value.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintCommon(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if len(m.Key) > 0 { i -= len(m.Key) copy(dAtA[i:], m.Key) @@ -919,10 +917,8 @@ func (m *KeyValue) Size() (n int) { if l > 0 { n += 1 + l + sovCommon(uint64(l)) } - if m.Value != nil { - l = m.Value.Size() - n += 1 + l + sovCommon(uint64(l)) - } + l = m.Value.Size() + n += 1 + l + sovCommon(uint64(l)) return n } @@ -1231,7 +1227,7 @@ func (m *ArrayValue) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Values = append(m.Values, &AnyValue{}) + m.Values = append(m.Values, AnyValue{}) if err := m.Values[len(m.Values)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1437,9 +1433,6 @@ func (m *KeyValue) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Value == nil { - m.Value = &AnyValue{} - } if err := m.Value.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/internal/data/opentelemetry-proto-gen/logs/v1/logs.pb.go b/internal/data/opentelemetry-proto-gen/logs/v1/logs.pb.go index e70e57c9b21..3092a71e09b 100644 --- a/internal/data/opentelemetry-proto-gen/logs/v1/logs.pb.go +++ b/internal/data/opentelemetry-proto-gen/logs/v1/logs.pb.go @@ -283,7 +283,7 @@ type LogRecord struct { // A value containing the body of the log record. Can be for example a human-readable // string message (including multi-line) describing the event in a free form or it can // be a structured data composed of arrays and maps of other values. [Optional]. - Body *v11.AnyValue `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` + Body v11.AnyValue `protobuf:"bytes,5,opt,name=body,proto3" json:"body"` // Additional attributes that describe the specific event occurrence. [Optional]. Attributes []v11.KeyValue `protobuf:"bytes,6,rep,name=attributes,proto3" json:"attributes"` DroppedAttributesCount uint32 `protobuf:"varint,7,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` @@ -366,11 +366,11 @@ func (m *LogRecord) GetName() string { return "" } -func (m *LogRecord) GetBody() *v11.AnyValue { +func (m *LogRecord) GetBody() v11.AnyValue { if m != nil { return m.Body } - return nil + return v11.AnyValue{} } func (m *LogRecord) GetAttributes() []v11.KeyValue { @@ -407,61 +407,61 @@ func init() { } var fileDescriptor_d1c030a3ec7e961e = []byte{ - // 851 bytes of a gzipped FileDescriptorProto + // 849 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x96, 0xdf, 0x6e, 0x22, 0x37, 0x14, 0xc6, 0x71, 0x42, 0x20, 0x71, 0x08, 0xeb, 0xba, 0xd9, 0xec, 0x94, 0x54, 0x04, 0xa5, 0xed, - 0x96, 0xa6, 0x5a, 0x50, 0x06, 0xaa, 0x56, 0xbb, 0x57, 0x10, 0x86, 0x68, 0x14, 0x42, 0x22, 0x43, - 0xd2, 0x3f, 0x37, 0xa3, 0x01, 0x5c, 0x34, 0x12, 0xd8, 0x68, 0xc6, 0x44, 0xe1, 0x2d, 0xaa, 0xbe, - 0x52, 0x6f, 0xb6, 0x37, 0xd5, 0x5e, 0x55, 0x55, 0x2f, 0x56, 0x55, 0xf2, 0x20, 0xad, 0xec, 0x19, - 0xe8, 0x82, 0xc6, 0xac, 0xf6, 0x0a, 0xcf, 0xf9, 0x9d, 0xef, 0x3b, 0xc7, 0x67, 0xc6, 0x16, 0xf0, - 0x39, 0x9f, 0x50, 0x26, 0xe8, 0x88, 0x8e, 0xa9, 0xf0, 0x67, 0xe5, 0x89, 0xcf, 0x05, 0x2f, 0x8f, - 0xf8, 0x30, 0x28, 0xdf, 0x9d, 0xaa, 0xdf, 0x92, 0x0a, 0xe1, 0xc3, 0xa5, 0xbc, 0x30, 0x58, 0x52, - 0xfc, 0xee, 0x34, 0xb7, 0x3f, 0xe4, 0x43, 0x1e, 0x4a, 0xe5, 0x2a, 0xa4, 0xb9, 0x93, 0x38, 0xeb, - 0x3e, 0x1f, 0x8f, 0x39, 0x93, 0xe6, 0xe1, 0x2a, 0xca, 0x2d, 0xc5, 0xe5, 0xfa, 0x34, 0xe0, 0x53, - 0xbf, 0x4f, 0x65, 0xf6, 0x7c,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2f, 0x68, 0x4d, 0xbe, 0xd4, 0xe1, 0xb5, 0x0c, 0x5d, 0x83, 0x9f, 0x2f, + 0x3e, 0xe0, 0x8e, 0x96, 0x97, 0x12, 0x5f, 0x28, 0xd7, 0x17, 0x03, 0xca, 0xe6, 0x3f, 0x25, 0xba, + 0x29, 0x15, 0xaa, 0xfc, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x8e, 0x28, 0xc9, 0xea, 0x70, 0x08, 0x00, + 0x00, } func (m *ResourceLogs) Marshal() (dAtA []byte, err error) { @@ -623,18 +623,16 @@ func (m *LogRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x32 } } - if m.Body != nil { - { - size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintLogs(dAtA, i, uint64(size)) + { + size, err := m.Body.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x2a + i -= size + i = encodeVarintLogs(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x2a if len(m.Name) > 0 { i -= len(m.Name) copy(dAtA[i:], m.Name) @@ -728,10 +726,8 @@ func (m *LogRecord) Size() (n int) { if l > 0 { n += 1 + l + sovLogs(uint64(l)) } - if m.Body != nil { - l = m.Body.Size() - n += 1 + l + sovLogs(uint64(l)) - } + l = m.Body.Size() + n += 1 + l + sovLogs(uint64(l)) if len(m.Attributes) > 0 { for _, e := range m.Attributes { l = e.Size() @@ -1148,9 +1144,6 @@ func (m *LogRecord) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Body == nil { - m.Body = &v11.AnyValue{} - } if err := m.Body.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/internal/goldendataset/generator_commons.go b/internal/goldendataset/generator_commons.go index 81f2a3b8363..cedbed1418e 100644 --- a/internal/goldendataset/generator_commons.go +++ b/internal/goldendataset/generator_commons.go @@ -45,32 +45,32 @@ func constructAttributeKeyValue(key string, value interface{}) otlpcommon.KeyVal case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: attr = otlpcommon.KeyValue{ Key: key, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: cast.ToInt64(val)}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: cast.ToInt64(val)}}, } case float32, float64: attr = otlpcommon.KeyValue{ Key: key, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: cast.ToFloat64(val)}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: cast.ToFloat64(val)}}, } case bool: attr = otlpcommon.KeyValue{ Key: key, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: cast.ToBool(val)}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: cast.ToBool(val)}}, } case *otlpcommon.ArrayValue: attr = otlpcommon.KeyValue{ Key: key, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: val}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: val}}, } case *otlpcommon.KeyValueList: attr = otlpcommon.KeyValue{ Key: key, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: val}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: val}}, } default: attr = otlpcommon.KeyValue{ Key: key, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: val.(string)}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: val.(string)}}, } } return attr diff --git a/internal/goldendataset/resource_generator.go b/internal/goldendataset/resource_generator.go index 55c4c666418..aba7483f38a 100644 --- a/internal/goldendataset/resource_generator.go +++ b/internal/goldendataset/resource_generator.go @@ -153,10 +153,10 @@ func generateFassAttributes() map[string]interface{} { func generateExecAttributes() map[string]interface{} { attrMap := make(map[string]interface{}) attrMap[conventions.AttributeProcessExecutableName] = "otelcol" - parts := make([]*otlpcommon.AnyValue, 3) - parts[0] = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "otelcol"}} - parts[1] = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "--config=/etc/otel-collector-config.yaml"}} - parts[2] = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "--mem-ballast-size-mib=683"}} + parts := make([]otlpcommon.AnyValue, 3) + parts[0] = otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "otelcol"}} + parts[1] = otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "--config=/etc/otel-collector-config.yaml"}} + parts[2] = otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "--mem-ballast-size-mib=683"}} attrMap[conventions.AttributeProcessCommandLine] = &otlpcommon.ArrayValue{ Values: parts, } diff --git a/internal/goldendataset/span_generator.go b/internal/goldendataset/span_generator.go index 174085d8869..d8f38a199fc 100644 --- a/internal/goldendataset/span_generator.go +++ b/internal/goldendataset/span_generator.go @@ -408,10 +408,10 @@ func generateMaxCountAttributes(includeStatus bool) map[string]interface{} { attrMap["ai-sampler.absolute"] = false attrMap["ai-sampler.maxhops"] = int64(6) attrMap["application.create.location"] = "https://api.opentelemetry.io/blog/posts/806673B9-4F4D-4284-9635-3A3E3E3805BE" - stages := make([]*otlpcommon.AnyValue, 3) - stages[0] = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "Launch"}} - stages[1] = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "Injestion"}} - stages[2] = &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "Validation"}} + stages := make([]otlpcommon.AnyValue, 3) + stages[0] = otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "Launch"}} + stages[1] = otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "Injestion"}} + stages[2] = otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "Validation"}} attrMap["application.stages"] = &otlpcommon.ArrayValue{ Values: stages, } diff --git a/internal/testdata/common.go b/internal/testdata/common.go index 91b2eb88c6a..ae61c3d2039 100644 --- a/internal/testdata/common.go +++ b/internal/testdata/common.go @@ -48,7 +48,7 @@ func generateOtlpResourceAttributes1() []otlpcommon.KeyValue { return []otlpcommon.KeyValue{ { Key: "resource-attr", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "resource-attr-val-1"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "resource-attr-val-1"}}, }, } } @@ -61,7 +61,7 @@ func generateOtlpResourceAttributes2() []otlpcommon.KeyValue { return []otlpcommon.KeyValue{ { Key: "resource-attr", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "resource-attr-val-2"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "resource-attr-val-2"}}, }, } } @@ -74,7 +74,7 @@ func generateOtlpSpanAttributes() []otlpcommon.KeyValue { return []otlpcommon.KeyValue{ { Key: "span-attr", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-attr-val"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-attr-val"}}, }, } } @@ -87,7 +87,7 @@ func generateOtlpSpanEventAttributes() []otlpcommon.KeyValue { return []otlpcommon.KeyValue{ { Key: "span-event-attr", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-event-attr-val"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-event-attr-val"}}, }, } } @@ -100,7 +100,7 @@ func generateOtlpSpanLinkAttributes() []otlpcommon.KeyValue { return []otlpcommon.KeyValue{ { Key: "span-link-attr", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-link-attr-val"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "span-link-attr-val"}}, }, } } diff --git a/internal/testdata/log.go b/internal/testdata/log.go index b060452c9d6..4c437724448 100644 --- a/internal/testdata/log.go +++ b/internal/testdata/log.go @@ -300,17 +300,17 @@ func generateOtlpLogOne() *otlplogs.LogRecord { DroppedAttributesCount: 1, SeverityNumber: otlplogs.SeverityNumber_SEVERITY_NUMBER_INFO, SeverityText: "Info", - Body: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "This is a log message"}}, + Body: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "This is a log message"}}, SpanId: data.NewSpanID([8]byte{0x01, 0x02, 0x04, 0x08}), TraceId: data.NewTraceID([16]byte{0x08, 0x04, 0x02, 0x01}), Attributes: []otlpcommon.KeyValue{ { Key: "app", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "server"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "server"}}, }, { Key: "instance_num", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: 1}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: 1}}, }, }, } @@ -337,15 +337,15 @@ func generateOtlpLogTwo() *otlplogs.LogRecord { DroppedAttributesCount: 1, SeverityNumber: otlplogs.SeverityNumber_SEVERITY_NUMBER_INFO, SeverityText: "Info", - Body: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "something happened"}}, + Body: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "something happened"}}, Attributes: []otlpcommon.KeyValue{ { Key: "customer", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "acme"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "acme"}}, }, { Key: "env", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "dev"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "dev"}}, }, }, } @@ -368,7 +368,7 @@ func generateOtlpLogThree() *otlplogs.LogRecord { DroppedAttributesCount: 1, SeverityNumber: otlplogs.SeverityNumber_SEVERITY_NUMBER_WARN, SeverityText: "Warning", - Body: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "something else happened"}}, + Body: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "something else happened"}}, } } diff --git a/proto_patch.sed b/proto_patch.sed index 53a1a67e519..2c07d098406 100644 --- a/proto_patch.sed +++ b/proto_patch.sed @@ -24,6 +24,16 @@ s+repeated opentelemetry.proto.common.v1.KeyValue \(.*\);+repeated opentelemetry s+repeated KeyValue \(.*\);+repeated KeyValue \1\ [ (gogoproto.nullable) = false ];+g +s+repeated opentelemetry.proto.common.v1.AnyValue \(.*\);+repeated opentelemetry.proto.common.v1.AnyValue \1\ + [\ + (gogoproto.nullable) = false\ + ];+g + +s+AnyValue \(.*\);+AnyValue \1\ + [\ + (gogoproto.nullable) = false\ + ];+g + s+repeated opentelemetry.proto.common.v1.StringKeyValue \(.*\);+repeated opentelemetry.proto.common.v1.StringKeyValue \1\ [ (gogoproto.nullable) = false ];+g diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 124c1d558b2..a14a1c09da9 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -101,7 +101,7 @@ var resourceSpansOtlp = otlptrace.ResourceSpans{ Attributes: []otlpcommon.KeyValue{ { Key: conventions.AttributeHostName, - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "testHost"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "testHost"}}, }, }, }, @@ -117,7 +117,7 @@ var resourceSpansOtlp = otlptrace.ResourceSpans{ Attributes: []otlpcommon.KeyValue{ { Key: "attr1", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: 55}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: 55}}, }, }, }, diff --git a/receiver/zipkinreceiver/proto_parse_test.go b/receiver/zipkinreceiver/proto_parse_test.go index 53649ff05e3..dfba6521b7e 100644 --- a/receiver/zipkinreceiver/proto_parse_test.go +++ b/receiver/zipkinreceiver/proto_parse_test.go @@ -117,7 +117,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: conventions.AttributeServiceName, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "svc-1", }, @@ -138,7 +138,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: conventions.AttributeNetHostIP, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "192.168.0.1", }, @@ -146,7 +146,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetHostPort, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_IntValue{ IntValue: 8009, }, @@ -154,7 +154,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetPeerName, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "memcached", }, @@ -162,7 +162,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetPeerIP, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "fe80::1453:a77c:da4d:d21b", }, @@ -170,7 +170,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetPeerPort, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_IntValue{ IntValue: 11211, }, @@ -178,7 +178,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: tracetranslator.TagSpanKind, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: string(tracetranslator.OpenTracingSpanKindConsumer), }, @@ -195,7 +195,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: conventions.AttributeServiceName, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "search", }, @@ -216,7 +216,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { Attributes: []otlpcommon.KeyValue{ { Key: conventions.AttributeNetHostIP, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "10.0.0.13", }, @@ -224,7 +224,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetHostPort, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_IntValue{ IntValue: 8009, }, @@ -232,7 +232,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetPeerName, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "redis", }, @@ -240,7 +240,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetPeerIP, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "fe80::1453:a77c:da4d:d21b", }, @@ -248,7 +248,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: conventions.AttributeNetPeerPort, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_IntValue{ IntValue: 6379, }, @@ -256,7 +256,7 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) { }, { Key: tracetranslator.TagSpanKind, - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: string(tracetranslator.OpenTracingSpanKindProducer), }, diff --git a/testbed/testbed/senders.go b/testbed/testbed/senders.go index 14af5c48cad..3e00b497d30 100644 --- a/testbed/testbed/senders.go +++ b/testbed/testbed/senders.go @@ -686,10 +686,7 @@ func (f *FluentBitFileLogWriter) convertLogToJSON(lr pdata.LogRecord) []byte { rec := map[string]string{ "time": time.Unix(0, int64(lr.Timestamp())).Format("02/01/2006:15:04:05Z"), } - - if !lr.Body().IsNil() { - rec["log"] = lr.Body().StringVal() - } + rec["log"] = lr.Body().StringVal() lr.Attributes().ForEach(func(k string, v pdata.AttributeValue) { switch v.Type() { diff --git a/testbed/testbed/validator.go b/testbed/testbed/validator.go index c2ec33d9432..fafdd6bad0b 100644 --- a/testbed/testbed/validator.go +++ b/testbed/testbed/validator.go @@ -509,7 +509,7 @@ func convertAttributesSliceToMap(attributes []otlpcommon.KeyValue) map[string]ot } func retrieveAttributeValue(attribute otlpcommon.KeyValue) interface{} { - if attribute.Value == nil || attribute.Value.Value == nil { + if attribute.Value.Value == nil { return nil } @@ -579,7 +579,7 @@ func convertKVListToJSONString(values []otlpcommon.KeyValue) string { return "" } -func convertArrayValuesToJSONString(values []*otlpcommon.AnyValue) string { +func convertArrayValuesToJSONString(values []otlpcommon.AnyValue) string { jsonStr, err := json.Marshal(convertArrayValuesToRawSlice(values)) if err == nil { return string(jsonStr) @@ -589,9 +589,9 @@ func convertArrayValuesToJSONString(values []*otlpcommon.AnyValue) string { func convertKVListToRawMap(values []otlpcommon.KeyValue) map[string]interface{} { rawMap := make(map[string]interface{}) - for _, kv := range values { - var value *otlpcommon.AnyValue = kv.GetValue() - switch val := value.GetValue().(type) { + for i := range values { + kv := &values[i] + switch val := kv.Value.GetValue().(type) { case *otlpcommon.AnyValue_StringValue: rawMap[kv.Key] = val.StringValue case *otlpcommon.AnyValue_IntValue: @@ -611,7 +611,7 @@ func convertKVListToRawMap(values []otlpcommon.KeyValue) map[string]interface{} return rawMap } -func convertArrayValuesToRawSlice(values []*otlpcommon.AnyValue) []interface{} { +func convertArrayValuesToRawSlice(values []otlpcommon.AnyValue) []interface{} { rawSlice := make([]interface{}, 0, len(values)) for _, v := range values { switch val := v.GetValue().(type) { diff --git a/testbed/tests/resource_processor_test.go b/testbed/tests/resource_processor_test.go index 6de88a4d6e0..c1c6dfc95b5 100644 --- a/testbed/tests/resource_processor_test.go +++ b/testbed/tests/resource_processor_test.go @@ -35,7 +35,7 @@ var ( Attributes: []otlpcommon.KeyValue{ { Key: "opencensus.resourcetype", - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "host", }, @@ -43,7 +43,7 @@ var ( }, { Key: "label-key", - Value: &otlpcommon.AnyValue{ + Value: otlpcommon.AnyValue{ Value: &otlpcommon.AnyValue_StringValue{ StringValue: "label-value", }, @@ -153,11 +153,11 @@ func getResourceProcessorTestCases() []resourceProcessorTestCase { Attributes: []otlpcommon.KeyValue{ { Key: "resource-type", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "host"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "host"}}, }, { Key: "label-key", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "new-label-value"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "new-label-value"}}, }, }, }, @@ -179,7 +179,7 @@ func getResourceProcessorTestCases() []resourceProcessorTestCase { Attributes: []otlpcommon.KeyValue{ { Key: "additional-label-key", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "additional-label-value"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "additional-label-value"}}, }, }, }, @@ -200,7 +200,7 @@ func getResourceProcessorTestCases() []resourceProcessorTestCase { Attributes: []otlpcommon.KeyValue{ { Key: "additional-label-key", - Value: &otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "additional-label-value"}}, + Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "additional-label-value"}}, }, }, }, diff --git a/testutil/logstest/logs.go b/testutil/logstest/logs.go index 3d3dfa7635e..962e2e6214e 100644 --- a/testutil/logstest/logs.go +++ b/testutil/logstest/logs.go @@ -42,9 +42,7 @@ func Logs(recs ...Log) pdata.Logs { logSlice.Resize(len(recs)) for i := range recs { l := logSlice.At(i) - if !recs[i].Body.IsNil() { - recs[i].Body.CopyTo(l.Body()) - } + recs[i].Body.CopyTo(l.Body()) l.SetTimestamp(pdata.TimestampUnixNano(recs[i].Timestamp)) l.Attributes().InitFromMap(recs[i].Attributes) l.Attributes().Sort()