diff --git a/pdata/internal/cmd/pdatagen/internal/base_fields.go b/pdata/internal/cmd/pdatagen/internal/base_fields.go index 26bcb65c0a7..ba0ed0a5498 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_fields.go +++ b/pdata/internal/cmd/pdatagen/internal/base_fields.go @@ -21,11 +21,23 @@ import ( ) const accessorSliceTemplate = `// ${fieldName} returns the ${fieldName} associated with this ${structName}. +func (ms ${structName}) ${fieldName}() ${returnType} { + return new${returnType}(&ms.${origAccessor}.${fieldName}) +}` + +const accessorSliceTemplateCommon = `// ${fieldName} returns the ${fieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { - return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${fieldName})) + return ${packageName}${returnType}(internal.New${returnType}(&ms.${origAccessor}.${fieldName})) }` const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { + ms := New${structName}() + assert.Equal(t, New${returnType}(), ms.${fieldName}()) + fillTest${returnType}(ms.${fieldName}()) + assert.Equal(t, generateTest${returnType}(), ms.${fieldName}()) +}` + +const accessorsSliceTestTemplateCommon = `func Test${structName}_${fieldName}(t *testing.T) { ms := New${structName}() assert.Equal(t, ${packageName}New${returnType}(), ms.${fieldName}()) internal.FillTest${returnType}(internal.${returnType}(ms.${fieldName}())) @@ -33,11 +45,22 @@ const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testi }` const accessorsMessageValueTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. +func (ms ${structName}) ${fieldName}() ${returnType} { + return new${returnType}(&ms.${origAccessor}.${fieldName}) +}` + +const accessorsMessageValueTemplateCommon = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { - return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${fieldName})) + return ${packageName}${returnType}(internal.New${returnType}(&ms.${origAccessor}.${fieldName})) }` const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { + ms := New${structName}() + fillTest${returnType}(ms.${fieldName}()) + assert.Equal(t, generateTest${returnType}(), ms.${fieldName}()) +}` + +const accessorsMessageValueTestTemplateCommon = `func Test${structName}_${fieldName}(t *testing.T) { ms := New${structName}() internal.FillTest${returnType}(internal.${returnType}(ms.${fieldName}())) assert.Equal(t, ${packageName}${returnType}(internal.GenerateTest${returnType}()), ms.${fieldName}()) @@ -45,23 +68,23 @@ const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t const accessorsPrimitiveTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { - return ms.getOrig().${fieldName} + return ms.${origAccessor}.${fieldName} } // Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) Set${fieldName}(v ${returnType}) { - ms.getOrig().${fieldName} = v + ms.${origAccessor}.${fieldName} = v }` const accessorsPrimitiveSliceTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { - return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${fieldName})) + return ${packageName}${returnType}(internal.New${returnType}(&ms.${origAccessor}.${fieldName})) }` const oneOfTypeAccessorHeaderTemplate = `// ${typeFuncName} returns the type of the ${lowerOriginFieldName} for this ${structName}. // Calling this function on zero-initialized ${structName} will cause a panic. func (ms ${structName}) ${typeFuncName}() ${typeName} { - switch ms.getOrig().${originFieldName}.(type) {` + switch ms.${origAccessor}.${originFieldName}.(type) {` const oneOfTypeAccessorHeaderTestTemplate = `func Test${structName}_${typeFuncName}(t *testing.T) { tv := New${structName}() @@ -76,7 +99,7 @@ const accessorsOneOfMessageTemplate = `// ${fieldName} returns the ${lowerFieldN // // Calling this function on zero-initialized ${structName} will cause a panic. func (ms ${structName}) ${fieldName}() ${returnType} { - v, ok := ms.getOrig().Get${originOneOfFieldName}().(*${originStructType}) + v, ok := ms.orig.Get${originOneOfFieldName}().(*${originStructType}) if !ok { return ${returnType}{} } @@ -90,20 +113,20 @@ func (ms ${structName}) ${fieldName}() ${returnType} { // Calling this function on zero-initialized ${structName} will cause a panic. func (ms ${structName}) SetEmpty${fieldName}() ${returnType} { val := &${originFieldPackageName}.${fieldName}{} - ms.getOrig().${originOneOfFieldName} = &${originStructType}{${fieldName}: val} + ms.orig.${originOneOfFieldName} = &${originStructType}{${fieldName}: val} return new${returnType}(val) }` const accessorsOneOfMessageTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { ms := New${structName}() - internal.FillTest${returnType}(internal.${returnType}(ms.SetEmpty${fieldName}())) + fillTest${returnType}(ms.SetEmpty${fieldName}()) assert.Equal(t, ${typeName}, ms.${originOneOfTypeFuncName}()) - assert.Equal(t, ${returnType}(internal.GenerateTest${returnType}()), ms.${fieldName}()) + assert.Equal(t, generateTest${returnType}(), ms.${fieldName}()) } func Test${structName}_CopyTo_${fieldName}(t *testing.T) { ms := New${structName}() - internal.FillTest${returnType}(internal.${returnType}(ms.SetEmpty${fieldName}())) + fillTest${returnType}(ms.SetEmpty${fieldName}()) dest := New${structName}() ms.CopyTo(dest) assert.Equal(t, ms, dest) @@ -114,12 +137,12 @@ const copyToValueOneOfMessageTemplate = ` case ${typeName}: const accessorsOneOfPrimitiveTemplate = `// ${accessorFieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${accessorFieldName}() ${returnType} { - return ms.getOrig().Get${originFieldName}() + return ms.orig.Get${originFieldName}() } // Set${accessorFieldName} replaces the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) Set${accessorFieldName}(v ${returnType}) { - ms.getOrig().${originOneOfFieldName} = &${originStructType}{ + ms.orig.${originOneOfFieldName} = &${originStructType}{ ${originFieldName}: v, } }` @@ -141,12 +164,12 @@ const accessorsPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *t const accessorsPrimitiveTypedTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { - return ${packageName}${returnType}(ms.getOrig().${originFieldName}) + return ${packageName}${returnType}(ms.orig.${originFieldName}) } // Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) Set${fieldName}(v ${packageName}${returnType}) { - ms.getOrig().${originFieldName} = ${rawType}(v) + ms.orig.${originFieldName} = ${rawType}(v) }` const accessorsPrimitiveTypedTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { @@ -166,23 +189,23 @@ const accessorsPrimitiveSliceTestTemplate = `func Test${structName}_${fieldName} const accessorsOptionalPrimitiveValueTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${returnType} { - return ms.getOrig().Get${fieldName}() + return ms.orig.Get${fieldName}() } // Has${fieldName} returns true if the ${structName} contains a // ${fieldName} value, false otherwise. func (ms ${structName}) Has${fieldName}() bool { - return ms.getOrig().${fieldName}_ != nil + return ms.orig.${fieldName}_ != nil } // Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) Set${fieldName}(v ${returnType}) { - ms.getOrig().${fieldName}_ = &${originStructType}{${fieldName}: v} + ms.orig.${fieldName}_ = &${originStructType}{${fieldName}: v} } // Remove${fieldName} removes the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) Remove${fieldName}() { - ms.getOrig().${fieldName}_ = nil + ms.orig.${fieldName}_ = nil }` const accessorsOptionalPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { @@ -200,7 +223,7 @@ type baseField interface { generateAccessorsTest(ms baseStruct, sb *bytes.Buffer) - generateSetWithTestValue(sb *bytes.Buffer) + generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) generateCopyToValue(ms baseStruct, sb *bytes.Buffer) } @@ -211,7 +234,11 @@ type sliceField struct { } func (sf *sliceField) generateAccessors(ms baseStruct, sb *bytes.Buffer) { - sb.WriteString(os.Expand(accessorSliceTemplate, func(name string) string { + template := accessorSliceTemplate + if usedByOtherDataTypes(sf.returnSlice.getPackageName()) { + template = accessorSliceTemplateCommon + } + sb.WriteString(os.Expand(template, func(name string) string { switch name { case "structName": return ms.getName() @@ -224,6 +251,8 @@ func (sf *sliceField) generateAccessors(ms baseStruct, sb *bytes.Buffer) { return "" case "returnType": return sf.returnSlice.getName() + case "origAccessor": + return origAccessor(ms) default: panic(name) } @@ -231,7 +260,11 @@ func (sf *sliceField) generateAccessors(ms baseStruct, sb *bytes.Buffer) { } func (sf *sliceField) generateAccessorsTest(ms baseStruct, sb *bytes.Buffer) { - sb.WriteString(os.Expand(accessorsSliceTestTemplate, func(name string) string { + template := accessorsSliceTestTemplate + if usedByOtherDataTypes(sf.returnSlice.getPackageName()) { + template = accessorsSliceTestTemplateCommon + } + sb.WriteString(os.Expand(template, func(name string) string { switch name { case "structName": return ms.getName() @@ -250,8 +283,14 @@ func (sf *sliceField) generateAccessorsTest(ms baseStruct, sb *bytes.Buffer) { })) } -func (sf *sliceField) generateSetWithTestValue(sb *bytes.Buffer) { - sb.WriteString("\tFillTest" + sf.returnSlice.getName() + "(New" + sf.returnSlice.getName() + "(&tv.orig." + sf.fieldName + "))") +func (sf *sliceField) generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) { + if usedByOtherDataTypes(sf.returnSlice.getPackageName()) { + sb.WriteString("\t" + internalPackagePrefix(ms) + "FillTest" + sf.returnSlice.getName() + "(" + + internalPackagePrefix(ms) + "New") + } else { + sb.WriteString("\tfillTest" + sf.returnSlice.getName() + "(new") + } + sb.WriteString(sf.returnSlice.getName() + "(&tv.orig." + sf.fieldName + "))") } func (sf *sliceField) generateCopyToValue(_ baseStruct, sb *bytes.Buffer) { @@ -266,7 +305,11 @@ type messageValueField struct { } func (mf *messageValueField) generateAccessors(ms baseStruct, sb *bytes.Buffer) { - sb.WriteString(os.Expand(accessorsMessageValueTemplate, func(name string) string { + template := accessorsMessageValueTemplate + if usedByOtherDataTypes(mf.returnMessage.getPackageName()) { + template = accessorsMessageValueTemplateCommon + } + sb.WriteString(os.Expand(template, func(name string) string { switch name { case "structName": return ms.getName() @@ -281,6 +324,8 @@ func (mf *messageValueField) generateAccessors(ms baseStruct, sb *bytes.Buffer) return "" case "returnType": return mf.returnMessage.getName() + case "origAccessor": + return origAccessor(ms) default: panic(name) } @@ -288,7 +333,11 @@ func (mf *messageValueField) generateAccessors(ms baseStruct, sb *bytes.Buffer) } func (mf *messageValueField) generateAccessorsTest(ms baseStruct, sb *bytes.Buffer) { - sb.WriteString(os.Expand(accessorsMessageValueTestTemplate, func(name string) string { + template := accessorsMessageValueTestTemplate + if usedByOtherDataTypes(mf.returnMessage.getPackageName()) { + template = accessorsMessageValueTestTemplateCommon + } + sb.WriteString(os.Expand(template, func(name string) string { switch name { case "structName": return ms.getName() @@ -307,8 +356,14 @@ func (mf *messageValueField) generateAccessorsTest(ms baseStruct, sb *bytes.Buff })) } -func (mf *messageValueField) generateSetWithTestValue(sb *bytes.Buffer) { - sb.WriteString("\tFillTest" + mf.returnMessage.getName() + "(New" + mf.returnMessage.getName() + "(&tv.orig." + mf.fieldName + "))") +func (mf *messageValueField) generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) { + if usedByOtherDataTypes(mf.returnMessage.getPackageName()) { + sb.WriteString("\t" + internalPackagePrefix(ms) + "FillTest" + mf.returnMessage.getName() + "(" + + internalPackagePrefix(ms) + "New") + } else { + sb.WriteString("\tfillTest" + mf.returnMessage.getName() + "(new") + } + sb.WriteString(mf.returnMessage.getName() + "(&tv.orig." + mf.fieldName + "))") } func (mf *messageValueField) generateCopyToValue(_ baseStruct, sb *bytes.Buffer) { @@ -337,6 +392,8 @@ func (pf *primitiveField) generateAccessors(ms baseStruct, sb *bytes.Buffer) { return strings.ToLower(pf.fieldName) case "returnType": return pf.returnType + case "origAccessor": + return origAccessor(ms) default: panic(name) } @@ -362,7 +419,7 @@ func (pf *primitiveField) generateAccessorsTest(ms baseStruct, sb *bytes.Buffer) })) } -func (pf *primitiveField) generateSetWithTestValue(sb *bytes.Buffer) { +func (pf *primitiveField) generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) { sb.WriteString("\ttv.orig." + pf.fieldName + " = " + pf.testVal) } @@ -440,7 +497,7 @@ func (ptf *primitiveTypedField) generateAccessorsTest(ms baseStruct, sb *bytes.B })) } -func (ptf *primitiveTypedField) generateSetWithTestValue(sb *bytes.Buffer) { +func (ptf *primitiveTypedField) generateSetWithTestValue(_ baseStruct, sb *bytes.Buffer) { originFieldName := ptf.fieldName if ptf.originFieldName != "" { originFieldName = ptf.originFieldName @@ -480,6 +537,8 @@ func (psf *primitiveSliceField) generateAccessors(ms baseStruct, sb *bytes.Buffe return psf.returnPackageName + "." } return "" + case "origAccessor": + return origAccessor(ms) default: panic(name) } @@ -510,7 +569,7 @@ func (psf *primitiveSliceField) generateAccessorsTest(ms baseStruct, sb *bytes.B })) } -func (psf *primitiveSliceField) generateSetWithTestValue(sb *bytes.Buffer) { +func (psf *primitiveSliceField) generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) { sb.WriteString("\ttv.orig." + psf.fieldName + " = " + psf.testVal) } @@ -551,6 +610,8 @@ func (of *oneOfField) generateTypeAccessors(ms baseStruct, sb *bytes.Buffer) { return ms.getName() case "typeName": return of.typeName + case "origAccessor": + return origAccessor(ms) default: panic(name) } @@ -592,7 +653,7 @@ func (of *oneOfField) generateAccessorsTest(ms baseStruct, sb *bytes.Buffer) { } } -func (of *oneOfField) generateSetWithTestValue(sb *bytes.Buffer) { +func (of *oneOfField) generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) { of.values[of.testValueIdx].generateSetWithTestValue(of, sb) } @@ -749,7 +810,7 @@ func (omv *oneOfMessageValue) generateTests(ms baseStruct, of *oneOfField, sb *b func (omv *oneOfMessageValue) generateSetWithTestValue(of *oneOfField, sb *bytes.Buffer) { sb.WriteString("\ttv.orig." + of.originFieldName + " = &" + of.originTypePrefix + omv.fieldName + "{" + omv.fieldName + ": &" + omv.originFieldPackageName + "." + omv.fieldName + "{}}\n") - sb.WriteString("\tFillTest" + omv.returnMessage.structName + "(New" + omv.fieldName + "(tv.orig.Get" + omv.fieldName + "()))") + sb.WriteString("\tfillTest" + omv.returnMessage.structName + "(new" + omv.fieldName + "(tv.orig.Get" + omv.fieldName + "()))") } func (omv *oneOfMessageValue) generateCopyToValue(of *oneOfField, sb *bytes.Buffer) { @@ -823,7 +884,7 @@ func (opv *optionalPrimitiveValue) generateAccessorsTest(ms baseStruct, sb *byte sb.WriteString("\n") } -func (opv *optionalPrimitiveValue) generateSetWithTestValue(sb *bytes.Buffer) { +func (opv *optionalPrimitiveValue) generateSetWithTestValue(ms baseStruct, sb *bytes.Buffer) { sb.WriteString("\ttv.orig." + opv.fieldName + "_ = &" + opv.originTypePrefix + opv.fieldName + "{" + opv.fieldName + ":" + opv.testVal + "}") } @@ -834,3 +895,17 @@ func (opv *optionalPrimitiveValue) generateCopyToValue(_ baseStruct, sb *bytes.B } var _ baseField = (*optionalPrimitiveValue)(nil) + +func origAccessor(bs baseStruct) string { + if usedByOtherDataTypes(bs.getPackageName()) { + return "getOrig()" + } + return "orig" +} + +func internalPackagePrefix(bs baseStruct) string { + if usedByOtherDataTypes(bs.getPackageName()) { + return "" + } + return "internal." +} diff --git a/pdata/internal/cmd/pdatagen/internal/base_slices.go b/pdata/internal/cmd/pdatagen/internal/base_slices.go index b866100ef6c..8e281481fa7 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_slices.go +++ b/pdata/internal/cmd/pdatagen/internal/base_slices.go @@ -23,20 +23,20 @@ const commonSliceTemplate = ` // 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.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ${structName}) RemoveIf(f func(${elementName}) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -45,33 +45,33 @@ func (es ${structName}) RemoveIf(f func(${elementName}) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] }` const commonSliceTestTemplate = ` func Test${structName}_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ${structName}(internal.GenerateTest${structName}()) + expectedSlice := generateTest${structName}() dest := New${structName}() - src := ${structName}(internal.GenerateTest${structName}()) + src := generateTest${structName}() src.MoveAndAppendTo(dest) - assert.Equal(t, ${structName}(internal.GenerateTest${structName}()), dest) + assert.Equal(t, generateTest${structName}(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ${structName}(internal.GenerateTest${structName}()), dest) + assert.Equal(t, generateTest${structName}(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ${structName}(internal.GenerateTest${structName}()).MoveAndAppendTo(dest) + generateTest${structName}().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -88,7 +88,7 @@ func Test${structName}_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ${structName}(internal.GenerateTest${structName}()) + filtered := generateTest${structName}() pos := 0 filtered.RemoveIf(func(el ${elementName}) bool { pos++ @@ -104,14 +104,12 @@ const slicePtrTemplate = `// ${structName} logically represents a slice of ${ele // // Must use New${structName} function to create new instances. // Important: zero-initialized instance is not valid for use. -type ${structName} internal.${structName} - -func new${structName}(orig *[]*${originName}) ${structName} { - return ${structName}(internal.New${structName}(orig)) +type ${structName} struct { + orig *[]*${originName} } -func (ms ${structName}) getOrig() *[]*${originName} { - return internal.GetOrig${structName}(internal.${structName}(ms)) +func new${structName}(orig *[]*${originName}) ${structName} { + return ${structName}{orig} } // New${structName} creates a ${structName} with 0 elements. @@ -125,7 +123,7 @@ func New${structName}() ${structName} { // // Returns "0" for a newly instance created with "New${structName}()". func (es ${structName}) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -136,27 +134,27 @@ func (es ${structName}) Len() int { // ... // Do something with the element // } func (es ${structName}) At(ix int) ${elementName} { - return new${elementName}((*es.getOrig())[ix]) + return new${elementName}((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ${structName}) CopyTo(dest ${structName}) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - new${elementName}((*es.getOrig())[i]).CopyTo(new${elementName}((*dest.getOrig())[i])) + (*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.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - new${elementName}((*es.getOrig())[i]).CopyTo(new${elementName}(wrappers[i])) + new${elementName}((*es.orig)[i]).CopyTo(new${elementName}(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -171,20 +169,20 @@ func (es ${structName}) CopyTo(dest ${structName}) { // // Here should set all the values for e. // } func (es ${structName}) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*${originName}, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*${originName}, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ${elementName}. // It returns the newly added ${elementName}. func (es ${structName}) AppendEmpty() ${elementName} { - *es.getOrig() = append(*es.getOrig(), &${originName}{}) + *es.orig = append(*es.orig, &${originName}{}) return es.At(es.Len() - 1) } @@ -192,7 +190,7 @@ func (es ${structName}) AppendEmpty() ${elementName} { // provided less function so that two instances of ${structName} // can be compared. func (es ${structName}) Sort(less func(a, b ${elementName}) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } ` @@ -204,12 +202,12 @@ const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { es.EnsureCapacity(7) emptyVal := new${elementName}(&${originName}{}) - testVal := ${elementName}(internal.GenerateTest${elementName}()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTest${elementName}() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTest${elementName}(internal.${elementName}(el)) + fillTest${elementName}(el) assert.Equal(t, testVal, el) } } @@ -221,28 +219,28 @@ func Test${structName}_CopyTo(t *testing.T) { assert.Equal(t, New${structName}(), dest) // Test CopyTo larger slice - ${structName}(internal.GenerateTest${structName}()).CopyTo(dest) - assert.Equal(t, ${structName}(internal.GenerateTest${structName}()), dest) + generateTest${structName}().CopyTo(dest) + assert.Equal(t, generateTest${structName}(), dest) // Test CopyTo same size slice - ${structName}(internal.GenerateTest${structName}()).CopyTo(dest) - assert.Equal(t, ${structName}(internal.GenerateTest${structName}()), dest) + generateTest${structName}().CopyTo(dest) + assert.Equal(t, generateTest${structName}(), dest) } func Test${structName}_EnsureCapacity(t *testing.T) { - es := ${structName}(internal.GenerateTest${structName}()) + es := generateTest${structName}() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*${originName}]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*${originName}]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -251,46 +249,34 @@ func Test${structName}_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*${originName}]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*${originName}]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) }` -const slicePtrGenerateTest = `func GenerateTest${structName}() ${structName} { - orig := []*${originName}{} - tv := New${structName}(&orig) - FillTest${structName}(tv) +const slicePtrGenerateTest = ` + +func generateTest${structName}() ${structName} { + tv := New${structName}() + fillTest${structName}(tv) return tv } -func FillTest${structName}(tv ${structName}) { +func fillTest${structName}(tv ${structName}) { *tv.orig = make([]*${originName}, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &${originName}{} - FillTest${elementName}(New${elementName}((*tv.orig)[i])) + fillTest${elementName}(new${elementName}((*tv.orig)[i])) } }` -const slicePtrInternalTemplate = ` -type ${structName} struct { - orig *[]*${originName} -} - -func GetOrig${structName}(ms ${structName}) *[]*${originName} { - return ms.orig -} - -func New${structName}(orig *[]*${originName}) ${structName} { - return ${structName}{orig: orig} -}` - const sliceValueTemplate = `// ${structName} logically represents a slice of ${elementName}. // // This is a reference type. If passed by value and callee modifies it, the @@ -298,28 +284,26 @@ const sliceValueTemplate = `// ${structName} logically represents a slice of ${e // // Must use New${structName} function to create new instances. // Important: zero-initialized instance is not valid for use. -type ${structName} internal.${structName} - -func new${structName}(orig *[]${originName}) ${structName} { - return ${structName}(internal.New${structName}(orig)) +type ${structName} struct { + orig *[]${originName} } -func (ms ${structName}) getOrig() *[]${originName} { - return internal.GetOrig${structName}(internal.${structName}(ms)) +func new${structName}(orig *[]${originName}) ${structName} { + return ${structName}{orig} } // New${structName} creates a ${structName} with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. func New${structName}() ${structName} { orig := []${originName}(nil) - return ${structName}(internal.New${structName}(&orig)) + return new${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.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -330,21 +314,21 @@ func (es ${structName}) Len() int { // ... // Do something with the element // } func (es ${structName}) At(ix int) ${elementName} { - return new${elementName}(&(*es.getOrig())[ix]) + return new${elementName}(&(*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ${structName}) CopyTo(dest ${structName}) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] + (*dest.orig) = (*dest.orig)[:srcLen:destCap] } else { - (*dest.getOrig()) = make([]${originName}, srcLen) + (*dest.orig) = make([]${originName}, srcLen) } - for i := range *es.getOrig() { - new${elementName}(&(*es.getOrig())[i]).CopyTo(new${elementName}(&(*dest.getOrig())[i])) + for i := range *es.orig { + new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&(*dest.orig)[i])) } } @@ -360,20 +344,20 @@ func (es ${structName}) CopyTo(dest ${structName}) { // // Here should set all the values for e. // } func (es ${structName}) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]${originName}, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]${originName}, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ${elementName}. // It returns the newly added ${elementName}. func (es ${structName}) AppendEmpty() ${elementName} { - *es.getOrig() = append(*es.getOrig(), ${originName}{}) + *es.orig = append(*es.orig, ${originName}{}) return es.At(es.Len() - 1) }` @@ -385,12 +369,12 @@ const sliceValueTestTemplate = `func Test${structName}(t *testing.T) { es.EnsureCapacity(7) emptyVal := new${elementName}(&${originName}{}) - testVal := ${elementName}(internal.GenerateTest${elementName}()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTest${elementName}() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTest${elementName}(internal.${elementName}(el)) + fillTest${elementName}(el) assert.Equal(t, testVal, el) } } @@ -402,28 +386,28 @@ func Test${structName}_CopyTo(t *testing.T) { assert.Equal(t, New${structName}(), dest) // Test CopyTo larger slice - ${structName}(internal.GenerateTest${structName}()).CopyTo(dest) - assert.Equal(t, ${structName}(internal.GenerateTest${structName}()), dest) + generateTest${structName}().CopyTo(dest) + assert.Equal(t, generateTest${structName}(), dest) // Test CopyTo same size slice - ${structName}(internal.GenerateTest${structName}()).CopyTo(dest) - assert.Equal(t, ${structName}(internal.GenerateTest${structName}()), dest) + generateTest${structName}().CopyTo(dest) + assert.Equal(t, generateTest${structName}(), dest) } func Test${structName}_EnsureCapacity(t *testing.T) { - es := ${structName}(internal.GenerateTest${structName}()) + es := generateTest${structName}() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*${originName}]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*${originName}]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -432,42 +416,28 @@ func Test${structName}_EnsureCapacity(t *testing.T) { oldLen := es.Len() assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) }` -const sliceValueGenerateTest = `func GenerateTest${structName}() ${structName} { - orig := []${originName}{} - tv := New${structName}(&orig) - FillTest${structName}(tv) +const sliceValueGenerateTest = `func generateTest${structName}() ${structName} { + tv := New${structName}() + fillTest${structName}(tv) return tv } -func FillTest${structName}(tv ${structName}) { +func fillTest${structName}(tv ${structName}) { *tv.orig = make([]${originName}, 7) for i := 0; i < 7; i++ { - FillTest${elementName}(New${elementName}(&(*tv.orig)[i])) + fillTest${elementName}(new${elementName}(&(*tv.orig)[i])) } }` -const sliceValueInternalTemplate = ` -type ${structName} struct { - orig *[]${originName} -} - -func GetOrig${structName}(ms ${structName}) *[]${originName} { - return ms.orig -} - -func New${structName}(orig *[]${originName}) ${structName} { - return ${structName}{orig: orig} -}` - type baseSlice interface { getName() string getPackageName() string } -// Will generate code only for a slice of pointer fields. +// sliceOfPtrs generates code for a slice of pointer fields. The generated structs cannot be used from other packages. type sliceOfPtrs struct { structName string packageName string @@ -511,23 +481,11 @@ func (ss *sliceOfPtrs) templateFields() func(name string) string { } } -func (ss *sliceOfPtrs) generateInternal(sb *bytes.Buffer) { - sb.WriteString(os.Expand(slicePtrInternalTemplate, func(name string) string { - switch name { - case "structName": - return ss.structName - case "originName": - return ss.element.originFullName - default: - panic(name) - } - })) - sb.WriteString(newLine + newLine) -} +func (ss *sliceOfPtrs) generateInternal(_ *bytes.Buffer) {} var _ baseStruct = (*sliceOfPtrs)(nil) -// Will generate code only for a slice of value fields. +// sliceOfValues generates code for a slice of pointer fields. The generated structs cannot be used from other packages. type sliceOfValues struct { structName string packageName string @@ -571,18 +529,6 @@ func (ss *sliceOfValues) templateFields() func(name string) string { } } -func (ss *sliceOfValues) generateInternal(sb *bytes.Buffer) { - sb.WriteString(os.Expand(sliceValueInternalTemplate, func(name string) string { - switch name { - case "structName": - return ss.structName - case "originName": - return ss.element.originFullName - default: - panic(name) - } - })) - sb.WriteString(newLine + newLine) -} +func (ss *sliceOfValues) generateInternal(_ *bytes.Buffer) {} var _ baseStruct = (*sliceOfValues)(nil) diff --git a/pdata/internal/cmd/pdatagen/internal/base_structs.go b/pdata/internal/cmd/pdatagen/internal/base_structs.go index 38a1f58de96..655ec3e6f46 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/base_structs.go @@ -26,15 +26,10 @@ const messageValueTemplate = `${description} // // Must use New${structName} function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ${structName} internal.${internalStructName} +${typeDeclaration} func new${structName}(orig *${originName}) ${structName} { - return ${structName}(internal.New${internalStructName}(orig)) -} - -func (ms ${structName}) getOrig() *${originName} { - return internal.GetOrig${internalStructName}(internal.${internalStructName}(ms)) + return ${newFuncValue} } // New${structName} creates a new empty ${structName}. @@ -48,8 +43,12 @@ func New${structName}() ${structName} { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ${structName}) MoveTo(dest ${structName}) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = ${originName}{} + *dest.${origAccessor} = *ms.${origAccessor} + *ms.${origAccessor} = ${originName}{} +}` + +const messageValueGetOrigTemplate = `func (ms ${structName}) getOrig() *${originName} { + return internal.GetOrig${structName}(internal.${structName}(ms)) }` const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct overriding the destination. @@ -59,11 +58,11 @@ const messageValueCopyToFooterTemplate = `}` const messageValueTestTemplate = ` func Test${structName}_MoveTo(t *testing.T) { - ms := ${structName}(internal.GenerateTest${internalStructName}()) + ms := ${generateTestData} dest := New${structName}() ms.MoveTo(dest) assert.Equal(t, New${structName}(), ms) - assert.Equal(t, ${structName}(internal.GenerateTest${internalStructName}()), dest) + assert.Equal(t, ${generateTestData}, dest) } func Test${structName}_CopyTo(t *testing.T) { @@ -71,70 +70,62 @@ func Test${structName}_CopyTo(t *testing.T) { orig := New${structName}() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ${structName}(internal.GenerateTest${internalStructName}()) + orig = ${generateTestData} orig.CopyTo(ms) assert.Equal(t, orig, ms) }` -const messageValueGenerateTestTemplate = `func GenerateTest${internalStructName}() ${internalStructName} { - orig := ${originName}{} - tv := New${internalStructName}(&orig) - FillTest${internalStructName}(tv) +const messageValueGenerateTestTemplate = `func generateTest${structName}() ${structName} { + tv := New${structName}() + fillTest${structName}(tv) return tv }` -const messageValueFillTestHeaderTemplate = `func FillTest${internalStructName}(tv ${internalStructName}) {` -const messageValueFillTestFooterTemplate = `}` +const messageValueGenerateTestTemplateCommon = `func GenerateTest${structName}() ${structName} { + orig := ${originName}{} + tv := New${structName}(&orig) + FillTest${structName}(tv) + return tv +}` const messageValueAliasTemplate = ` -type ${internalStructName} struct { +type ${structName} struct { orig *${originName} } -func GetOrig${internalStructName}(ms ${internalStructName}) *${originName} { +func GetOrig${structName}(ms ${structName}) *${originName} { return ms.orig } -func New${internalStructName}(orig *${originName}) ${internalStructName} { - return ${internalStructName}{orig: orig} +func New${structName}(orig *${originName}) ${structName} { + return ${structName}{orig: orig} }` const newLine = "\n" type baseStruct interface { getName() string - getPackageName() string - generateStruct(sb *bytes.Buffer) - generateTests(sb *bytes.Buffer) - generateTestValueHelpers(sb *bytes.Buffer) - generateInternal(sb *bytes.Buffer) } +// messageValueStruct generates a struct for a proto message. The struct can be generated both as a common struct +// that can be used as a field in struct from other packages and as an isolated struct with depending on a package name. type messageValueStruct struct { - structName string - internalStructName string - packageName string - description string - originFullName string - fields []baseField + structName string + packageName string + description string + originFullName string + fields []baseField } func (ms *messageValueStruct) getName() string { return ms.structName } -func (ms *messageValueStruct) getInternalName() string { - if ms.internalStructName != "" { - return ms.internalStructName - } - return ms.structName -} - func (ms *messageValueStruct) getPackageName() string { return ms.packageName } @@ -144,16 +135,39 @@ func (ms *messageValueStruct) generateStruct(sb *bytes.Buffer) { switch name { case "structName": return ms.structName - case "internalStructName": - return ms.getInternalName() case "originName": return ms.originFullName case "description": return ms.description + case "typeDeclaration": + if usedByOtherDataTypes(ms.packageName) { + return "type " + ms.structName + " internal." + ms.structName + } + return "type " + ms.structName + " struct {\n\torig *" + ms.originFullName + "\n}" + case "newFuncValue": + if usedByOtherDataTypes(ms.packageName) { + return ms.structName + "(internal.New" + ms.structName + "(orig))" + } + return ms.structName + "{orig}" + case "origAccessor": + return origAccessor(ms) default: panic(name) } })) + if usedByOtherDataTypes(ms.packageName) { + sb.WriteString(newLine + newLine) + sb.WriteString(os.Expand(messageValueGetOrigTemplate, func(name string) string { + switch name { + case "structName": + return ms.structName + case "originName": + return ms.originFullName + default: + panic(name) + } + })) + } // Write accessors for the struct for _, f := range ms.fields { sb.WriteString(newLine + newLine) @@ -184,8 +198,11 @@ func (ms *messageValueStruct) generateTests(sb *bytes.Buffer) { switch name { case "structName": return ms.structName - case "internalStructName": - return ms.getInternalName() + case "generateTestData": + if usedByOtherDataTypes(ms.packageName) { + return ms.structName + "(internal.GenerateTest" + ms.structName + "())" + } + return "generateTest" + ms.structName + "()" default: panic(name) } @@ -199,41 +216,42 @@ func (ms *messageValueStruct) generateTests(sb *bytes.Buffer) { } func (ms *messageValueStruct) generateTestValueHelpers(sb *bytes.Buffer) { - sb.WriteString(os.Expand(messageValueGenerateTestTemplate, func(name string) string { + // Write generateTest func for the struct + template := messageValueGenerateTestTemplate + if usedByOtherDataTypes(ms.packageName) { + template = messageValueGenerateTestTemplateCommon + } + sb.WriteString(os.Expand(template, func(name string) string { switch name { - case "internalStructName": - return ms.getInternalName() + case "structName": + return ms.structName case "originName": return ms.originFullName default: panic(name) } })) - sb.WriteString(newLine + newLine) - sb.WriteString(os.Expand(messageValueFillTestHeaderTemplate, func(name string) string { - switch name { - case "internalStructName": - return ms.getInternalName() - default: - panic(name) - } - })) - // Write accessors test value for the struct + + // Write fillTest func for the struct + sb.WriteString(newLine + newLine + "func ") + if usedByOtherDataTypes(ms.packageName) { + sb.WriteString("FillTest") + } else { + sb.WriteString("fillTest") + } + sb.WriteString(ms.structName + "(tv " + ms.structName + ") {") for _, f := range ms.fields { sb.WriteString(newLine) - f.generateSetWithTestValue(sb) + f.generateSetWithTestValue(ms, sb) } - sb.WriteString(newLine) - sb.WriteString(os.Expand(messageValueFillTestFooterTemplate, func(name string) string { - panic(name) - })) + sb.WriteString(newLine + "}" + newLine) } func (ms *messageValueStruct) generateInternal(sb *bytes.Buffer) { sb.WriteString(os.Expand(messageValueAliasTemplate, func(name string) string { switch name { - case "internalStructName": - return ms.getInternalName() + case "structName": + return ms.structName case "originName": return ms.originFullName default: diff --git a/pdata/internal/cmd/pdatagen/internal/files.go b/pdata/internal/cmd/pdatagen/internal/files.go index eee78010762..225388274a9 100644 --- a/pdata/internal/cmd/pdatagen/internal/files.go +++ b/pdata/internal/cmd/pdatagen/internal/files.go @@ -109,6 +109,10 @@ func (f *File) GenerateTestFile() error { for _, s := range f.structs { sb.WriteString(newLine + newLine) s.generateTests(&sb) + if !usedByOtherDataTypes(f.PackageName) { + sb.WriteString(newLine + newLine) + s.generateTestValueHelpers(&sb) + } } // ignore gosec complain about permissions being `0644`. @@ -118,6 +122,10 @@ func (f *File) GenerateTestFile() error { // GenerateInternalFile generates the internal pdata structures for this File. func (f *File) GenerateInternalFile() error { + if !usedByOtherDataTypes(f.PackageName) { + return nil + } + var sb bytes.Buffer generateHeader(&sb, "internal") @@ -168,3 +176,9 @@ func generateHeader(sb *bytes.Buffer, packageName string) { sb.WriteString("package " + packageName) sb.WriteString(newLine + newLine) } + +// usedByOtherDataTypes defines if the package is used by other data types and orig fields of the package's structs +// need to be accessible from other pdata packages. +func usedByOtherDataTypes(packageName string) bool { + return packageName == "pcommon" +} diff --git a/pdata/internal/cmd/pdatagen/internal/pcommon_structs.go b/pdata/internal/cmd/pdatagen/internal/pcommon_structs.go index 0ce9cc7686f..20251bd4649 100644 --- a/pdata/internal/cmd/pdatagen/internal/pcommon_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/pcommon_structs.go @@ -31,7 +31,6 @@ var commonFile = &File{ }, structs: []baseStruct{ scope, - attributeValueSlice, }, } @@ -58,12 +57,6 @@ var scope = &messageValueStruct{ var mapStruct = &sliceOfPtrs{ structName: "Map", packageName: "pcommon", - element: attributeKeyValue, -} - -var attributeKeyValue = &messageValueStruct{ - structName: "Map", - packageName: "pcommon", } var scopeField = &messageValueField{ @@ -120,11 +113,6 @@ var anyValue = &messageValueStruct{ originFullName: "otlpcommon.AnyValue", } -var attributeValueSlice = &sliceOfValues{ - structName: "Slice", - element: anyValue, -} - var traceIDField = &primitiveTypedField{ fieldName: "TraceID", originFieldName: "TraceId", diff --git a/pdata/internal/cmd/pdatagen/internal/plogotlp_structs.go b/pdata/internal/cmd/pdatagen/internal/plogotlp_structs.go index c60cf7e8e05..c986ff7bce2 100644 --- a/pdata/internal/cmd/pdatagen/internal/plogotlp_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/plogotlp_structs.go @@ -41,10 +41,9 @@ var logOtlpFile = &File{ } var exportLogsPartialSuccess = &messageValueStruct{ - structName: "ExportPartialSuccess", - internalStructName: "LogsExportPartialSuccess", - description: "// ExportPartialSuccess represents the details of a partially successful export request.", - originFullName: "otlpcollectorlog.ExportLogsPartialSuccess", + structName: "ExportPartialSuccess", + description: "// ExportPartialSuccess represents the details of a partially successful export request.", + originFullName: "otlpcollectorlog.ExportLogsPartialSuccess", fields: []baseField{ &primitiveField{ fieldName: "RejectedLogRecords", diff --git a/pdata/internal/cmd/pdatagen/internal/pmetricotlp_structs.go b/pdata/internal/cmd/pdatagen/internal/pmetricotlp_structs.go index 9b8dcc186a1..8a00220e8df 100644 --- a/pdata/internal/cmd/pdatagen/internal/pmetricotlp_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/pmetricotlp_structs.go @@ -42,10 +42,9 @@ var metricsOtlpFile = &File{ } var exportMetricsPartialSuccess = &messageValueStruct{ - structName: "ExportPartialSuccess", - internalStructName: "MetricsExportPartialSuccess", - description: "// ExportPartialSuccess represents the details of a partially successful export request.", - originFullName: "otlpcollectormetrics.ExportMetricsPartialSuccess", + structName: "ExportPartialSuccess", + description: "// ExportPartialSuccess represents the details of a partially successful export request.", + originFullName: "otlpcollectormetrics.ExportMetricsPartialSuccess", fields: []baseField{ &primitiveField{ fieldName: "RejectedDataPoints", diff --git a/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go b/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go index ca814a046d5..6bee5b5dc4f 100644 --- a/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go @@ -165,6 +165,8 @@ func New${structName}(orig *[]${itemType}) ${structName} { return ${structName}{orig: orig} }` +// primitiveSliceStruct generates a struct for a slice of primitive value elements. The structs are always generated +// in a way that they can be used as fields in structs from other packages (using the internal package). type primitiveSliceStruct struct { structName string packageName string diff --git a/pdata/internal/cmd/pdatagen/internal/ptraceotlp_structs.go b/pdata/internal/cmd/pdatagen/internal/ptraceotlp_structs.go index 73ecc0ec8d2..2985a30c53d 100644 --- a/pdata/internal/cmd/pdatagen/internal/ptraceotlp_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/ptraceotlp_structs.go @@ -42,10 +42,9 @@ var traceOtlpFile = &File{ } var exportTracePartialSuccess = &messageValueStruct{ - structName: "ExportPartialSuccess", - internalStructName: "TracesExportPartialSuccess", - description: "// ExportPartialSuccess represents the details of a partially successful export request.", - originFullName: "otlpcollectortrace.ExportTracePartialSuccess", + structName: "ExportPartialSuccess", + description: "// ExportPartialSuccess represents the details of a partially successful export request.", + originFullName: "otlpcollectortrace.ExportTracePartialSuccess", fields: []baseField{ &primitiveField{ fieldName: "RejectedSpans", diff --git a/pdata/internal/generated_wrapper_common.go b/pdata/internal/generated_wrapper_common.go index 28c256c871c..4b790252a33 100644 --- a/pdata/internal/generated_wrapper_common.go +++ b/pdata/internal/generated_wrapper_common.go @@ -33,18 +33,6 @@ func NewInstrumentationScope(orig *otlpcommon.InstrumentationScope) Instrumentat return InstrumentationScope{orig: orig} } -type Slice struct { - orig *[]otlpcommon.AnyValue -} - -func GetOrigSlice(ms Slice) *[]otlpcommon.AnyValue { - return ms.orig -} - -func NewSlice(orig *[]otlpcommon.AnyValue) Slice { - return Slice{orig: orig} -} - func GenerateTestInstrumentationScope() InstrumentationScope { orig := otlpcommon.InstrumentationScope{} tv := NewInstrumentationScope(&orig) @@ -58,17 +46,3 @@ func FillTestInstrumentationScope(tv InstrumentationScope) { FillTestMap(NewMap(&tv.orig.Attributes)) tv.orig.DroppedAttributesCount = uint32(17) } - -func GenerateTestSlice() Slice { - orig := []otlpcommon.AnyValue{} - tv := NewSlice(&orig) - FillTestSlice(tv) - return tv -} - -func FillTestSlice(tv Slice) { - *tv.orig = make([]otlpcommon.AnyValue, 7) - for i := 0; i < 7; i++ { - FillTestValue(NewValue(&(*tv.orig)[i])) - } -} diff --git a/pdata/internal/generated_wrapper_logs.go b/pdata/internal/generated_wrapper_logs.go deleted file mode 100644 index 9c94a4237ca..00000000000 --- a/pdata/internal/generated_wrapper_logs.go +++ /dev/null @@ -1,186 +0,0 @@ -// 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. - -// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT. -// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go". - -package internal - -import ( - "go.opentelemetry.io/collector/pdata/internal/data" - otlplogs "go.opentelemetry.io/collector/pdata/internal/data/protogen/logs/v1" -) - -type ResourceLogsSlice struct { - orig *[]*otlplogs.ResourceLogs -} - -func GetOrigResourceLogsSlice(ms ResourceLogsSlice) *[]*otlplogs.ResourceLogs { - return ms.orig -} - -func NewResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) ResourceLogsSlice { - return ResourceLogsSlice{orig: orig} -} - -type ResourceLogs struct { - orig *otlplogs.ResourceLogs -} - -func GetOrigResourceLogs(ms ResourceLogs) *otlplogs.ResourceLogs { - return ms.orig -} - -func NewResourceLogs(orig *otlplogs.ResourceLogs) ResourceLogs { - return ResourceLogs{orig: orig} -} - -type ScopeLogsSlice struct { - orig *[]*otlplogs.ScopeLogs -} - -func GetOrigScopeLogsSlice(ms ScopeLogsSlice) *[]*otlplogs.ScopeLogs { - return ms.orig -} - -func NewScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) ScopeLogsSlice { - return ScopeLogsSlice{orig: orig} -} - -type ScopeLogs struct { - orig *otlplogs.ScopeLogs -} - -func GetOrigScopeLogs(ms ScopeLogs) *otlplogs.ScopeLogs { - return ms.orig -} - -func NewScopeLogs(orig *otlplogs.ScopeLogs) ScopeLogs { - return ScopeLogs{orig: orig} -} - -type LogRecordSlice struct { - orig *[]*otlplogs.LogRecord -} - -func GetOrigLogRecordSlice(ms LogRecordSlice) *[]*otlplogs.LogRecord { - return ms.orig -} - -func NewLogRecordSlice(orig *[]*otlplogs.LogRecord) LogRecordSlice { - return LogRecordSlice{orig: orig} -} - -type LogRecord struct { - orig *otlplogs.LogRecord -} - -func GetOrigLogRecord(ms LogRecord) *otlplogs.LogRecord { - return ms.orig -} - -func NewLogRecord(orig *otlplogs.LogRecord) LogRecord { - return LogRecord{orig: orig} -} - -func GenerateTestResourceLogsSlice() ResourceLogsSlice { - orig := []*otlplogs.ResourceLogs{} - tv := NewResourceLogsSlice(&orig) - FillTestResourceLogsSlice(tv) - return tv -} - -func FillTestResourceLogsSlice(tv ResourceLogsSlice) { - *tv.orig = make([]*otlplogs.ResourceLogs, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlplogs.ResourceLogs{} - FillTestResourceLogs(NewResourceLogs((*tv.orig)[i])) - } -} - -func GenerateTestResourceLogs() ResourceLogs { - orig := otlplogs.ResourceLogs{} - tv := NewResourceLogs(&orig) - FillTestResourceLogs(tv) - return tv -} - -func FillTestResourceLogs(tv ResourceLogs) { - FillTestResource(NewResource(&tv.orig.Resource)) - tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestScopeLogsSlice(NewScopeLogsSlice(&tv.orig.ScopeLogs)) -} - -func GenerateTestScopeLogsSlice() ScopeLogsSlice { - orig := []*otlplogs.ScopeLogs{} - tv := NewScopeLogsSlice(&orig) - FillTestScopeLogsSlice(tv) - return tv -} - -func FillTestScopeLogsSlice(tv ScopeLogsSlice) { - *tv.orig = make([]*otlplogs.ScopeLogs, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlplogs.ScopeLogs{} - FillTestScopeLogs(NewScopeLogs((*tv.orig)[i])) - } -} - -func GenerateTestScopeLogs() ScopeLogs { - orig := otlplogs.ScopeLogs{} - tv := NewScopeLogs(&orig) - FillTestScopeLogs(tv) - return tv -} - -func FillTestScopeLogs(tv ScopeLogs) { - FillTestInstrumentationScope(NewInstrumentationScope(&tv.orig.Scope)) - tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestLogRecordSlice(NewLogRecordSlice(&tv.orig.LogRecords)) -} - -func GenerateTestLogRecordSlice() LogRecordSlice { - orig := []*otlplogs.LogRecord{} - tv := NewLogRecordSlice(&orig) - FillTestLogRecordSlice(tv) - return tv -} - -func FillTestLogRecordSlice(tv LogRecordSlice) { - *tv.orig = make([]*otlplogs.LogRecord, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlplogs.LogRecord{} - FillTestLogRecord(NewLogRecord((*tv.orig)[i])) - } -} - -func GenerateTestLogRecord() LogRecord { - orig := otlplogs.LogRecord{} - tv := NewLogRecord(&orig) - FillTestLogRecord(tv) - return tv -} - -func FillTestLogRecord(tv LogRecord) { - tv.orig.ObservedTimeUnixNano = 1234567890 - tv.orig.TimeUnixNano = 1234567890 - tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) - tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) - tv.orig.Flags = 1 - tv.orig.SeverityText = "INFO" - tv.orig.SeverityNumber = otlplogs.SeverityNumber(5) - FillTestValue(NewValue(&tv.orig.Body)) - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.DroppedAttributesCount = uint32(17) -} diff --git a/pdata/internal/generated_wrapper_logs_otlp.go b/pdata/internal/generated_wrapper_logs_otlp.go deleted file mode 100644 index eb2109f0a92..00000000000 --- a/pdata/internal/generated_wrapper_logs_otlp.go +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT. -// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go". - -package internal - -import ( - otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1" -) - -type LogsExportPartialSuccess struct { - orig *otlpcollectorlog.ExportLogsPartialSuccess -} - -func GetOrigLogsExportPartialSuccess(ms LogsExportPartialSuccess) *otlpcollectorlog.ExportLogsPartialSuccess { - return ms.orig -} - -func NewLogsExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) LogsExportPartialSuccess { - return LogsExportPartialSuccess{orig: orig} -} - -func GenerateTestLogsExportPartialSuccess() LogsExportPartialSuccess { - orig := otlpcollectorlog.ExportLogsPartialSuccess{} - tv := NewLogsExportPartialSuccess(&orig) - FillTestLogsExportPartialSuccess(tv) - return tv -} - -func FillTestLogsExportPartialSuccess(tv LogsExportPartialSuccess) { - tv.orig.RejectedLogRecords = int64(13) - tv.orig.ErrorMessage = "error message" -} diff --git a/pdata/internal/generated_wrapper_metrics.go b/pdata/internal/generated_wrapper_metrics.go deleted file mode 100644 index 1345b0cab30..00000000000 --- a/pdata/internal/generated_wrapper_metrics.go +++ /dev/null @@ -1,661 +0,0 @@ -// 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. - -// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT. -// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go". - -package internal - -import ( - "go.opentelemetry.io/collector/pdata/internal/data" - otlpmetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1" -) - -type ResourceMetricsSlice struct { - orig *[]*otlpmetrics.ResourceMetrics -} - -func GetOrigResourceMetricsSlice(ms ResourceMetricsSlice) *[]*otlpmetrics.ResourceMetrics { - return ms.orig -} - -func NewResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) ResourceMetricsSlice { - return ResourceMetricsSlice{orig: orig} -} - -type ResourceMetrics struct { - orig *otlpmetrics.ResourceMetrics -} - -func GetOrigResourceMetrics(ms ResourceMetrics) *otlpmetrics.ResourceMetrics { - return ms.orig -} - -func NewResourceMetrics(orig *otlpmetrics.ResourceMetrics) ResourceMetrics { - return ResourceMetrics{orig: orig} -} - -type ScopeMetricsSlice struct { - orig *[]*otlpmetrics.ScopeMetrics -} - -func GetOrigScopeMetricsSlice(ms ScopeMetricsSlice) *[]*otlpmetrics.ScopeMetrics { - return ms.orig -} - -func NewScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) ScopeMetricsSlice { - return ScopeMetricsSlice{orig: orig} -} - -type ScopeMetrics struct { - orig *otlpmetrics.ScopeMetrics -} - -func GetOrigScopeMetrics(ms ScopeMetrics) *otlpmetrics.ScopeMetrics { - return ms.orig -} - -func NewScopeMetrics(orig *otlpmetrics.ScopeMetrics) ScopeMetrics { - return ScopeMetrics{orig: orig} -} - -type MetricSlice struct { - orig *[]*otlpmetrics.Metric -} - -func GetOrigMetricSlice(ms MetricSlice) *[]*otlpmetrics.Metric { - return ms.orig -} - -func NewMetricSlice(orig *[]*otlpmetrics.Metric) MetricSlice { - return MetricSlice{orig: orig} -} - -type Metric struct { - orig *otlpmetrics.Metric -} - -func GetOrigMetric(ms Metric) *otlpmetrics.Metric { - return ms.orig -} - -func NewMetric(orig *otlpmetrics.Metric) Metric { - return Metric{orig: orig} -} - -type Gauge struct { - orig *otlpmetrics.Gauge -} - -func GetOrigGauge(ms Gauge) *otlpmetrics.Gauge { - return ms.orig -} - -func NewGauge(orig *otlpmetrics.Gauge) Gauge { - return Gauge{orig: orig} -} - -type Sum struct { - orig *otlpmetrics.Sum -} - -func GetOrigSum(ms Sum) *otlpmetrics.Sum { - return ms.orig -} - -func NewSum(orig *otlpmetrics.Sum) Sum { - return Sum{orig: orig} -} - -type Histogram struct { - orig *otlpmetrics.Histogram -} - -func GetOrigHistogram(ms Histogram) *otlpmetrics.Histogram { - return ms.orig -} - -func NewHistogram(orig *otlpmetrics.Histogram) Histogram { - return Histogram{orig: orig} -} - -type ExponentialHistogram struct { - orig *otlpmetrics.ExponentialHistogram -} - -func GetOrigExponentialHistogram(ms ExponentialHistogram) *otlpmetrics.ExponentialHistogram { - return ms.orig -} - -func NewExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) ExponentialHistogram { - return ExponentialHistogram{orig: orig} -} - -type Summary struct { - orig *otlpmetrics.Summary -} - -func GetOrigSummary(ms Summary) *otlpmetrics.Summary { - return ms.orig -} - -func NewSummary(orig *otlpmetrics.Summary) Summary { - return Summary{orig: orig} -} - -type NumberDataPointSlice struct { - orig *[]*otlpmetrics.NumberDataPoint -} - -func GetOrigNumberDataPointSlice(ms NumberDataPointSlice) *[]*otlpmetrics.NumberDataPoint { - return ms.orig -} - -func NewNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) NumberDataPointSlice { - return NumberDataPointSlice{orig: orig} -} - -type NumberDataPoint struct { - orig *otlpmetrics.NumberDataPoint -} - -func GetOrigNumberDataPoint(ms NumberDataPoint) *otlpmetrics.NumberDataPoint { - return ms.orig -} - -func NewNumberDataPoint(orig *otlpmetrics.NumberDataPoint) NumberDataPoint { - return NumberDataPoint{orig: orig} -} - -type HistogramDataPointSlice struct { - orig *[]*otlpmetrics.HistogramDataPoint -} - -func GetOrigHistogramDataPointSlice(ms HistogramDataPointSlice) *[]*otlpmetrics.HistogramDataPoint { - return ms.orig -} - -func NewHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) HistogramDataPointSlice { - return HistogramDataPointSlice{orig: orig} -} - -type HistogramDataPoint struct { - orig *otlpmetrics.HistogramDataPoint -} - -func GetOrigHistogramDataPoint(ms HistogramDataPoint) *otlpmetrics.HistogramDataPoint { - return ms.orig -} - -func NewHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) HistogramDataPoint { - return HistogramDataPoint{orig: orig} -} - -type ExponentialHistogramDataPointSlice struct { - orig *[]*otlpmetrics.ExponentialHistogramDataPoint -} - -func GetOrigExponentialHistogramDataPointSlice(ms ExponentialHistogramDataPointSlice) *[]*otlpmetrics.ExponentialHistogramDataPoint { - return ms.orig -} - -func NewExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPointSlice { - return ExponentialHistogramDataPointSlice{orig: orig} -} - -type ExponentialHistogramDataPoint struct { - orig *otlpmetrics.ExponentialHistogramDataPoint -} - -func GetOrigExponentialHistogramDataPoint(ms ExponentialHistogramDataPoint) *otlpmetrics.ExponentialHistogramDataPoint { - return ms.orig -} - -func NewExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPoint { - return ExponentialHistogramDataPoint{orig: orig} -} - -type ExponentialHistogramDataPointBuckets struct { - orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets -} - -func GetOrigExponentialHistogramDataPointBuckets(ms ExponentialHistogramDataPointBuckets) *otlpmetrics.ExponentialHistogramDataPoint_Buckets { - return ms.orig -} - -func NewExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) ExponentialHistogramDataPointBuckets { - return ExponentialHistogramDataPointBuckets{orig: orig} -} - -type SummaryDataPointSlice struct { - orig *[]*otlpmetrics.SummaryDataPoint -} - -func GetOrigSummaryDataPointSlice(ms SummaryDataPointSlice) *[]*otlpmetrics.SummaryDataPoint { - return ms.orig -} - -func NewSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) SummaryDataPointSlice { - return SummaryDataPointSlice{orig: orig} -} - -type SummaryDataPoint struct { - orig *otlpmetrics.SummaryDataPoint -} - -func GetOrigSummaryDataPoint(ms SummaryDataPoint) *otlpmetrics.SummaryDataPoint { - return ms.orig -} - -func NewSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) SummaryDataPoint { - return SummaryDataPoint{orig: orig} -} - -type SummaryDataPointValueAtQuantileSlice struct { - orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile -} - -func GetOrigSummaryDataPointValueAtQuantileSlice(ms SummaryDataPointValueAtQuantileSlice) *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile { - return ms.orig -} - -func NewSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantileSlice { - return SummaryDataPointValueAtQuantileSlice{orig: orig} -} - -type SummaryDataPointValueAtQuantile struct { - orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile -} - -func GetOrigSummaryDataPointValueAtQuantile(ms SummaryDataPointValueAtQuantile) *otlpmetrics.SummaryDataPoint_ValueAtQuantile { - return ms.orig -} - -func NewSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantile { - return SummaryDataPointValueAtQuantile{orig: orig} -} - -type ExemplarSlice struct { - orig *[]otlpmetrics.Exemplar -} - -func GetOrigExemplarSlice(ms ExemplarSlice) *[]otlpmetrics.Exemplar { - return ms.orig -} - -func NewExemplarSlice(orig *[]otlpmetrics.Exemplar) ExemplarSlice { - return ExemplarSlice{orig: orig} -} - -type Exemplar struct { - orig *otlpmetrics.Exemplar -} - -func GetOrigExemplar(ms Exemplar) *otlpmetrics.Exemplar { - return ms.orig -} - -func NewExemplar(orig *otlpmetrics.Exemplar) Exemplar { - return Exemplar{orig: orig} -} - -func GenerateTestResourceMetricsSlice() ResourceMetricsSlice { - orig := []*otlpmetrics.ResourceMetrics{} - tv := NewResourceMetricsSlice(&orig) - FillTestResourceMetricsSlice(tv) - return tv -} - -func FillTestResourceMetricsSlice(tv ResourceMetricsSlice) { - *tv.orig = make([]*otlpmetrics.ResourceMetrics, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.ResourceMetrics{} - FillTestResourceMetrics(NewResourceMetrics((*tv.orig)[i])) - } -} - -func GenerateTestResourceMetrics() ResourceMetrics { - orig := otlpmetrics.ResourceMetrics{} - tv := NewResourceMetrics(&orig) - FillTestResourceMetrics(tv) - return tv -} - -func FillTestResourceMetrics(tv ResourceMetrics) { - FillTestResource(NewResource(&tv.orig.Resource)) - tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestScopeMetricsSlice(NewScopeMetricsSlice(&tv.orig.ScopeMetrics)) -} - -func GenerateTestScopeMetricsSlice() ScopeMetricsSlice { - orig := []*otlpmetrics.ScopeMetrics{} - tv := NewScopeMetricsSlice(&orig) - FillTestScopeMetricsSlice(tv) - return tv -} - -func FillTestScopeMetricsSlice(tv ScopeMetricsSlice) { - *tv.orig = make([]*otlpmetrics.ScopeMetrics, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.ScopeMetrics{} - FillTestScopeMetrics(NewScopeMetrics((*tv.orig)[i])) - } -} - -func GenerateTestScopeMetrics() ScopeMetrics { - orig := otlpmetrics.ScopeMetrics{} - tv := NewScopeMetrics(&orig) - FillTestScopeMetrics(tv) - return tv -} - -func FillTestScopeMetrics(tv ScopeMetrics) { - FillTestInstrumentationScope(NewInstrumentationScope(&tv.orig.Scope)) - tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestMetricSlice(NewMetricSlice(&tv.orig.Metrics)) -} - -func GenerateTestMetricSlice() MetricSlice { - orig := []*otlpmetrics.Metric{} - tv := NewMetricSlice(&orig) - FillTestMetricSlice(tv) - return tv -} - -func FillTestMetricSlice(tv MetricSlice) { - *tv.orig = make([]*otlpmetrics.Metric, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.Metric{} - FillTestMetric(NewMetric((*tv.orig)[i])) - } -} - -func GenerateTestMetric() Metric { - orig := otlpmetrics.Metric{} - tv := NewMetric(&orig) - FillTestMetric(tv) - return tv -} - -func FillTestMetric(tv Metric) { - tv.orig.Name = "test_name" - tv.orig.Description = "test_description" - tv.orig.Unit = "1" - tv.orig.Data = &otlpmetrics.Metric_Sum{Sum: &otlpmetrics.Sum{}} - FillTestSum(NewSum(tv.orig.GetSum())) -} - -func GenerateTestGauge() Gauge { - orig := otlpmetrics.Gauge{} - tv := NewGauge(&orig) - FillTestGauge(tv) - return tv -} - -func FillTestGauge(tv Gauge) { - FillTestNumberDataPointSlice(NewNumberDataPointSlice(&tv.orig.DataPoints)) -} - -func GenerateTestSum() Sum { - orig := otlpmetrics.Sum{} - tv := NewSum(&orig) - FillTestSum(tv) - return tv -} - -func FillTestSum(tv Sum) { - tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) - tv.orig.IsMonotonic = true - FillTestNumberDataPointSlice(NewNumberDataPointSlice(&tv.orig.DataPoints)) -} - -func GenerateTestHistogram() Histogram { - orig := otlpmetrics.Histogram{} - tv := NewHistogram(&orig) - FillTestHistogram(tv) - return tv -} - -func FillTestHistogram(tv Histogram) { - tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) - FillTestHistogramDataPointSlice(NewHistogramDataPointSlice(&tv.orig.DataPoints)) -} - -func GenerateTestExponentialHistogram() ExponentialHistogram { - orig := otlpmetrics.ExponentialHistogram{} - tv := NewExponentialHistogram(&orig) - FillTestExponentialHistogram(tv) - return tv -} - -func FillTestExponentialHistogram(tv ExponentialHistogram) { - tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) - FillTestExponentialHistogramDataPointSlice(NewExponentialHistogramDataPointSlice(&tv.orig.DataPoints)) -} - -func GenerateTestSummary() Summary { - orig := otlpmetrics.Summary{} - tv := NewSummary(&orig) - FillTestSummary(tv) - return tv -} - -func FillTestSummary(tv Summary) { - FillTestSummaryDataPointSlice(NewSummaryDataPointSlice(&tv.orig.DataPoints)) -} - -func GenerateTestNumberDataPointSlice() NumberDataPointSlice { - orig := []*otlpmetrics.NumberDataPoint{} - tv := NewNumberDataPointSlice(&orig) - FillTestNumberDataPointSlice(tv) - return tv -} - -func FillTestNumberDataPointSlice(tv NumberDataPointSlice) { - *tv.orig = make([]*otlpmetrics.NumberDataPoint, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.NumberDataPoint{} - FillTestNumberDataPoint(NewNumberDataPoint((*tv.orig)[i])) - } -} - -func GenerateTestNumberDataPoint() NumberDataPoint { - orig := otlpmetrics.NumberDataPoint{} - tv := NewNumberDataPoint(&orig) - FillTestNumberDataPoint(tv) - return tv -} - -func FillTestNumberDataPoint(tv NumberDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.StartTimeUnixNano = 1234567890 - tv.orig.TimeUnixNano = 1234567890 - tv.orig.Value = &otlpmetrics.NumberDataPoint_AsDouble{AsDouble: float64(17.13)} - FillTestExemplarSlice(NewExemplarSlice(&tv.orig.Exemplars)) - tv.orig.Flags = 1 -} - -func GenerateTestHistogramDataPointSlice() HistogramDataPointSlice { - orig := []*otlpmetrics.HistogramDataPoint{} - tv := NewHistogramDataPointSlice(&orig) - FillTestHistogramDataPointSlice(tv) - return tv -} - -func FillTestHistogramDataPointSlice(tv HistogramDataPointSlice) { - *tv.orig = make([]*otlpmetrics.HistogramDataPoint, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.HistogramDataPoint{} - FillTestHistogramDataPoint(NewHistogramDataPoint((*tv.orig)[i])) - } -} - -func GenerateTestHistogramDataPoint() HistogramDataPoint { - orig := otlpmetrics.HistogramDataPoint{} - tv := NewHistogramDataPoint(&orig) - FillTestHistogramDataPoint(tv) - return tv -} - -func FillTestHistogramDataPoint(tv HistogramDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.StartTimeUnixNano = 1234567890 - tv.orig.TimeUnixNano = 1234567890 - tv.orig.Count = uint64(17) - tv.orig.Sum_ = &otlpmetrics.HistogramDataPoint_Sum{Sum: float64(17.13)} - tv.orig.BucketCounts = []uint64{1, 2, 3} - tv.orig.ExplicitBounds = []float64{1, 2, 3} - FillTestExemplarSlice(NewExemplarSlice(&tv.orig.Exemplars)) - tv.orig.Flags = 1 - tv.orig.Min_ = &otlpmetrics.HistogramDataPoint_Min{Min: float64(9.23)} - tv.orig.Max_ = &otlpmetrics.HistogramDataPoint_Max{Max: float64(182.55)} -} - -func GenerateTestExponentialHistogramDataPointSlice() ExponentialHistogramDataPointSlice { - orig := []*otlpmetrics.ExponentialHistogramDataPoint{} - tv := NewExponentialHistogramDataPointSlice(&orig) - FillTestExponentialHistogramDataPointSlice(tv) - return tv -} - -func FillTestExponentialHistogramDataPointSlice(tv ExponentialHistogramDataPointSlice) { - *tv.orig = make([]*otlpmetrics.ExponentialHistogramDataPoint, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.ExponentialHistogramDataPoint{} - FillTestExponentialHistogramDataPoint(NewExponentialHistogramDataPoint((*tv.orig)[i])) - } -} - -func GenerateTestExponentialHistogramDataPoint() ExponentialHistogramDataPoint { - orig := otlpmetrics.ExponentialHistogramDataPoint{} - tv := NewExponentialHistogramDataPoint(&orig) - FillTestExponentialHistogramDataPoint(tv) - return tv -} - -func FillTestExponentialHistogramDataPoint(tv ExponentialHistogramDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.StartTimeUnixNano = 1234567890 - tv.orig.TimeUnixNano = 1234567890 - tv.orig.Count = uint64(17) - tv.orig.Sum_ = &otlpmetrics.ExponentialHistogramDataPoint_Sum{Sum: float64(17.13)} - tv.orig.Scale = int32(4) - tv.orig.ZeroCount = uint64(201) - FillTestExponentialHistogramDataPointBuckets(NewExponentialHistogramDataPointBuckets(&tv.orig.Positive)) - FillTestExponentialHistogramDataPointBuckets(NewExponentialHistogramDataPointBuckets(&tv.orig.Negative)) - FillTestExemplarSlice(NewExemplarSlice(&tv.orig.Exemplars)) - tv.orig.Flags = 1 - tv.orig.Min_ = &otlpmetrics.ExponentialHistogramDataPoint_Min{Min: float64(9.23)} - tv.orig.Max_ = &otlpmetrics.ExponentialHistogramDataPoint_Max{Max: float64(182.55)} -} - -func GenerateTestExponentialHistogramDataPointBuckets() ExponentialHistogramDataPointBuckets { - orig := otlpmetrics.ExponentialHistogramDataPoint_Buckets{} - tv := NewExponentialHistogramDataPointBuckets(&orig) - FillTestExponentialHistogramDataPointBuckets(tv) - return tv -} - -func FillTestExponentialHistogramDataPointBuckets(tv ExponentialHistogramDataPointBuckets) { - tv.orig.Offset = int32(909) - tv.orig.BucketCounts = []uint64{1, 2, 3} -} - -func GenerateTestSummaryDataPointSlice() SummaryDataPointSlice { - orig := []*otlpmetrics.SummaryDataPoint{} - tv := NewSummaryDataPointSlice(&orig) - FillTestSummaryDataPointSlice(tv) - return tv -} - -func FillTestSummaryDataPointSlice(tv SummaryDataPointSlice) { - *tv.orig = make([]*otlpmetrics.SummaryDataPoint, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.SummaryDataPoint{} - FillTestSummaryDataPoint(NewSummaryDataPoint((*tv.orig)[i])) - } -} - -func GenerateTestSummaryDataPoint() SummaryDataPoint { - orig := otlpmetrics.SummaryDataPoint{} - tv := NewSummaryDataPoint(&orig) - FillTestSummaryDataPoint(tv) - return tv -} - -func FillTestSummaryDataPoint(tv SummaryDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.StartTimeUnixNano = 1234567890 - tv.orig.TimeUnixNano = 1234567890 - tv.orig.Count = uint64(17) - tv.orig.Sum = float64(17.13) - FillTestSummaryDataPointValueAtQuantileSlice(NewSummaryDataPointValueAtQuantileSlice(&tv.orig.QuantileValues)) - tv.orig.Flags = 1 -} - -func GenerateTestSummaryDataPointValueAtQuantileSlice() SummaryDataPointValueAtQuantileSlice { - orig := []*otlpmetrics.SummaryDataPoint_ValueAtQuantile{} - tv := NewSummaryDataPointValueAtQuantileSlice(&orig) - FillTestSummaryDataPointValueAtQuantileSlice(tv) - return tv -} - -func FillTestSummaryDataPointValueAtQuantileSlice(tv SummaryDataPointValueAtQuantileSlice) { - *tv.orig = make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlpmetrics.SummaryDataPoint_ValueAtQuantile{} - FillTestSummaryDataPointValueAtQuantile(NewSummaryDataPointValueAtQuantile((*tv.orig)[i])) - } -} - -func GenerateTestSummaryDataPointValueAtQuantile() SummaryDataPointValueAtQuantile { - orig := otlpmetrics.SummaryDataPoint_ValueAtQuantile{} - tv := NewSummaryDataPointValueAtQuantile(&orig) - FillTestSummaryDataPointValueAtQuantile(tv) - return tv -} - -func FillTestSummaryDataPointValueAtQuantile(tv SummaryDataPointValueAtQuantile) { - tv.orig.Quantile = float64(17.13) - tv.orig.Value = float64(17.13) -} - -func GenerateTestExemplarSlice() ExemplarSlice { - orig := []otlpmetrics.Exemplar{} - tv := NewExemplarSlice(&orig) - FillTestExemplarSlice(tv) - return tv -} - -func FillTestExemplarSlice(tv ExemplarSlice) { - *tv.orig = make([]otlpmetrics.Exemplar, 7) - for i := 0; i < 7; i++ { - FillTestExemplar(NewExemplar(&(*tv.orig)[i])) - } -} - -func GenerateTestExemplar() Exemplar { - orig := otlpmetrics.Exemplar{} - tv := NewExemplar(&orig) - FillTestExemplar(tv) - return tv -} - -func FillTestExemplar(tv Exemplar) { - tv.orig.TimeUnixNano = 1234567890 - tv.orig.Value = &otlpmetrics.Exemplar_AsInt{AsInt: int64(17)} - FillTestMap(NewMap(&tv.orig.FilteredAttributes)) - tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) - tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) -} diff --git a/pdata/internal/generated_wrapper_metrics_otlp.go b/pdata/internal/generated_wrapper_metrics_otlp.go deleted file mode 100644 index 7256ee8d6ee..00000000000 --- a/pdata/internal/generated_wrapper_metrics_otlp.go +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT. -// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go". - -package internal - -import ( - otlpcollectormetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/metrics/v1" -) - -type MetricsExportPartialSuccess struct { - orig *otlpcollectormetrics.ExportMetricsPartialSuccess -} - -func GetOrigMetricsExportPartialSuccess(ms MetricsExportPartialSuccess) *otlpcollectormetrics.ExportMetricsPartialSuccess { - return ms.orig -} - -func NewMetricsExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) MetricsExportPartialSuccess { - return MetricsExportPartialSuccess{orig: orig} -} - -func GenerateTestMetricsExportPartialSuccess() MetricsExportPartialSuccess { - orig := otlpcollectormetrics.ExportMetricsPartialSuccess{} - tv := NewMetricsExportPartialSuccess(&orig) - FillTestMetricsExportPartialSuccess(tv) - return tv -} - -func FillTestMetricsExportPartialSuccess(tv MetricsExportPartialSuccess) { - tv.orig.RejectedDataPoints = int64(13) - tv.orig.ErrorMessage = "error message" -} diff --git a/pdata/internal/generated_wrapper_traces.go b/pdata/internal/generated_wrapper_traces.go deleted file mode 100644 index 38d7e69d117..00000000000 --- a/pdata/internal/generated_wrapper_traces.go +++ /dev/null @@ -1,322 +0,0 @@ -// 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. - -// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT. -// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go". - -package internal - -import ( - "go.opentelemetry.io/collector/pdata/internal/data" - otlptrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/trace/v1" -) - -type ResourceSpansSlice struct { - orig *[]*otlptrace.ResourceSpans -} - -func GetOrigResourceSpansSlice(ms ResourceSpansSlice) *[]*otlptrace.ResourceSpans { - return ms.orig -} - -func NewResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) ResourceSpansSlice { - return ResourceSpansSlice{orig: orig} -} - -type ResourceSpans struct { - orig *otlptrace.ResourceSpans -} - -func GetOrigResourceSpans(ms ResourceSpans) *otlptrace.ResourceSpans { - return ms.orig -} - -func NewResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans { - return ResourceSpans{orig: orig} -} - -type ScopeSpansSlice struct { - orig *[]*otlptrace.ScopeSpans -} - -func GetOrigScopeSpansSlice(ms ScopeSpansSlice) *[]*otlptrace.ScopeSpans { - return ms.orig -} - -func NewScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) ScopeSpansSlice { - return ScopeSpansSlice{orig: orig} -} - -type ScopeSpans struct { - orig *otlptrace.ScopeSpans -} - -func GetOrigScopeSpans(ms ScopeSpans) *otlptrace.ScopeSpans { - return ms.orig -} - -func NewScopeSpans(orig *otlptrace.ScopeSpans) ScopeSpans { - return ScopeSpans{orig: orig} -} - -type SpanSlice struct { - orig *[]*otlptrace.Span -} - -func GetOrigSpanSlice(ms SpanSlice) *[]*otlptrace.Span { - return ms.orig -} - -func NewSpanSlice(orig *[]*otlptrace.Span) SpanSlice { - return SpanSlice{orig: orig} -} - -type Span struct { - orig *otlptrace.Span -} - -func GetOrigSpan(ms Span) *otlptrace.Span { - return ms.orig -} - -func NewSpan(orig *otlptrace.Span) Span { - return Span{orig: orig} -} - -type SpanEventSlice struct { - orig *[]*otlptrace.Span_Event -} - -func GetOrigSpanEventSlice(ms SpanEventSlice) *[]*otlptrace.Span_Event { - return ms.orig -} - -func NewSpanEventSlice(orig *[]*otlptrace.Span_Event) SpanEventSlice { - return SpanEventSlice{orig: orig} -} - -type SpanEvent struct { - orig *otlptrace.Span_Event -} - -func GetOrigSpanEvent(ms SpanEvent) *otlptrace.Span_Event { - return ms.orig -} - -func NewSpanEvent(orig *otlptrace.Span_Event) SpanEvent { - return SpanEvent{orig: orig} -} - -type SpanLinkSlice struct { - orig *[]*otlptrace.Span_Link -} - -func GetOrigSpanLinkSlice(ms SpanLinkSlice) *[]*otlptrace.Span_Link { - return ms.orig -} - -func NewSpanLinkSlice(orig *[]*otlptrace.Span_Link) SpanLinkSlice { - return SpanLinkSlice{orig: orig} -} - -type SpanLink struct { - orig *otlptrace.Span_Link -} - -func GetOrigSpanLink(ms SpanLink) *otlptrace.Span_Link { - return ms.orig -} - -func NewSpanLink(orig *otlptrace.Span_Link) SpanLink { - return SpanLink{orig: orig} -} - -type Status struct { - orig *otlptrace.Status -} - -func GetOrigStatus(ms Status) *otlptrace.Status { - return ms.orig -} - -func NewStatus(orig *otlptrace.Status) Status { - return Status{orig: orig} -} - -func GenerateTestResourceSpansSlice() ResourceSpansSlice { - orig := []*otlptrace.ResourceSpans{} - tv := NewResourceSpansSlice(&orig) - FillTestResourceSpansSlice(tv) - return tv -} - -func FillTestResourceSpansSlice(tv ResourceSpansSlice) { - *tv.orig = make([]*otlptrace.ResourceSpans, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlptrace.ResourceSpans{} - FillTestResourceSpans(NewResourceSpans((*tv.orig)[i])) - } -} - -func GenerateTestResourceSpans() ResourceSpans { - orig := otlptrace.ResourceSpans{} - tv := NewResourceSpans(&orig) - FillTestResourceSpans(tv) - return tv -} - -func FillTestResourceSpans(tv ResourceSpans) { - FillTestResource(NewResource(&tv.orig.Resource)) - tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestScopeSpansSlice(NewScopeSpansSlice(&tv.orig.ScopeSpans)) -} - -func GenerateTestScopeSpansSlice() ScopeSpansSlice { - orig := []*otlptrace.ScopeSpans{} - tv := NewScopeSpansSlice(&orig) - FillTestScopeSpansSlice(tv) - return tv -} - -func FillTestScopeSpansSlice(tv ScopeSpansSlice) { - *tv.orig = make([]*otlptrace.ScopeSpans, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlptrace.ScopeSpans{} - FillTestScopeSpans(NewScopeSpans((*tv.orig)[i])) - } -} - -func GenerateTestScopeSpans() ScopeSpans { - orig := otlptrace.ScopeSpans{} - tv := NewScopeSpans(&orig) - FillTestScopeSpans(tv) - return tv -} - -func FillTestScopeSpans(tv ScopeSpans) { - FillTestInstrumentationScope(NewInstrumentationScope(&tv.orig.Scope)) - tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestSpanSlice(NewSpanSlice(&tv.orig.Spans)) -} - -func GenerateTestSpanSlice() SpanSlice { - orig := []*otlptrace.Span{} - tv := NewSpanSlice(&orig) - FillTestSpanSlice(tv) - return tv -} - -func FillTestSpanSlice(tv SpanSlice) { - *tv.orig = make([]*otlptrace.Span, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlptrace.Span{} - FillTestSpan(NewSpan((*tv.orig)[i])) - } -} - -func GenerateTestSpan() Span { - orig := otlptrace.Span{} - tv := NewSpan(&orig) - FillTestSpan(tv) - return tv -} - -func FillTestSpan(tv Span) { - tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) - tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) - FillTestTraceState(NewTraceState(&tv.orig.TraceState)) - tv.orig.ParentSpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) - tv.orig.Name = "test_name" - tv.orig.Kind = otlptrace.Span_SpanKind(3) - tv.orig.StartTimeUnixNano = 1234567890 - tv.orig.EndTimeUnixNano = 1234567890 - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.DroppedAttributesCount = uint32(17) - FillTestSpanEventSlice(NewSpanEventSlice(&tv.orig.Events)) - tv.orig.DroppedEventsCount = uint32(17) - FillTestSpanLinkSlice(NewSpanLinkSlice(&tv.orig.Links)) - tv.orig.DroppedLinksCount = uint32(17) - FillTestStatus(NewStatus(&tv.orig.Status)) -} - -func GenerateTestSpanEventSlice() SpanEventSlice { - orig := []*otlptrace.Span_Event{} - tv := NewSpanEventSlice(&orig) - FillTestSpanEventSlice(tv) - return tv -} - -func FillTestSpanEventSlice(tv SpanEventSlice) { - *tv.orig = make([]*otlptrace.Span_Event, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlptrace.Span_Event{} - FillTestSpanEvent(NewSpanEvent((*tv.orig)[i])) - } -} - -func GenerateTestSpanEvent() SpanEvent { - orig := otlptrace.Span_Event{} - tv := NewSpanEvent(&orig) - FillTestSpanEvent(tv) - return tv -} - -func FillTestSpanEvent(tv SpanEvent) { - tv.orig.TimeUnixNano = 1234567890 - tv.orig.Name = "test_name" - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.DroppedAttributesCount = uint32(17) -} - -func GenerateTestSpanLinkSlice() SpanLinkSlice { - orig := []*otlptrace.Span_Link{} - tv := NewSpanLinkSlice(&orig) - FillTestSpanLinkSlice(tv) - return tv -} - -func FillTestSpanLinkSlice(tv SpanLinkSlice) { - *tv.orig = make([]*otlptrace.Span_Link, 7) - for i := 0; i < 7; i++ { - (*tv.orig)[i] = &otlptrace.Span_Link{} - FillTestSpanLink(NewSpanLink((*tv.orig)[i])) - } -} - -func GenerateTestSpanLink() SpanLink { - orig := otlptrace.Span_Link{} - tv := NewSpanLink(&orig) - FillTestSpanLink(tv) - return tv -} - -func FillTestSpanLink(tv SpanLink) { - tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) - tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) - FillTestTraceState(NewTraceState(&tv.orig.TraceState)) - FillTestMap(NewMap(&tv.orig.Attributes)) - tv.orig.DroppedAttributesCount = uint32(17) -} - -func GenerateTestStatus() Status { - orig := otlptrace.Status{} - tv := NewStatus(&orig) - FillTestStatus(tv) - return tv -} - -func FillTestStatus(tv Status) { - tv.orig.Code = 1 - tv.orig.Message = "cancelled" -} diff --git a/pdata/internal/generated_wrapper_traces_otlp.go b/pdata/internal/generated_wrapper_traces_otlp.go deleted file mode 100644 index 1949149976a..00000000000 --- a/pdata/internal/generated_wrapper_traces_otlp.go +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT. -// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go". - -package internal - -import ( - otlpcollectortrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/trace/v1" -) - -type TracesExportPartialSuccess struct { - orig *otlpcollectortrace.ExportTracePartialSuccess -} - -func GetOrigTracesExportPartialSuccess(ms TracesExportPartialSuccess) *otlpcollectortrace.ExportTracePartialSuccess { - return ms.orig -} - -func NewTracesExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) TracesExportPartialSuccess { - return TracesExportPartialSuccess{orig: orig} -} - -func GenerateTestTracesExportPartialSuccess() TracesExportPartialSuccess { - orig := otlpcollectortrace.ExportTracePartialSuccess{} - tv := NewTracesExportPartialSuccess(&orig) - FillTestTracesExportPartialSuccess(tv) - return tv -} - -func FillTestTracesExportPartialSuccess(tv TracesExportPartialSuccess) { - tv.orig.RejectedSpans = int64(13) - tv.orig.ErrorMessage = "error message" -} diff --git a/pdata/internal/wrapper_common.go b/pdata/internal/wrapper_common.go index f78ff175425..e6088a5bd56 100644 --- a/pdata/internal/wrapper_common.go +++ b/pdata/internal/wrapper_common.go @@ -87,3 +87,29 @@ func GenerateTestTraceState() TraceState { func FillTestTraceState(dest TraceState) { *dest.orig = "rojo=00f067aa0ba902b7" } + +type Slice struct { + orig *[]otlpcommon.AnyValue +} + +func GetOrigSlice(ms Slice) *[]otlpcommon.AnyValue { + return ms.orig +} + +func NewSlice(orig *[]otlpcommon.AnyValue) Slice { + return Slice{orig: orig} +} + +func GenerateTestSlice() Slice { + orig := []otlpcommon.AnyValue{} + tv := NewSlice(&orig) + FillTestSlice(tv) + return tv +} + +func FillTestSlice(tv Slice) { + *tv.orig = make([]otlpcommon.AnyValue, 7) + for i := 0; i < 7; i++ { + FillTestValue(NewValue(&(*tv.orig)[i])) + } +} diff --git a/pdata/pcommon/common.go b/pdata/pcommon/common.go index a30709418d3..99a510f2935 100644 --- a/pdata/pcommon/common.go +++ b/pdata/pcommon/common.go @@ -750,6 +750,126 @@ func (m Map) FromRaw(rawMap map[string]any) error { return errs } +// Slice logically represents a slice of Value. +// +// This is a reference type. If passed by value and callee modifies it, the +// caller will see the modification. +// +// Must use NewSlice function to create new instances. +// Important: zero-initialized instance is not valid for use. +type Slice internal.Slice + +func newSlice(orig *[]otlpcommon.AnyValue) Slice { + return Slice(internal.NewSlice(orig)) +} + +func (es Slice) getOrig() *[]otlpcommon.AnyValue { + return internal.GetOrigSlice(internal.Slice(es)) +} + +// NewSlice creates a Slice with 0 elements. +// Can use "EnsureCapacity" to initialize with a given capacity. +func NewSlice() Slice { + orig := []otlpcommon.AnyValue(nil) + return Slice(internal.NewSlice(&orig)) +} + +// Len returns the number of elements in the slice. +// +// Returns "0" for a newly instance created with "NewSlice()". +func (es Slice) Len() int { + return len(*es.getOrig()) +} + +// 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 Slice) At(ix int) Value { + return newValue(&(*es.getOrig())[ix]) +} + +// CopyTo copies all elements from the current slice overriding the destination. +func (es Slice) CopyTo(dest Slice) { + srcLen := es.Len() + destCap := cap(*dest.getOrig()) + if srcLen <= destCap { + (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] + } else { + (*dest.getOrig()) = make([]otlpcommon.AnyValue, srcLen) + } + + for i := range *es.getOrig() { + newValue(&(*es.getOrig())[i]).CopyTo(newValue(&(*dest.getOrig())[i])) + } +} + +// EnsureCapacity is an operation that ensures the slice has at least the specified capacity. +// 1. If the newCap <= cap then no change in capacity. +// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. +// +// Here is how a new Slice can be initialized: +// +// es := NewSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } +func (es Slice) EnsureCapacity(newCap int) { + oldCap := cap(*es.getOrig()) + if newCap <= oldCap { + return + } + + newOrig := make([]otlpcommon.AnyValue, len(*es.getOrig()), newCap) + copy(newOrig, *es.getOrig()) + *es.getOrig() = newOrig +} + +// AppendEmpty will append to the end of the slice an empty Value. +// It returns the newly added Value. +func (es Slice) AppendEmpty() Value { + *es.getOrig() = append(*es.getOrig(), otlpcommon.AnyValue{}) + return es.At(es.Len() - 1) +} + +// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. +// The current slice will be cleared. +func (es Slice) MoveAndAppendTo(dest Slice) { + if *dest.getOrig() == nil { + // We can simply move the entire vector and avoid any allocations. + *dest.getOrig() = *es.getOrig() + } else { + *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + } + *es.getOrig() = nil +} + +// RemoveIf calls f sequentially for each element present in the slice. +// If f returns true, the element is removed from the slice. +func (es Slice) RemoveIf(f func(Value) bool) { + newLen := 0 + for i := 0; i < len(*es.getOrig()); i++ { + if f(es.At(i)) { + continue + } + if newLen == i { + // Nothing to move, element is at the right place. + newLen++ + continue + } + (*es.getOrig())[newLen] = (*es.getOrig())[i] + newLen++ + } + // TODO: Prevent memory leak by erasing truncated values. + *es.getOrig() = (*es.getOrig())[:newLen] +} + // AsRaw return []any copy of the Slice. func (es Slice) AsRaw() []any { rawSlice := make([]any, 0, es.Len()) diff --git a/pdata/pcommon/common_test.go b/pdata/pcommon/common_test.go index f6b6fdcf1e7..f5e2d125c8b 100644 --- a/pdata/pcommon/common_test.go +++ b/pdata/pcommon/common_test.go @@ -1029,3 +1029,104 @@ func generateTestValueBytes() Value { v.Bytes().FromRaw([]byte("String bytes")) return v } + +func TestSlice(t *testing.T) { + es := NewSlice() + assert.Equal(t, 0, es.Len()) + es = newSlice(&[]otlpcommon.AnyValue{}) + assert.Equal(t, 0, es.Len()) + + es.EnsureCapacity(7) + emptyVal := newValue(&otlpcommon.AnyValue{}) + testVal := Value(internal.GenerateTestValue()) + assert.Equal(t, 7, cap(*es.getOrig())) + for i := 0; i < es.Len(); i++ { + el := es.AppendEmpty() + assert.Equal(t, emptyVal, el) + internal.FillTestValue(internal.Value(el)) + assert.Equal(t, testVal, el) + } +} + +func TestSlice_CopyTo(t *testing.T) { + dest := NewSlice() + // Test CopyTo to empty + NewSlice().CopyTo(dest) + assert.Equal(t, NewSlice(), dest) + + // Test CopyTo larger slice + Slice(internal.GenerateTestSlice()).CopyTo(dest) + assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) + + // Test CopyTo same size slice + Slice(internal.GenerateTestSlice()).CopyTo(dest) + assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) +} + +func TestSlice_EnsureCapacity(t *testing.T) { + es := Slice(internal.GenerateTestSlice()) + // Test ensure smaller capacity. + const ensureSmallLen = 4 + expectedEs := make(map[*otlpcommon.AnyValue]bool) + for i := 0; i < es.Len(); i++ { + expectedEs[es.At(i).getOrig()] = true + } + assert.Equal(t, es.Len(), len(expectedEs)) + es.EnsureCapacity(ensureSmallLen) + assert.Less(t, ensureSmallLen, es.Len()) + foundEs := make(map[*otlpcommon.AnyValue]bool, es.Len()) + for i := 0; i < es.Len(); i++ { + foundEs[es.At(i).getOrig()] = true + } + assert.Equal(t, expectedEs, foundEs) + + // Test ensure larger capacity + const ensureLargeLen = 9 + oldLen := es.Len() + assert.Equal(t, oldLen, len(expectedEs)) + es.EnsureCapacity(ensureLargeLen) + assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) +} + +func TestSlice_MoveAndAppendTo(t *testing.T) { + // Test MoveAndAppendTo to empty + expectedSlice := Slice(internal.GenerateTestSlice()) + dest := NewSlice() + src := Slice(internal.GenerateTestSlice()) + src.MoveAndAppendTo(dest) + assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo empty slice + src.MoveAndAppendTo(dest) + assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) + assert.Equal(t, 0, src.Len()) + assert.Equal(t, expectedSlice.Len(), dest.Len()) + + // Test MoveAndAppendTo not empty slice + Slice(internal.GenerateTestSlice()).MoveAndAppendTo(dest) + assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) + for i := 0; i < expectedSlice.Len(); i++ { + assert.Equal(t, expectedSlice.At(i), dest.At(i)) + assert.Equal(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) + } +} + +func TestSlice_RemoveIf(t *testing.T) { + // Test RemoveIf on empty slice + emptySlice := NewSlice() + emptySlice.RemoveIf(func(el Value) bool { + t.Fail() + return false + }) + + // Test RemoveIf + filtered := Slice(internal.GenerateTestSlice()) + pos := 0 + filtered.RemoveIf(func(el Value) bool { + pos++ + return pos%3 == 0 + }) + assert.Equal(t, 5, filtered.Len()) +} diff --git a/pdata/pcommon/generated_common.go b/pdata/pcommon/generated_common.go index e53019a3725..ec7bc1bf4e7 100644 --- a/pdata/pcommon/generated_common.go +++ b/pdata/pcommon/generated_common.go @@ -29,17 +29,12 @@ import ( // // Must use NewInstrumentationScope function to create new instances. // Important: zero-initialized instance is not valid for use. - type InstrumentationScope internal.InstrumentationScope func newInstrumentationScope(orig *otlpcommon.InstrumentationScope) InstrumentationScope { return InstrumentationScope(internal.NewInstrumentationScope(orig)) } -func (ms InstrumentationScope) getOrig() *otlpcommon.InstrumentationScope { - return internal.GetOrigInstrumentationScope(internal.InstrumentationScope(ms)) -} - // NewInstrumentationScope creates a new empty InstrumentationScope. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, @@ -55,6 +50,10 @@ func (ms InstrumentationScope) MoveTo(dest InstrumentationScope) { *ms.getOrig() = otlpcommon.InstrumentationScope{} } +func (ms InstrumentationScope) getOrig() *otlpcommon.InstrumentationScope { + return internal.GetOrigInstrumentationScope(internal.InstrumentationScope(ms)) +} + // Name returns the name associated with this InstrumentationScope. func (ms InstrumentationScope) Name() string { return ms.getOrig().Name @@ -97,123 +96,3 @@ func (ms InstrumentationScope) CopyTo(dest InstrumentationScope) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } - -// Slice logically represents a slice of Value. -// -// This is a reference type. If passed by value and callee modifies it, the -// caller will see the modification. -// -// Must use NewSlice function to create new instances. -// Important: zero-initialized instance is not valid for use. -type Slice internal.Slice - -func newSlice(orig *[]otlpcommon.AnyValue) Slice { - return Slice(internal.NewSlice(orig)) -} - -func (ms Slice) getOrig() *[]otlpcommon.AnyValue { - return internal.GetOrigSlice(internal.Slice(ms)) -} - -// NewSlice creates a Slice with 0 elements. -// Can use "EnsureCapacity" to initialize with a given capacity. -func NewSlice() Slice { - orig := []otlpcommon.AnyValue(nil) - return Slice(internal.NewSlice(&orig)) -} - -// Len returns the number of elements in the slice. -// -// Returns "0" for a newly instance created with "NewSlice()". -func (es Slice) Len() int { - return len(*es.getOrig()) -} - -// 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 Slice) At(ix int) Value { - return newValue(&(*es.getOrig())[ix]) -} - -// CopyTo copies all elements from the current slice overriding the destination. -func (es Slice) CopyTo(dest Slice) { - srcLen := es.Len() - destCap := cap(*dest.getOrig()) - if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - } else { - (*dest.getOrig()) = make([]otlpcommon.AnyValue, srcLen) - } - - for i := range *es.getOrig() { - newValue(&(*es.getOrig())[i]).CopyTo(newValue(&(*dest.getOrig())[i])) - } -} - -// EnsureCapacity is an operation that ensures the slice has at least the specified capacity. -// 1. If the newCap <= cap then no change in capacity. -// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. -// -// Here is how a new Slice can be initialized: -// -// es := NewSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } -func (es Slice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) - if newCap <= oldCap { - return - } - - newOrig := make([]otlpcommon.AnyValue, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig -} - -// AppendEmpty will append to the end of the slice an empty Value. -// It returns the newly added Value. -func (es Slice) AppendEmpty() Value { - *es.getOrig() = append(*es.getOrig(), otlpcommon.AnyValue{}) - return es.At(es.Len() - 1) -} - -// MoveAndAppendTo moves all elements from the current slice and appends them to the dest. -// The current slice will be cleared. -func (es Slice) MoveAndAppendTo(dest Slice) { - if *dest.getOrig() == nil { - // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() - } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) - } - *es.getOrig() = nil -} - -// RemoveIf calls f sequentially for each element present in the slice. -// If f returns true, the element is removed from the slice. -func (es Slice) RemoveIf(f func(Value) bool) { - newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { - if f(es.At(i)) { - continue - } - if newLen == i { - // Nothing to move, element is at the right place. - newLen++ - continue - } - (*es.getOrig())[newLen] = (*es.getOrig())[i] - newLen++ - } - // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] -} diff --git a/pdata/pcommon/generated_common_test.go b/pdata/pcommon/generated_common_test.go index ab221ac43e3..7fac602a6ca 100644 --- a/pdata/pcommon/generated_common_test.go +++ b/pdata/pcommon/generated_common_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/internal" - otlpcommon "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1" ) func TestInstrumentationScope_MoveTo(t *testing.T) { @@ -71,104 +70,3 @@ func TestInstrumentationScope_DroppedAttributesCount(t *testing.T) { ms.SetDroppedAttributesCount(uint32(17)) assert.Equal(t, uint32(17), ms.DroppedAttributesCount()) } - -func TestSlice(t *testing.T) { - es := NewSlice() - assert.Equal(t, 0, es.Len()) - es = newSlice(&[]otlpcommon.AnyValue{}) - assert.Equal(t, 0, es.Len()) - - es.EnsureCapacity(7) - emptyVal := newValue(&otlpcommon.AnyValue{}) - testVal := Value(internal.GenerateTestValue()) - assert.Equal(t, 7, cap(*es.getOrig())) - for i := 0; i < es.Len(); i++ { - el := es.AppendEmpty() - assert.Equal(t, emptyVal, el) - internal.FillTestValue(internal.Value(el)) - assert.Equal(t, testVal, el) - } -} - -func TestSlice_CopyTo(t *testing.T) { - dest := NewSlice() - // Test CopyTo to empty - NewSlice().CopyTo(dest) - assert.Equal(t, NewSlice(), dest) - - // Test CopyTo larger slice - Slice(internal.GenerateTestSlice()).CopyTo(dest) - assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) - - // Test CopyTo same size slice - Slice(internal.GenerateTestSlice()).CopyTo(dest) - assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) -} - -func TestSlice_EnsureCapacity(t *testing.T) { - es := Slice(internal.GenerateTestSlice()) - // Test ensure smaller capacity. - const ensureSmallLen = 4 - expectedEs := make(map[*otlpcommon.AnyValue]bool) - for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true - } - assert.Equal(t, es.Len(), len(expectedEs)) - es.EnsureCapacity(ensureSmallLen) - assert.Less(t, ensureSmallLen, es.Len()) - foundEs := make(map[*otlpcommon.AnyValue]bool, es.Len()) - for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true - } - assert.Equal(t, expectedEs, foundEs) - - // Test ensure larger capacity - const ensureLargeLen = 9 - oldLen := es.Len() - assert.Equal(t, oldLen, len(expectedEs)) - es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) -} - -func TestSlice_MoveAndAppendTo(t *testing.T) { - // Test MoveAndAppendTo to empty - expectedSlice := Slice(internal.GenerateTestSlice()) - dest := NewSlice() - src := Slice(internal.GenerateTestSlice()) - src.MoveAndAppendTo(dest) - assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) - assert.Equal(t, 0, src.Len()) - assert.Equal(t, expectedSlice.Len(), dest.Len()) - - // Test MoveAndAppendTo empty slice - src.MoveAndAppendTo(dest) - assert.Equal(t, Slice(internal.GenerateTestSlice()), dest) - assert.Equal(t, 0, src.Len()) - assert.Equal(t, expectedSlice.Len(), dest.Len()) - - // Test MoveAndAppendTo not empty slice - Slice(internal.GenerateTestSlice()).MoveAndAppendTo(dest) - assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) - for i := 0; i < expectedSlice.Len(); i++ { - assert.Equal(t, expectedSlice.At(i), dest.At(i)) - assert.Equal(t, expectedSlice.At(i), dest.At(i+expectedSlice.Len())) - } -} - -func TestSlice_RemoveIf(t *testing.T) { - // Test RemoveIf on empty slice - emptySlice := NewSlice() - emptySlice.RemoveIf(func(el Value) bool { - t.Fail() - return false - }) - - // Test RemoveIf - filtered := Slice(internal.GenerateTestSlice()) - pos := 0 - filtered.RemoveIf(func(el Value) bool { - pos++ - return pos%3 == 0 - }) - assert.Equal(t, 5, filtered.Len()) -} diff --git a/pdata/pcommon/generated_resource.go b/pdata/pcommon/generated_resource.go index f98f10f53f6..c4b36a2e856 100644 --- a/pdata/pcommon/generated_resource.go +++ b/pdata/pcommon/generated_resource.go @@ -29,17 +29,12 @@ import ( // // Must use NewResource function to create new instances. // Important: zero-initialized instance is not valid for use. - type Resource internal.Resource func newResource(orig *otlpresource.Resource) Resource { return Resource(internal.NewResource(orig)) } -func (ms Resource) getOrig() *otlpresource.Resource { - return internal.GetOrigResource(internal.Resource(ms)) -} - // NewResource creates a new empty Resource. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, @@ -55,6 +50,10 @@ func (ms Resource) MoveTo(dest Resource) { *ms.getOrig() = otlpresource.Resource{} } +func (ms Resource) getOrig() *otlpresource.Resource { + return internal.GetOrigResource(internal.Resource(ms)) +} + // Attributes returns the Attributes associated with this Resource. func (ms Resource) Attributes() Map { return Map(internal.NewMap(&ms.getOrig().Attributes)) diff --git a/pdata/plog/generated_logs.go b/pdata/plog/generated_logs.go index b9071256387..15413b12847 100644 --- a/pdata/plog/generated_logs.go +++ b/pdata/plog/generated_logs.go @@ -33,14 +33,12 @@ import ( // // Must use NewResourceLogsSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ResourceLogsSlice internal.ResourceLogsSlice - -func newResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) ResourceLogsSlice { - return ResourceLogsSlice(internal.NewResourceLogsSlice(orig)) +type ResourceLogsSlice struct { + orig *[]*otlplogs.ResourceLogs } -func (ms ResourceLogsSlice) getOrig() *[]*otlplogs.ResourceLogs { - return internal.GetOrigResourceLogsSlice(internal.ResourceLogsSlice(ms)) +func newResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) ResourceLogsSlice { + return ResourceLogsSlice{orig} } // NewResourceLogsSlice creates a ResourceLogsSlice with 0 elements. @@ -54,7 +52,7 @@ func NewResourceLogsSlice() ResourceLogsSlice { // // Returns "0" for a newly instance created with "NewResourceLogsSlice()". func (es ResourceLogsSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -66,27 +64,27 @@ func (es ResourceLogsSlice) Len() int { // ... // Do something with the element // } func (es ResourceLogsSlice) At(ix int) ResourceLogs { - return newResourceLogs((*es.getOrig())[ix]) + return newResourceLogs((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newResourceLogs((*es.getOrig())[i]).CopyTo(newResourceLogs((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newResourceLogs((*es.orig)[i]).CopyTo(newResourceLogs((*dest.orig)[i])) } return } origs := make([]otlplogs.ResourceLogs, srcLen) wrappers := make([]*otlplogs.ResourceLogs, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newResourceLogs((*es.getOrig())[i]).CopyTo(newResourceLogs(wrappers[i])) + newResourceLogs((*es.orig)[i]).CopyTo(newResourceLogs(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -102,20 +100,20 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { // // Here should set all the values for e. // } func (es ResourceLogsSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlplogs.ResourceLogs, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlplogs.ResourceLogs, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ResourceLogs. // It returns the newly added ResourceLogs. func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { - *es.getOrig() = append(*es.getOrig(), &otlplogs.ResourceLogs{}) + *es.orig = append(*es.orig, &otlplogs.ResourceLogs{}) return es.At(es.Len() - 1) } @@ -123,26 +121,26 @@ func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { // provided less function so that two instances of ResourceLogsSlice // can be compared. func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceLogsSlice) MoveAndAppendTo(dest ResourceLogsSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ResourceLogsSlice) RemoveIf(f func(ResourceLogs) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -151,11 +149,11 @@ func (es ResourceLogsSlice) RemoveIf(f func(ResourceLogs) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ResourceLogs is a collection of logs from a Resource. @@ -165,15 +163,12 @@ func (es ResourceLogsSlice) RemoveIf(f func(ResourceLogs) bool) { // // Must use NewResourceLogs function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ResourceLogs internal.ResourceLogs - -func newResourceLogs(orig *otlplogs.ResourceLogs) ResourceLogs { - return ResourceLogs(internal.NewResourceLogs(orig)) +type ResourceLogs struct { + orig *otlplogs.ResourceLogs } -func (ms ResourceLogs) getOrig() *otlplogs.ResourceLogs { - return internal.GetOrigResourceLogs(internal.ResourceLogs(ms)) +func newResourceLogs(orig *otlplogs.ResourceLogs) ResourceLogs { + return ResourceLogs{orig} } // NewResourceLogs creates a new empty ResourceLogs. @@ -187,28 +182,28 @@ func NewResourceLogs() ResourceLogs { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ResourceLogs) MoveTo(dest ResourceLogs) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlplogs.ResourceLogs{} + *dest.orig = *ms.orig + *ms.orig = otlplogs.ResourceLogs{} } // Resource returns the resource associated with this ResourceLogs. func (ms ResourceLogs) Resource() pcommon.Resource { - return pcommon.Resource(internal.NewResource(&ms.getOrig().Resource)) + return pcommon.Resource(internal.NewResource(&ms.orig.Resource)) } // SchemaUrl returns the schemaurl associated with this ResourceLogs. func (ms ResourceLogs) SchemaUrl() string { - return ms.getOrig().SchemaUrl + return ms.orig.SchemaUrl } // SetSchemaUrl replaces the schemaurl associated with this ResourceLogs. func (ms ResourceLogs) SetSchemaUrl(v string) { - ms.getOrig().SchemaUrl = v + ms.orig.SchemaUrl = v } // ScopeLogs returns the ScopeLogs associated with this ResourceLogs. func (ms ResourceLogs) ScopeLogs() ScopeLogsSlice { - return ScopeLogsSlice(internal.NewScopeLogsSlice(&ms.getOrig().ScopeLogs)) + return newScopeLogsSlice(&ms.orig.ScopeLogs) } // CopyTo copies all properties from the current struct overriding the destination. @@ -225,14 +220,12 @@ func (ms ResourceLogs) CopyTo(dest ResourceLogs) { // // Must use NewScopeLogsSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ScopeLogsSlice internal.ScopeLogsSlice - -func newScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) ScopeLogsSlice { - return ScopeLogsSlice(internal.NewScopeLogsSlice(orig)) +type ScopeLogsSlice struct { + orig *[]*otlplogs.ScopeLogs } -func (ms ScopeLogsSlice) getOrig() *[]*otlplogs.ScopeLogs { - return internal.GetOrigScopeLogsSlice(internal.ScopeLogsSlice(ms)) +func newScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) ScopeLogsSlice { + return ScopeLogsSlice{orig} } // NewScopeLogsSlice creates a ScopeLogsSlice with 0 elements. @@ -246,7 +239,7 @@ func NewScopeLogsSlice() ScopeLogsSlice { // // Returns "0" for a newly instance created with "NewScopeLogsSlice()". func (es ScopeLogsSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -258,27 +251,27 @@ func (es ScopeLogsSlice) Len() int { // ... // Do something with the element // } func (es ScopeLogsSlice) At(ix int) ScopeLogs { - return newScopeLogs((*es.getOrig())[ix]) + return newScopeLogs((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newScopeLogs((*es.getOrig())[i]).CopyTo(newScopeLogs((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newScopeLogs((*es.orig)[i]).CopyTo(newScopeLogs((*dest.orig)[i])) } return } origs := make([]otlplogs.ScopeLogs, srcLen) wrappers := make([]*otlplogs.ScopeLogs, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newScopeLogs((*es.getOrig())[i]).CopyTo(newScopeLogs(wrappers[i])) + newScopeLogs((*es.orig)[i]).CopyTo(newScopeLogs(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -294,20 +287,20 @@ func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { // // Here should set all the values for e. // } func (es ScopeLogsSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlplogs.ScopeLogs, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlplogs.ScopeLogs, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ScopeLogs. // It returns the newly added ScopeLogs. func (es ScopeLogsSlice) AppendEmpty() ScopeLogs { - *es.getOrig() = append(*es.getOrig(), &otlplogs.ScopeLogs{}) + *es.orig = append(*es.orig, &otlplogs.ScopeLogs{}) return es.At(es.Len() - 1) } @@ -315,26 +308,26 @@ func (es ScopeLogsSlice) AppendEmpty() ScopeLogs { // provided less function so that two instances of ScopeLogsSlice // can be compared. func (es ScopeLogsSlice) Sort(less func(a, b ScopeLogs) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ScopeLogsSlice) MoveAndAppendTo(dest ScopeLogsSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ScopeLogsSlice) RemoveIf(f func(ScopeLogs) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -343,11 +336,11 @@ func (es ScopeLogsSlice) RemoveIf(f func(ScopeLogs) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ScopeLogs is a collection of logs from a LibraryInstrumentation. @@ -357,15 +350,12 @@ func (es ScopeLogsSlice) RemoveIf(f func(ScopeLogs) bool) { // // Must use NewScopeLogs function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ScopeLogs internal.ScopeLogs - -func newScopeLogs(orig *otlplogs.ScopeLogs) ScopeLogs { - return ScopeLogs(internal.NewScopeLogs(orig)) +type ScopeLogs struct { + orig *otlplogs.ScopeLogs } -func (ms ScopeLogs) getOrig() *otlplogs.ScopeLogs { - return internal.GetOrigScopeLogs(internal.ScopeLogs(ms)) +func newScopeLogs(orig *otlplogs.ScopeLogs) ScopeLogs { + return ScopeLogs{orig} } // NewScopeLogs creates a new empty ScopeLogs. @@ -379,28 +369,28 @@ func NewScopeLogs() ScopeLogs { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ScopeLogs) MoveTo(dest ScopeLogs) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlplogs.ScopeLogs{} + *dest.orig = *ms.orig + *ms.orig = otlplogs.ScopeLogs{} } // Scope returns the scope associated with this ScopeLogs. func (ms ScopeLogs) Scope() pcommon.InstrumentationScope { - return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.getOrig().Scope)) + return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.orig.Scope)) } // SchemaUrl returns the schemaurl associated with this ScopeLogs. func (ms ScopeLogs) SchemaUrl() string { - return ms.getOrig().SchemaUrl + return ms.orig.SchemaUrl } // SetSchemaUrl replaces the schemaurl associated with this ScopeLogs. func (ms ScopeLogs) SetSchemaUrl(v string) { - ms.getOrig().SchemaUrl = v + ms.orig.SchemaUrl = v } // LogRecords returns the LogRecords associated with this ScopeLogs. func (ms ScopeLogs) LogRecords() LogRecordSlice { - return LogRecordSlice(internal.NewLogRecordSlice(&ms.getOrig().LogRecords)) + return newLogRecordSlice(&ms.orig.LogRecords) } // CopyTo copies all properties from the current struct overriding the destination. @@ -417,14 +407,12 @@ func (ms ScopeLogs) CopyTo(dest ScopeLogs) { // // Must use NewLogRecordSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type LogRecordSlice internal.LogRecordSlice - -func newLogRecordSlice(orig *[]*otlplogs.LogRecord) LogRecordSlice { - return LogRecordSlice(internal.NewLogRecordSlice(orig)) +type LogRecordSlice struct { + orig *[]*otlplogs.LogRecord } -func (ms LogRecordSlice) getOrig() *[]*otlplogs.LogRecord { - return internal.GetOrigLogRecordSlice(internal.LogRecordSlice(ms)) +func newLogRecordSlice(orig *[]*otlplogs.LogRecord) LogRecordSlice { + return LogRecordSlice{orig} } // NewLogRecordSlice creates a LogRecordSlice with 0 elements. @@ -438,7 +426,7 @@ func NewLogRecordSlice() LogRecordSlice { // // Returns "0" for a newly instance created with "NewLogRecordSlice()". func (es LogRecordSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -450,27 +438,27 @@ func (es LogRecordSlice) Len() int { // ... // Do something with the element // } func (es LogRecordSlice) At(ix int) LogRecord { - return newLogRecord((*es.getOrig())[ix]) + return newLogRecord((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newLogRecord((*es.getOrig())[i]).CopyTo(newLogRecord((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newLogRecord((*es.orig)[i]).CopyTo(newLogRecord((*dest.orig)[i])) } return } origs := make([]otlplogs.LogRecord, srcLen) wrappers := make([]*otlplogs.LogRecord, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newLogRecord((*es.getOrig())[i]).CopyTo(newLogRecord(wrappers[i])) + newLogRecord((*es.orig)[i]).CopyTo(newLogRecord(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -486,20 +474,20 @@ func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { // // Here should set all the values for e. // } func (es LogRecordSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlplogs.LogRecord, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlplogs.LogRecord, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty LogRecord. // It returns the newly added LogRecord. func (es LogRecordSlice) AppendEmpty() LogRecord { - *es.getOrig() = append(*es.getOrig(), &otlplogs.LogRecord{}) + *es.orig = append(*es.orig, &otlplogs.LogRecord{}) return es.At(es.Len() - 1) } @@ -507,26 +495,26 @@ func (es LogRecordSlice) AppendEmpty() LogRecord { // provided less function so that two instances of LogRecordSlice // can be compared. func (es LogRecordSlice) Sort(less func(a, b LogRecord) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es LogRecordSlice) MoveAndAppendTo(dest LogRecordSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -535,30 +523,26 @@ func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // LogRecord are experimental implementation of OpenTelemetry Log Data Model. -// // This is a reference type, if passed by value and callee modifies it the // caller will see the modification. // // Must use NewLogRecord function to create new instances. // Important: zero-initialized instance is not valid for use. - -type LogRecord internal.LogRecord - -func newLogRecord(orig *otlplogs.LogRecord) LogRecord { - return LogRecord(internal.NewLogRecord(orig)) +type LogRecord struct { + orig *otlplogs.LogRecord } -func (ms LogRecord) getOrig() *otlplogs.LogRecord { - return internal.GetOrigLogRecord(internal.LogRecord(ms)) +func newLogRecord(orig *otlplogs.LogRecord) LogRecord { + return LogRecord{orig} } // NewLogRecord creates a new empty LogRecord. @@ -572,98 +556,98 @@ func NewLogRecord() LogRecord { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms LogRecord) MoveTo(dest LogRecord) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlplogs.LogRecord{} + *dest.orig = *ms.orig + *ms.orig = otlplogs.LogRecord{} } // ObservedTimestamp returns the observedtimestamp associated with this LogRecord. func (ms LogRecord) ObservedTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().ObservedTimeUnixNano) + return pcommon.Timestamp(ms.orig.ObservedTimeUnixNano) } // SetObservedTimestamp replaces the observedtimestamp associated with this LogRecord. func (ms LogRecord) SetObservedTimestamp(v pcommon.Timestamp) { - ms.getOrig().ObservedTimeUnixNano = uint64(v) + ms.orig.ObservedTimeUnixNano = uint64(v) } // Timestamp returns the timestamp associated with this LogRecord. func (ms LogRecord) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this LogRecord. func (ms LogRecord) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // TraceID returns the traceid associated with this LogRecord. func (ms LogRecord) TraceID() pcommon.TraceID { - return pcommon.TraceID(ms.getOrig().TraceId) + return pcommon.TraceID(ms.orig.TraceId) } // SetTraceID replaces the traceid associated with this LogRecord. func (ms LogRecord) SetTraceID(v pcommon.TraceID) { - ms.getOrig().TraceId = data.TraceID(v) + ms.orig.TraceId = data.TraceID(v) } // SpanID returns the spanid associated with this LogRecord. func (ms LogRecord) SpanID() pcommon.SpanID { - return pcommon.SpanID(ms.getOrig().SpanId) + return pcommon.SpanID(ms.orig.SpanId) } // SetSpanID replaces the spanid associated with this LogRecord. func (ms LogRecord) SetSpanID(v pcommon.SpanID) { - ms.getOrig().SpanId = data.SpanID(v) + ms.orig.SpanId = data.SpanID(v) } // Flags returns the flags associated with this LogRecord. func (ms LogRecord) Flags() LogRecordFlags { - return LogRecordFlags(ms.getOrig().Flags) + return LogRecordFlags(ms.orig.Flags) } // SetFlags replaces the flags associated with this LogRecord. func (ms LogRecord) SetFlags(v LogRecordFlags) { - ms.getOrig().Flags = uint32(v) + ms.orig.Flags = uint32(v) } // SeverityText returns the severitytext associated with this LogRecord. func (ms LogRecord) SeverityText() string { - return ms.getOrig().SeverityText + return ms.orig.SeverityText } // SetSeverityText replaces the severitytext associated with this LogRecord. func (ms LogRecord) SetSeverityText(v string) { - ms.getOrig().SeverityText = v + ms.orig.SeverityText = v } // SeverityNumber returns the severitynumber associated with this LogRecord. func (ms LogRecord) SeverityNumber() SeverityNumber { - return SeverityNumber(ms.getOrig().SeverityNumber) + return SeverityNumber(ms.orig.SeverityNumber) } // SetSeverityNumber replaces the severitynumber associated with this LogRecord. func (ms LogRecord) SetSeverityNumber(v SeverityNumber) { - ms.getOrig().SeverityNumber = otlplogs.SeverityNumber(v) + ms.orig.SeverityNumber = otlplogs.SeverityNumber(v) } // Body returns the body associated with this LogRecord. func (ms LogRecord) Body() pcommon.Value { - return pcommon.Value(internal.NewValue(&ms.getOrig().Body)) + return pcommon.Value(internal.NewValue(&ms.orig.Body)) } // Attributes returns the Attributes associated with this LogRecord. func (ms LogRecord) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // DroppedAttributesCount returns the droppedattributescount associated with this LogRecord. func (ms LogRecord) DroppedAttributesCount() uint32 { - return ms.getOrig().DroppedAttributesCount + return ms.orig.DroppedAttributesCount } // SetDroppedAttributesCount replaces the droppedattributescount associated with this LogRecord. func (ms LogRecord) SetDroppedAttributesCount(v uint32) { - ms.getOrig().DroppedAttributesCount = v + ms.orig.DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/plog/generated_logs_test.go b/pdata/plog/generated_logs_test.go index 178650370f7..26aecf75295 100644 --- a/pdata/plog/generated_logs_test.go +++ b/pdata/plog/generated_logs_test.go @@ -36,12 +36,12 @@ func TestResourceLogsSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newResourceLogs(&otlplogs.ResourceLogs{}) - testVal := ResourceLogs(internal.GenerateTestResourceLogs()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestResourceLogs() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestResourceLogs(internal.ResourceLogs(el)) + fillTestResourceLogs(el) assert.Equal(t, testVal, el) } } @@ -53,28 +53,28 @@ func TestResourceLogsSlice_CopyTo(t *testing.T) { assert.Equal(t, NewResourceLogsSlice(), dest) // Test CopyTo larger slice - ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()).CopyTo(dest) - assert.Equal(t, ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()), dest) + generateTestResourceLogsSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceLogsSlice(), dest) // Test CopyTo same size slice - ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()).CopyTo(dest) - assert.Equal(t, ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()), dest) + generateTestResourceLogsSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceLogsSlice(), dest) } func TestResourceLogsSlice_EnsureCapacity(t *testing.T) { - es := ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()) + es := generateTestResourceLogsSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlplogs.ResourceLogs]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlplogs.ResourceLogs]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -83,36 +83,36 @@ func TestResourceLogsSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlplogs.ResourceLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlplogs.ResourceLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestResourceLogsSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()) + expectedSlice := generateTestResourceLogsSlice() dest := NewResourceLogsSlice() - src := ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()) + src := generateTestResourceLogsSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()), dest) + assert.Equal(t, generateTestResourceLogsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()), dest) + assert.Equal(t, generateTestResourceLogsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()).MoveAndAppendTo(dest) + generateTestResourceLogsSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -129,7 +129,7 @@ func TestResourceLogsSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()) + filtered := generateTestResourceLogsSlice() pos := 0 filtered.RemoveIf(func(el ResourceLogs) bool { pos++ @@ -138,12 +138,26 @@ func TestResourceLogsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestResourceLogsSlice() ResourceLogsSlice { + tv := NewResourceLogsSlice() + fillTestResourceLogsSlice(tv) + return tv +} + +func fillTestResourceLogsSlice(tv ResourceLogsSlice) { + *tv.orig = make([]*otlplogs.ResourceLogs, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlplogs.ResourceLogs{} + fillTestResourceLogs(newResourceLogs((*tv.orig)[i])) + } +} + func TestResourceLogs_MoveTo(t *testing.T) { - ms := ResourceLogs(internal.GenerateTestResourceLogs()) + ms := generateTestResourceLogs() dest := NewResourceLogs() ms.MoveTo(dest) assert.Equal(t, NewResourceLogs(), ms) - assert.Equal(t, ResourceLogs(internal.GenerateTestResourceLogs()), dest) + assert.Equal(t, generateTestResourceLogs(), dest) } func TestResourceLogs_CopyTo(t *testing.T) { @@ -151,7 +165,7 @@ func TestResourceLogs_CopyTo(t *testing.T) { orig := NewResourceLogs() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ResourceLogs(internal.GenerateTestResourceLogs()) + orig = generateTestResourceLogs() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -172,8 +186,20 @@ func TestResourceLogs_SchemaUrl(t *testing.T) { func TestResourceLogs_ScopeLogs(t *testing.T) { ms := NewResourceLogs() assert.Equal(t, NewScopeLogsSlice(), ms.ScopeLogs()) - internal.FillTestScopeLogsSlice(internal.ScopeLogsSlice(ms.ScopeLogs())) - assert.Equal(t, ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()), ms.ScopeLogs()) + fillTestScopeLogsSlice(ms.ScopeLogs()) + assert.Equal(t, generateTestScopeLogsSlice(), ms.ScopeLogs()) +} + +func generateTestResourceLogs() ResourceLogs { + tv := NewResourceLogs() + fillTestResourceLogs(tv) + return tv +} + +func fillTestResourceLogs(tv ResourceLogs) { + internal.FillTestResource(internal.NewResource(&tv.orig.Resource)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestScopeLogsSlice(newScopeLogsSlice(&tv.orig.ScopeLogs)) } func TestScopeLogsSlice(t *testing.T) { @@ -184,12 +210,12 @@ func TestScopeLogsSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newScopeLogs(&otlplogs.ScopeLogs{}) - testVal := ScopeLogs(internal.GenerateTestScopeLogs()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestScopeLogs() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestScopeLogs(internal.ScopeLogs(el)) + fillTestScopeLogs(el) assert.Equal(t, testVal, el) } } @@ -201,28 +227,28 @@ func TestScopeLogsSlice_CopyTo(t *testing.T) { assert.Equal(t, NewScopeLogsSlice(), dest) // Test CopyTo larger slice - ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()).CopyTo(dest) - assert.Equal(t, ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()), dest) + generateTestScopeLogsSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeLogsSlice(), dest) // Test CopyTo same size slice - ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()).CopyTo(dest) - assert.Equal(t, ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()), dest) + generateTestScopeLogsSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeLogsSlice(), dest) } func TestScopeLogsSlice_EnsureCapacity(t *testing.T) { - es := ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()) + es := generateTestScopeLogsSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlplogs.ScopeLogs]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlplogs.ScopeLogs]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -231,36 +257,36 @@ func TestScopeLogsSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlplogs.ScopeLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlplogs.ScopeLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestScopeLogsSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()) + expectedSlice := generateTestScopeLogsSlice() dest := NewScopeLogsSlice() - src := ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()) + src := generateTestScopeLogsSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()), dest) + assert.Equal(t, generateTestScopeLogsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()), dest) + assert.Equal(t, generateTestScopeLogsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()).MoveAndAppendTo(dest) + generateTestScopeLogsSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -277,7 +303,7 @@ func TestScopeLogsSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ScopeLogsSlice(internal.GenerateTestScopeLogsSlice()) + filtered := generateTestScopeLogsSlice() pos := 0 filtered.RemoveIf(func(el ScopeLogs) bool { pos++ @@ -286,12 +312,26 @@ func TestScopeLogsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestScopeLogsSlice() ScopeLogsSlice { + tv := NewScopeLogsSlice() + fillTestScopeLogsSlice(tv) + return tv +} + +func fillTestScopeLogsSlice(tv ScopeLogsSlice) { + *tv.orig = make([]*otlplogs.ScopeLogs, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlplogs.ScopeLogs{} + fillTestScopeLogs(newScopeLogs((*tv.orig)[i])) + } +} + func TestScopeLogs_MoveTo(t *testing.T) { - ms := ScopeLogs(internal.GenerateTestScopeLogs()) + ms := generateTestScopeLogs() dest := NewScopeLogs() ms.MoveTo(dest) assert.Equal(t, NewScopeLogs(), ms) - assert.Equal(t, ScopeLogs(internal.GenerateTestScopeLogs()), dest) + assert.Equal(t, generateTestScopeLogs(), dest) } func TestScopeLogs_CopyTo(t *testing.T) { @@ -299,7 +339,7 @@ func TestScopeLogs_CopyTo(t *testing.T) { orig := NewScopeLogs() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ScopeLogs(internal.GenerateTestScopeLogs()) + orig = generateTestScopeLogs() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -320,8 +360,20 @@ func TestScopeLogs_SchemaUrl(t *testing.T) { func TestScopeLogs_LogRecords(t *testing.T) { ms := NewScopeLogs() assert.Equal(t, NewLogRecordSlice(), ms.LogRecords()) - internal.FillTestLogRecordSlice(internal.LogRecordSlice(ms.LogRecords())) - assert.Equal(t, LogRecordSlice(internal.GenerateTestLogRecordSlice()), ms.LogRecords()) + fillTestLogRecordSlice(ms.LogRecords()) + assert.Equal(t, generateTestLogRecordSlice(), ms.LogRecords()) +} + +func generateTestScopeLogs() ScopeLogs { + tv := NewScopeLogs() + fillTestScopeLogs(tv) + return tv +} + +func fillTestScopeLogs(tv ScopeLogs) { + internal.FillTestInstrumentationScope(internal.NewInstrumentationScope(&tv.orig.Scope)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestLogRecordSlice(newLogRecordSlice(&tv.orig.LogRecords)) } func TestLogRecordSlice(t *testing.T) { @@ -332,12 +384,12 @@ func TestLogRecordSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newLogRecord(&otlplogs.LogRecord{}) - testVal := LogRecord(internal.GenerateTestLogRecord()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestLogRecord() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestLogRecord(internal.LogRecord(el)) + fillTestLogRecord(el) assert.Equal(t, testVal, el) } } @@ -349,28 +401,28 @@ func TestLogRecordSlice_CopyTo(t *testing.T) { assert.Equal(t, NewLogRecordSlice(), dest) // Test CopyTo larger slice - LogRecordSlice(internal.GenerateTestLogRecordSlice()).CopyTo(dest) - assert.Equal(t, LogRecordSlice(internal.GenerateTestLogRecordSlice()), dest) + generateTestLogRecordSlice().CopyTo(dest) + assert.Equal(t, generateTestLogRecordSlice(), dest) // Test CopyTo same size slice - LogRecordSlice(internal.GenerateTestLogRecordSlice()).CopyTo(dest) - assert.Equal(t, LogRecordSlice(internal.GenerateTestLogRecordSlice()), dest) + generateTestLogRecordSlice().CopyTo(dest) + assert.Equal(t, generateTestLogRecordSlice(), dest) } func TestLogRecordSlice_EnsureCapacity(t *testing.T) { - es := LogRecordSlice(internal.GenerateTestLogRecordSlice()) + es := generateTestLogRecordSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlplogs.LogRecord]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlplogs.LogRecord]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -379,36 +431,36 @@ func TestLogRecordSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlplogs.LogRecord]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlplogs.LogRecord]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestLogRecordSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := LogRecordSlice(internal.GenerateTestLogRecordSlice()) + expectedSlice := generateTestLogRecordSlice() dest := NewLogRecordSlice() - src := LogRecordSlice(internal.GenerateTestLogRecordSlice()) + src := generateTestLogRecordSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, LogRecordSlice(internal.GenerateTestLogRecordSlice()), dest) + assert.Equal(t, generateTestLogRecordSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, LogRecordSlice(internal.GenerateTestLogRecordSlice()), dest) + assert.Equal(t, generateTestLogRecordSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - LogRecordSlice(internal.GenerateTestLogRecordSlice()).MoveAndAppendTo(dest) + generateTestLogRecordSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -425,7 +477,7 @@ func TestLogRecordSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := LogRecordSlice(internal.GenerateTestLogRecordSlice()) + filtered := generateTestLogRecordSlice() pos := 0 filtered.RemoveIf(func(el LogRecord) bool { pos++ @@ -434,12 +486,26 @@ func TestLogRecordSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestLogRecordSlice() LogRecordSlice { + tv := NewLogRecordSlice() + fillTestLogRecordSlice(tv) + return tv +} + +func fillTestLogRecordSlice(tv LogRecordSlice) { + *tv.orig = make([]*otlplogs.LogRecord, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlplogs.LogRecord{} + fillTestLogRecord(newLogRecord((*tv.orig)[i])) + } +} + func TestLogRecord_MoveTo(t *testing.T) { - ms := LogRecord(internal.GenerateTestLogRecord()) + ms := generateTestLogRecord() dest := NewLogRecord() ms.MoveTo(dest) assert.Equal(t, NewLogRecord(), ms) - assert.Equal(t, LogRecord(internal.GenerateTestLogRecord()), dest) + assert.Equal(t, generateTestLogRecord(), dest) } func TestLogRecord_CopyTo(t *testing.T) { @@ -447,7 +513,7 @@ func TestLogRecord_CopyTo(t *testing.T) { orig := NewLogRecord() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = LogRecord(internal.GenerateTestLogRecord()) + orig = generateTestLogRecord() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -526,3 +592,22 @@ func TestLogRecord_DroppedAttributesCount(t *testing.T) { ms.SetDroppedAttributesCount(uint32(17)) assert.Equal(t, uint32(17), ms.DroppedAttributesCount()) } + +func generateTestLogRecord() LogRecord { + tv := NewLogRecord() + fillTestLogRecord(tv) + return tv +} + +func fillTestLogRecord(tv LogRecord) { + tv.orig.ObservedTimeUnixNano = 1234567890 + tv.orig.TimeUnixNano = 1234567890 + tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) + tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) + tv.orig.Flags = 1 + tv.orig.SeverityText = "INFO" + tv.orig.SeverityNumber = otlplogs.SeverityNumber(5) + internal.FillTestValue(internal.NewValue(&tv.orig.Body)) + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.DroppedAttributesCount = uint32(17) +} diff --git a/pdata/plog/logs_test.go b/pdata/plog/logs_test.go index aa1db8ae210..ae740684e51 100644 --- a/pdata/plog/logs_test.go +++ b/pdata/plog/logs_test.go @@ -22,7 +22,6 @@ import ( goproto "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/emptypb" - "go.opentelemetry.io/collector/pdata/internal" otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1" otlplogs "go.opentelemetry.io/collector/pdata/internal/data/protogen/logs/v1" ) @@ -90,7 +89,7 @@ func TestResourceLogsWireCompatibility(t *testing.T) { // Generate ResourceLogs as pdata struct. logs := NewLogs() - internal.FillTestResourceLogsSlice(internal.ResourceLogsSlice(logs.ResourceLogs())) + fillTestResourceLogsSlice(logs.ResourceLogs()) // Marshal its underlying ProtoBuf to wire. wire1, err := gogoproto.Marshal(logs.getOrig()) @@ -119,16 +118,16 @@ func TestResourceLogsWireCompatibility(t *testing.T) { func TestLogsMoveTo(t *testing.T) { logs := NewLogs() - internal.FillTestResourceLogsSlice(internal.ResourceLogsSlice(logs.ResourceLogs())) + fillTestResourceLogsSlice(logs.ResourceLogs()) dest := NewLogs() logs.MoveTo(dest) assert.EqualValues(t, NewLogs(), logs) - assert.EqualValues(t, ResourceLogsSlice(internal.GenerateTestResourceLogsSlice()), dest.ResourceLogs()) + assert.EqualValues(t, generateTestResourceLogsSlice(), dest.ResourceLogs()) } func TestLogsCopyTo(t *testing.T) { logs := NewLogs() - internal.FillTestResourceLogsSlice(internal.ResourceLogsSlice(logs.ResourceLogs())) + fillTestResourceLogsSlice(logs.ResourceLogs()) logsCopy := NewLogs() logs.CopyTo(logsCopy) assert.EqualValues(t, logs, logsCopy) diff --git a/pdata/plog/plogotlp/generated_logs_otlp.go b/pdata/plog/plogotlp/generated_logs_otlp.go index 14279cc3a6e..0f729d9aa50 100644 --- a/pdata/plog/plogotlp/generated_logs_otlp.go +++ b/pdata/plog/plogotlp/generated_logs_otlp.go @@ -18,7 +18,6 @@ package plogotlp import ( - "go.opentelemetry.io/collector/pdata/internal" otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1" ) @@ -29,15 +28,12 @@ import ( // // Must use NewExportPartialSuccess function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ExportPartialSuccess internal.LogsExportPartialSuccess - -func newExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) ExportPartialSuccess { - return ExportPartialSuccess(internal.NewLogsExportPartialSuccess(orig)) +type ExportPartialSuccess struct { + orig *otlpcollectorlog.ExportLogsPartialSuccess } -func (ms ExportPartialSuccess) getOrig() *otlpcollectorlog.ExportLogsPartialSuccess { - return internal.GetOrigLogsExportPartialSuccess(internal.LogsExportPartialSuccess(ms)) +func newExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) ExportPartialSuccess { + return ExportPartialSuccess{orig} } // NewExportPartialSuccess creates a new empty ExportPartialSuccess. @@ -51,28 +47,28 @@ func NewExportPartialSuccess() ExportPartialSuccess { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ExportPartialSuccess) MoveTo(dest ExportPartialSuccess) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpcollectorlog.ExportLogsPartialSuccess{} + *dest.orig = *ms.orig + *ms.orig = otlpcollectorlog.ExportLogsPartialSuccess{} } // RejectedLogRecords returns the rejectedlogrecords associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) RejectedLogRecords() int64 { - return ms.getOrig().RejectedLogRecords + return ms.orig.RejectedLogRecords } // SetRejectedLogRecords replaces the rejectedlogrecords associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) SetRejectedLogRecords(v int64) { - ms.getOrig().RejectedLogRecords = v + ms.orig.RejectedLogRecords = v } // ErrorMessage returns the errormessage associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) ErrorMessage() string { - return ms.getOrig().ErrorMessage + return ms.orig.ErrorMessage } // SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) SetErrorMessage(v string) { - ms.getOrig().ErrorMessage = v + ms.orig.ErrorMessage = v } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/plog/plogotlp/generated_logs_otlp_test.go b/pdata/plog/plogotlp/generated_logs_otlp_test.go index 28c9f7c568c..a0db18b5637 100644 --- a/pdata/plog/plogotlp/generated_logs_otlp_test.go +++ b/pdata/plog/plogotlp/generated_logs_otlp_test.go @@ -21,16 +21,14 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/pdata/internal" ) func TestExportPartialSuccess_MoveTo(t *testing.T) { - ms := ExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()) + ms := generateTestExportPartialSuccess() dest := NewExportPartialSuccess() ms.MoveTo(dest) assert.Equal(t, NewExportPartialSuccess(), ms) - assert.Equal(t, ExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()), dest) + assert.Equal(t, generateTestExportPartialSuccess(), dest) } func TestExportPartialSuccess_CopyTo(t *testing.T) { @@ -38,7 +36,7 @@ func TestExportPartialSuccess_CopyTo(t *testing.T) { orig := NewExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()) + orig = generateTestExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -56,3 +54,14 @@ func TestExportPartialSuccess_ErrorMessage(t *testing.T) { ms.SetErrorMessage("error message") assert.Equal(t, "error message", ms.ErrorMessage()) } + +func generateTestExportPartialSuccess() ExportPartialSuccess { + tv := NewExportPartialSuccess() + fillTestExportPartialSuccess(tv) + return tv +} + +func fillTestExportPartialSuccess(tv ExportPartialSuccess) { + tv.orig.RejectedLogRecords = int64(13) + tv.orig.ErrorMessage = "error message" +} diff --git a/pdata/plog/plogotlp/response.go b/pdata/plog/plogotlp/response.go index fffeb5f0262..94c4086a643 100644 --- a/pdata/plog/plogotlp/response.go +++ b/pdata/plog/plogotlp/response.go @@ -13,10 +13,10 @@ // limitations under the License. package plogotlp // import "go.opentelemetry.io/collector/pdata/plog/plogotlp" + import ( "bytes" - "go.opentelemetry.io/collector/pdata/internal" otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1" "go.opentelemetry.io/collector/pdata/plog/internal/plogjson" ) @@ -57,5 +57,5 @@ func (lr ExportResponse) UnmarshalJSON(data []byte) error { // PartialSuccess returns the ExportPartialSuccess associated with this ExportResponse. func (lr ExportResponse) PartialSuccess() ExportPartialSuccess { - return ExportPartialSuccess(internal.NewLogsExportPartialSuccess(&lr.orig.PartialSuccess)) + return newExportPartialSuccess(&lr.orig.PartialSuccess) } diff --git a/pdata/pmetric/generated_metrics.go b/pdata/pmetric/generated_metrics.go index 2f97d3ccde1..55026217c58 100644 --- a/pdata/pmetric/generated_metrics.go +++ b/pdata/pmetric/generated_metrics.go @@ -33,14 +33,12 @@ import ( // // Must use NewResourceMetricsSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ResourceMetricsSlice internal.ResourceMetricsSlice - -func newResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) ResourceMetricsSlice { - return ResourceMetricsSlice(internal.NewResourceMetricsSlice(orig)) +type ResourceMetricsSlice struct { + orig *[]*otlpmetrics.ResourceMetrics } -func (ms ResourceMetricsSlice) getOrig() *[]*otlpmetrics.ResourceMetrics { - return internal.GetOrigResourceMetricsSlice(internal.ResourceMetricsSlice(ms)) +func newResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) ResourceMetricsSlice { + return ResourceMetricsSlice{orig} } // NewResourceMetricsSlice creates a ResourceMetricsSlice with 0 elements. @@ -54,7 +52,7 @@ func NewResourceMetricsSlice() ResourceMetricsSlice { // // Returns "0" for a newly instance created with "NewResourceMetricsSlice()". func (es ResourceMetricsSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -66,27 +64,27 @@ func (es ResourceMetricsSlice) Len() int { // ... // Do something with the element // } func (es ResourceMetricsSlice) At(ix int) ResourceMetrics { - return newResourceMetrics((*es.getOrig())[ix]) + return newResourceMetrics((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newResourceMetrics((*es.getOrig())[i]).CopyTo(newResourceMetrics((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newResourceMetrics((*es.orig)[i]).CopyTo(newResourceMetrics((*dest.orig)[i])) } return } origs := make([]otlpmetrics.ResourceMetrics, srcLen) wrappers := make([]*otlpmetrics.ResourceMetrics, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newResourceMetrics((*es.getOrig())[i]).CopyTo(newResourceMetrics(wrappers[i])) + newResourceMetrics((*es.orig)[i]).CopyTo(newResourceMetrics(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -102,20 +100,20 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { // // Here should set all the values for e. // } func (es ResourceMetricsSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.ResourceMetrics, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.ResourceMetrics, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ResourceMetrics. // It returns the newly added ResourceMetrics. func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.ResourceMetrics{}) + *es.orig = append(*es.orig, &otlpmetrics.ResourceMetrics{}) return es.At(es.Len() - 1) } @@ -123,26 +121,26 @@ func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { // provided less function so that two instances of ResourceMetricsSlice // can be compared. func (es ResourceMetricsSlice) Sort(less func(a, b ResourceMetrics) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceMetricsSlice) MoveAndAppendTo(dest ResourceMetricsSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ResourceMetricsSlice) RemoveIf(f func(ResourceMetrics) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -151,11 +149,11 @@ func (es ResourceMetricsSlice) RemoveIf(f func(ResourceMetrics) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ResourceMetrics is a collection of metrics from a Resource. @@ -165,15 +163,12 @@ func (es ResourceMetricsSlice) RemoveIf(f func(ResourceMetrics) bool) { // // Must use NewResourceMetrics function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ResourceMetrics internal.ResourceMetrics - -func newResourceMetrics(orig *otlpmetrics.ResourceMetrics) ResourceMetrics { - return ResourceMetrics(internal.NewResourceMetrics(orig)) +type ResourceMetrics struct { + orig *otlpmetrics.ResourceMetrics } -func (ms ResourceMetrics) getOrig() *otlpmetrics.ResourceMetrics { - return internal.GetOrigResourceMetrics(internal.ResourceMetrics(ms)) +func newResourceMetrics(orig *otlpmetrics.ResourceMetrics) ResourceMetrics { + return ResourceMetrics{orig} } // NewResourceMetrics creates a new empty ResourceMetrics. @@ -187,28 +182,28 @@ func NewResourceMetrics() ResourceMetrics { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ResourceMetrics) MoveTo(dest ResourceMetrics) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.ResourceMetrics{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.ResourceMetrics{} } // Resource returns the resource associated with this ResourceMetrics. func (ms ResourceMetrics) Resource() pcommon.Resource { - return pcommon.Resource(internal.NewResource(&ms.getOrig().Resource)) + return pcommon.Resource(internal.NewResource(&ms.orig.Resource)) } // SchemaUrl returns the schemaurl associated with this ResourceMetrics. func (ms ResourceMetrics) SchemaUrl() string { - return ms.getOrig().SchemaUrl + return ms.orig.SchemaUrl } // SetSchemaUrl replaces the schemaurl associated with this ResourceMetrics. func (ms ResourceMetrics) SetSchemaUrl(v string) { - ms.getOrig().SchemaUrl = v + ms.orig.SchemaUrl = v } // ScopeMetrics returns the ScopeMetrics associated with this ResourceMetrics. func (ms ResourceMetrics) ScopeMetrics() ScopeMetricsSlice { - return ScopeMetricsSlice(internal.NewScopeMetricsSlice(&ms.getOrig().ScopeMetrics)) + return newScopeMetricsSlice(&ms.orig.ScopeMetrics) } // CopyTo copies all properties from the current struct overriding the destination. @@ -225,14 +220,12 @@ func (ms ResourceMetrics) CopyTo(dest ResourceMetrics) { // // Must use NewScopeMetricsSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ScopeMetricsSlice internal.ScopeMetricsSlice - -func newScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) ScopeMetricsSlice { - return ScopeMetricsSlice(internal.NewScopeMetricsSlice(orig)) +type ScopeMetricsSlice struct { + orig *[]*otlpmetrics.ScopeMetrics } -func (ms ScopeMetricsSlice) getOrig() *[]*otlpmetrics.ScopeMetrics { - return internal.GetOrigScopeMetricsSlice(internal.ScopeMetricsSlice(ms)) +func newScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) ScopeMetricsSlice { + return ScopeMetricsSlice{orig} } // NewScopeMetricsSlice creates a ScopeMetricsSlice with 0 elements. @@ -246,7 +239,7 @@ func NewScopeMetricsSlice() ScopeMetricsSlice { // // Returns "0" for a newly instance created with "NewScopeMetricsSlice()". func (es ScopeMetricsSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -258,27 +251,27 @@ func (es ScopeMetricsSlice) Len() int { // ... // Do something with the element // } func (es ScopeMetricsSlice) At(ix int) ScopeMetrics { - return newScopeMetrics((*es.getOrig())[ix]) + return newScopeMetrics((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newScopeMetrics((*es.getOrig())[i]).CopyTo(newScopeMetrics((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newScopeMetrics((*es.orig)[i]).CopyTo(newScopeMetrics((*dest.orig)[i])) } return } origs := make([]otlpmetrics.ScopeMetrics, srcLen) wrappers := make([]*otlpmetrics.ScopeMetrics, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newScopeMetrics((*es.getOrig())[i]).CopyTo(newScopeMetrics(wrappers[i])) + newScopeMetrics((*es.orig)[i]).CopyTo(newScopeMetrics(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -294,20 +287,20 @@ func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { // // Here should set all the values for e. // } func (es ScopeMetricsSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.ScopeMetrics, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.ScopeMetrics, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ScopeMetrics. // It returns the newly added ScopeMetrics. func (es ScopeMetricsSlice) AppendEmpty() ScopeMetrics { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.ScopeMetrics{}) + *es.orig = append(*es.orig, &otlpmetrics.ScopeMetrics{}) return es.At(es.Len() - 1) } @@ -315,26 +308,26 @@ func (es ScopeMetricsSlice) AppendEmpty() ScopeMetrics { // provided less function so that two instances of ScopeMetricsSlice // can be compared. func (es ScopeMetricsSlice) Sort(less func(a, b ScopeMetrics) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ScopeMetricsSlice) MoveAndAppendTo(dest ScopeMetricsSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ScopeMetricsSlice) RemoveIf(f func(ScopeMetrics) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -343,11 +336,11 @@ func (es ScopeMetricsSlice) RemoveIf(f func(ScopeMetrics) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ScopeMetrics is a collection of metrics from a LibraryInstrumentation. @@ -357,15 +350,12 @@ func (es ScopeMetricsSlice) RemoveIf(f func(ScopeMetrics) bool) { // // Must use NewScopeMetrics function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ScopeMetrics internal.ScopeMetrics - -func newScopeMetrics(orig *otlpmetrics.ScopeMetrics) ScopeMetrics { - return ScopeMetrics(internal.NewScopeMetrics(orig)) +type ScopeMetrics struct { + orig *otlpmetrics.ScopeMetrics } -func (ms ScopeMetrics) getOrig() *otlpmetrics.ScopeMetrics { - return internal.GetOrigScopeMetrics(internal.ScopeMetrics(ms)) +func newScopeMetrics(orig *otlpmetrics.ScopeMetrics) ScopeMetrics { + return ScopeMetrics{orig} } // NewScopeMetrics creates a new empty ScopeMetrics. @@ -379,28 +369,28 @@ func NewScopeMetrics() ScopeMetrics { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ScopeMetrics) MoveTo(dest ScopeMetrics) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.ScopeMetrics{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.ScopeMetrics{} } // Scope returns the scope associated with this ScopeMetrics. func (ms ScopeMetrics) Scope() pcommon.InstrumentationScope { - return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.getOrig().Scope)) + return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.orig.Scope)) } // SchemaUrl returns the schemaurl associated with this ScopeMetrics. func (ms ScopeMetrics) SchemaUrl() string { - return ms.getOrig().SchemaUrl + return ms.orig.SchemaUrl } // SetSchemaUrl replaces the schemaurl associated with this ScopeMetrics. func (ms ScopeMetrics) SetSchemaUrl(v string) { - ms.getOrig().SchemaUrl = v + ms.orig.SchemaUrl = v } // Metrics returns the Metrics associated with this ScopeMetrics. func (ms ScopeMetrics) Metrics() MetricSlice { - return MetricSlice(internal.NewMetricSlice(&ms.getOrig().Metrics)) + return newMetricSlice(&ms.orig.Metrics) } // CopyTo copies all properties from the current struct overriding the destination. @@ -417,14 +407,12 @@ func (ms ScopeMetrics) CopyTo(dest ScopeMetrics) { // // Must use NewMetricSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type MetricSlice internal.MetricSlice - -func newMetricSlice(orig *[]*otlpmetrics.Metric) MetricSlice { - return MetricSlice(internal.NewMetricSlice(orig)) +type MetricSlice struct { + orig *[]*otlpmetrics.Metric } -func (ms MetricSlice) getOrig() *[]*otlpmetrics.Metric { - return internal.GetOrigMetricSlice(internal.MetricSlice(ms)) +func newMetricSlice(orig *[]*otlpmetrics.Metric) MetricSlice { + return MetricSlice{orig} } // NewMetricSlice creates a MetricSlice with 0 elements. @@ -438,7 +426,7 @@ func NewMetricSlice() MetricSlice { // // Returns "0" for a newly instance created with "NewMetricSlice()". func (es MetricSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -450,27 +438,27 @@ func (es MetricSlice) Len() int { // ... // Do something with the element // } func (es MetricSlice) At(ix int) Metric { - return newMetric((*es.getOrig())[ix]) + return newMetric((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es MetricSlice) CopyTo(dest MetricSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newMetric((*es.getOrig())[i]).CopyTo(newMetric((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newMetric((*es.orig)[i]).CopyTo(newMetric((*dest.orig)[i])) } return } origs := make([]otlpmetrics.Metric, srcLen) wrappers := make([]*otlpmetrics.Metric, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newMetric((*es.getOrig())[i]).CopyTo(newMetric(wrappers[i])) + newMetric((*es.orig)[i]).CopyTo(newMetric(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -486,20 +474,20 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { // // Here should set all the values for e. // } func (es MetricSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.Metric, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.Metric, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty Metric. // It returns the newly added Metric. func (es MetricSlice) AppendEmpty() Metric { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.Metric{}) + *es.orig = append(*es.orig, &otlpmetrics.Metric{}) return es.At(es.Len() - 1) } @@ -507,26 +495,26 @@ func (es MetricSlice) AppendEmpty() Metric { // provided less function so that two instances of MetricSlice // can be compared. func (es MetricSlice) Sort(less func(a, b Metric) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es MetricSlice) MoveAndAppendTo(dest MetricSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es MetricSlice) RemoveIf(f func(Metric) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -535,11 +523,11 @@ func (es MetricSlice) RemoveIf(f func(Metric) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // Metric represents one metric as a collection of datapoints. @@ -550,15 +538,12 @@ func (es MetricSlice) RemoveIf(f func(Metric) bool) { // // Must use NewMetric function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Metric internal.Metric - -func newMetric(orig *otlpmetrics.Metric) Metric { - return Metric(internal.NewMetric(orig)) +type Metric struct { + orig *otlpmetrics.Metric } -func (ms Metric) getOrig() *otlpmetrics.Metric { - return internal.GetOrigMetric(internal.Metric(ms)) +func newMetric(orig *otlpmetrics.Metric) Metric { + return Metric{orig} } // NewMetric creates a new empty Metric. @@ -572,44 +557,44 @@ func NewMetric() Metric { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Metric) MoveTo(dest Metric) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.Metric{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.Metric{} } // Name returns the name associated with this Metric. func (ms Metric) Name() string { - return ms.getOrig().Name + return ms.orig.Name } // SetName replaces the name associated with this Metric. func (ms Metric) SetName(v string) { - ms.getOrig().Name = v + ms.orig.Name = v } // Description returns the description associated with this Metric. func (ms Metric) Description() string { - return ms.getOrig().Description + return ms.orig.Description } // SetDescription replaces the description associated with this Metric. func (ms Metric) SetDescription(v string) { - ms.getOrig().Description = v + ms.orig.Description = v } // Unit returns the unit associated with this Metric. func (ms Metric) Unit() string { - return ms.getOrig().Unit + return ms.orig.Unit } // SetUnit replaces the unit associated with this Metric. func (ms Metric) SetUnit(v string) { - ms.getOrig().Unit = v + ms.orig.Unit = v } // Type returns the type of the data for this Metric. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) Type() MetricType { - switch ms.getOrig().Data.(type) { + switch ms.orig.Data.(type) { case *otlpmetrics.Metric_Gauge: return MetricTypeGauge case *otlpmetrics.Metric_Sum: @@ -631,7 +616,7 @@ func (ms Metric) Type() MetricType { // // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) Gauge() Gauge { - v, ok := ms.getOrig().GetData().(*otlpmetrics.Metric_Gauge) + v, ok := ms.orig.GetData().(*otlpmetrics.Metric_Gauge) if !ok { return Gauge{} } @@ -645,7 +630,7 @@ func (ms Metric) Gauge() Gauge { // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) SetEmptyGauge() Gauge { val := &otlpmetrics.Gauge{} - ms.getOrig().Data = &otlpmetrics.Metric_Gauge{Gauge: val} + ms.orig.Data = &otlpmetrics.Metric_Gauge{Gauge: val} return newGauge(val) } @@ -656,7 +641,7 @@ func (ms Metric) SetEmptyGauge() Gauge { // // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) Sum() Sum { - v, ok := ms.getOrig().GetData().(*otlpmetrics.Metric_Sum) + v, ok := ms.orig.GetData().(*otlpmetrics.Metric_Sum) if !ok { return Sum{} } @@ -670,7 +655,7 @@ func (ms Metric) Sum() Sum { // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) SetEmptySum() Sum { val := &otlpmetrics.Sum{} - ms.getOrig().Data = &otlpmetrics.Metric_Sum{Sum: val} + ms.orig.Data = &otlpmetrics.Metric_Sum{Sum: val} return newSum(val) } @@ -681,7 +666,7 @@ func (ms Metric) SetEmptySum() Sum { // // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) Histogram() Histogram { - v, ok := ms.getOrig().GetData().(*otlpmetrics.Metric_Histogram) + v, ok := ms.orig.GetData().(*otlpmetrics.Metric_Histogram) if !ok { return Histogram{} } @@ -695,7 +680,7 @@ func (ms Metric) Histogram() Histogram { // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) SetEmptyHistogram() Histogram { val := &otlpmetrics.Histogram{} - ms.getOrig().Data = &otlpmetrics.Metric_Histogram{Histogram: val} + ms.orig.Data = &otlpmetrics.Metric_Histogram{Histogram: val} return newHistogram(val) } @@ -706,7 +691,7 @@ func (ms Metric) SetEmptyHistogram() Histogram { // // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) ExponentialHistogram() ExponentialHistogram { - v, ok := ms.getOrig().GetData().(*otlpmetrics.Metric_ExponentialHistogram) + v, ok := ms.orig.GetData().(*otlpmetrics.Metric_ExponentialHistogram) if !ok { return ExponentialHistogram{} } @@ -720,7 +705,7 @@ func (ms Metric) ExponentialHistogram() ExponentialHistogram { // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram { val := &otlpmetrics.ExponentialHistogram{} - ms.getOrig().Data = &otlpmetrics.Metric_ExponentialHistogram{ExponentialHistogram: val} + ms.orig.Data = &otlpmetrics.Metric_ExponentialHistogram{ExponentialHistogram: val} return newExponentialHistogram(val) } @@ -731,7 +716,7 @@ func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram { // // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) Summary() Summary { - v, ok := ms.getOrig().GetData().(*otlpmetrics.Metric_Summary) + v, ok := ms.orig.GetData().(*otlpmetrics.Metric_Summary) if !ok { return Summary{} } @@ -745,7 +730,7 @@ func (ms Metric) Summary() Summary { // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) SetEmptySummary() Summary { val := &otlpmetrics.Summary{} - ms.getOrig().Data = &otlpmetrics.Metric_Summary{Summary: val} + ms.orig.Data = &otlpmetrics.Metric_Summary{Summary: val} return newSummary(val) } @@ -776,15 +761,12 @@ func (ms Metric) CopyTo(dest Metric) { // // Must use NewGauge function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Gauge internal.Gauge - -func newGauge(orig *otlpmetrics.Gauge) Gauge { - return Gauge(internal.NewGauge(orig)) +type Gauge struct { + orig *otlpmetrics.Gauge } -func (ms Gauge) getOrig() *otlpmetrics.Gauge { - return internal.GetOrigGauge(internal.Gauge(ms)) +func newGauge(orig *otlpmetrics.Gauge) Gauge { + return Gauge{orig} } // NewGauge creates a new empty Gauge. @@ -798,13 +780,13 @@ func NewGauge() Gauge { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Gauge) MoveTo(dest Gauge) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.Gauge{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.Gauge{} } // DataPoints returns the DataPoints associated with this Gauge. func (ms Gauge) DataPoints() NumberDataPointSlice { - return NumberDataPointSlice(internal.NewNumberDataPointSlice(&ms.getOrig().DataPoints)) + return newNumberDataPointSlice(&ms.orig.DataPoints) } // CopyTo copies all properties from the current struct overriding the destination. @@ -819,15 +801,12 @@ func (ms Gauge) CopyTo(dest Gauge) { // // Must use NewSum function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Sum internal.Sum - -func newSum(orig *otlpmetrics.Sum) Sum { - return Sum(internal.NewSum(orig)) +type Sum struct { + orig *otlpmetrics.Sum } -func (ms Sum) getOrig() *otlpmetrics.Sum { - return internal.GetOrigSum(internal.Sum(ms)) +func newSum(orig *otlpmetrics.Sum) Sum { + return Sum{orig} } // NewSum creates a new empty Sum. @@ -841,33 +820,33 @@ func NewSum() Sum { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Sum) MoveTo(dest Sum) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.Sum{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.Sum{} } // AggregationTemporality returns the aggregationtemporality associated with this Sum. func (ms Sum) AggregationTemporality() AggregationTemporality { - return AggregationTemporality(ms.getOrig().AggregationTemporality) + return AggregationTemporality(ms.orig.AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this Sum. func (ms Sum) SetAggregationTemporality(v AggregationTemporality) { - ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) + ms.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(v) } // IsMonotonic returns the ismonotonic associated with this Sum. func (ms Sum) IsMonotonic() bool { - return ms.getOrig().IsMonotonic + return ms.orig.IsMonotonic } // SetIsMonotonic replaces the ismonotonic associated with this Sum. func (ms Sum) SetIsMonotonic(v bool) { - ms.getOrig().IsMonotonic = v + ms.orig.IsMonotonic = v } // DataPoints returns the DataPoints associated with this Sum. func (ms Sum) DataPoints() NumberDataPointSlice { - return NumberDataPointSlice(internal.NewNumberDataPointSlice(&ms.getOrig().DataPoints)) + return newNumberDataPointSlice(&ms.orig.DataPoints) } // CopyTo copies all properties from the current struct overriding the destination. @@ -884,15 +863,12 @@ func (ms Sum) CopyTo(dest Sum) { // // Must use NewHistogram function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Histogram internal.Histogram - -func newHistogram(orig *otlpmetrics.Histogram) Histogram { - return Histogram(internal.NewHistogram(orig)) +type Histogram struct { + orig *otlpmetrics.Histogram } -func (ms Histogram) getOrig() *otlpmetrics.Histogram { - return internal.GetOrigHistogram(internal.Histogram(ms)) +func newHistogram(orig *otlpmetrics.Histogram) Histogram { + return Histogram{orig} } // NewHistogram creates a new empty Histogram. @@ -906,23 +882,23 @@ func NewHistogram() Histogram { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Histogram) MoveTo(dest Histogram) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.Histogram{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.Histogram{} } // AggregationTemporality returns the aggregationtemporality associated with this Histogram. func (ms Histogram) AggregationTemporality() AggregationTemporality { - return AggregationTemporality(ms.getOrig().AggregationTemporality) + return AggregationTemporality(ms.orig.AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this Histogram. func (ms Histogram) SetAggregationTemporality(v AggregationTemporality) { - ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) + ms.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(v) } // DataPoints returns the DataPoints associated with this Histogram. func (ms Histogram) DataPoints() HistogramDataPointSlice { - return HistogramDataPointSlice(internal.NewHistogramDataPointSlice(&ms.getOrig().DataPoints)) + return newHistogramDataPointSlice(&ms.orig.DataPoints) } // CopyTo copies all properties from the current struct overriding the destination. @@ -939,15 +915,12 @@ func (ms Histogram) CopyTo(dest Histogram) { // // Must use NewExponentialHistogram function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ExponentialHistogram internal.ExponentialHistogram - -func newExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) ExponentialHistogram { - return ExponentialHistogram(internal.NewExponentialHistogram(orig)) +type ExponentialHistogram struct { + orig *otlpmetrics.ExponentialHistogram } -func (ms ExponentialHistogram) getOrig() *otlpmetrics.ExponentialHistogram { - return internal.GetOrigExponentialHistogram(internal.ExponentialHistogram(ms)) +func newExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) ExponentialHistogram { + return ExponentialHistogram{orig} } // NewExponentialHistogram creates a new empty ExponentialHistogram. @@ -961,23 +934,23 @@ func NewExponentialHistogram() ExponentialHistogram { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ExponentialHistogram) MoveTo(dest ExponentialHistogram) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.ExponentialHistogram{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.ExponentialHistogram{} } // AggregationTemporality returns the aggregationtemporality associated with this ExponentialHistogram. func (ms ExponentialHistogram) AggregationTemporality() AggregationTemporality { - return AggregationTemporality(ms.getOrig().AggregationTemporality) + return AggregationTemporality(ms.orig.AggregationTemporality) } // SetAggregationTemporality replaces the aggregationtemporality associated with this ExponentialHistogram. func (ms ExponentialHistogram) SetAggregationTemporality(v AggregationTemporality) { - ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) + ms.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(v) } // DataPoints returns the DataPoints associated with this ExponentialHistogram. func (ms ExponentialHistogram) DataPoints() ExponentialHistogramDataPointSlice { - return ExponentialHistogramDataPointSlice(internal.NewExponentialHistogramDataPointSlice(&ms.getOrig().DataPoints)) + return newExponentialHistogramDataPointSlice(&ms.orig.DataPoints) } // CopyTo copies all properties from the current struct overriding the destination. @@ -993,15 +966,12 @@ func (ms ExponentialHistogram) CopyTo(dest ExponentialHistogram) { // // Must use NewSummary function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Summary internal.Summary - -func newSummary(orig *otlpmetrics.Summary) Summary { - return Summary(internal.NewSummary(orig)) +type Summary struct { + orig *otlpmetrics.Summary } -func (ms Summary) getOrig() *otlpmetrics.Summary { - return internal.GetOrigSummary(internal.Summary(ms)) +func newSummary(orig *otlpmetrics.Summary) Summary { + return Summary{orig} } // NewSummary creates a new empty Summary. @@ -1015,13 +985,13 @@ func NewSummary() Summary { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Summary) MoveTo(dest Summary) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.Summary{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.Summary{} } // DataPoints returns the DataPoints associated with this Summary. func (ms Summary) DataPoints() SummaryDataPointSlice { - return SummaryDataPointSlice(internal.NewSummaryDataPointSlice(&ms.getOrig().DataPoints)) + return newSummaryDataPointSlice(&ms.orig.DataPoints) } // CopyTo copies all properties from the current struct overriding the destination. @@ -1036,14 +1006,12 @@ func (ms Summary) CopyTo(dest Summary) { // // Must use NewNumberDataPointSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type NumberDataPointSlice internal.NumberDataPointSlice - -func newNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) NumberDataPointSlice { - return NumberDataPointSlice(internal.NewNumberDataPointSlice(orig)) +type NumberDataPointSlice struct { + orig *[]*otlpmetrics.NumberDataPoint } -func (ms NumberDataPointSlice) getOrig() *[]*otlpmetrics.NumberDataPoint { - return internal.GetOrigNumberDataPointSlice(internal.NumberDataPointSlice(ms)) +func newNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) NumberDataPointSlice { + return NumberDataPointSlice{orig} } // NewNumberDataPointSlice creates a NumberDataPointSlice with 0 elements. @@ -1057,7 +1025,7 @@ func NewNumberDataPointSlice() NumberDataPointSlice { // // Returns "0" for a newly instance created with "NewNumberDataPointSlice()". func (es NumberDataPointSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -1069,27 +1037,27 @@ func (es NumberDataPointSlice) Len() int { // ... // Do something with the element // } func (es NumberDataPointSlice) At(ix int) NumberDataPoint { - return newNumberDataPoint((*es.getOrig())[ix]) + return newNumberDataPoint((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newNumberDataPoint((*es.getOrig())[i]).CopyTo(newNumberDataPoint((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newNumberDataPoint((*es.orig)[i]).CopyTo(newNumberDataPoint((*dest.orig)[i])) } return } origs := make([]otlpmetrics.NumberDataPoint, srcLen) wrappers := make([]*otlpmetrics.NumberDataPoint, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newNumberDataPoint((*es.getOrig())[i]).CopyTo(newNumberDataPoint(wrappers[i])) + newNumberDataPoint((*es.orig)[i]).CopyTo(newNumberDataPoint(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -1105,20 +1073,20 @@ func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { // // Here should set all the values for e. // } func (es NumberDataPointSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.NumberDataPoint, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.NumberDataPoint, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty NumberDataPoint. // It returns the newly added NumberDataPoint. func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.NumberDataPoint{}) + *es.orig = append(*es.orig, &otlpmetrics.NumberDataPoint{}) return es.At(es.Len() - 1) } @@ -1126,26 +1094,26 @@ func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { // provided less function so that two instances of NumberDataPointSlice // can be compared. func (es NumberDataPointSlice) Sort(less func(a, b NumberDataPoint) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es NumberDataPointSlice) MoveAndAppendTo(dest NumberDataPointSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es NumberDataPointSlice) RemoveIf(f func(NumberDataPoint) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -1154,11 +1122,11 @@ func (es NumberDataPointSlice) RemoveIf(f func(NumberDataPoint) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // NumberDataPoint is a single data point in a timeseries that describes the time-varying value of a number metric. @@ -1168,15 +1136,12 @@ func (es NumberDataPointSlice) RemoveIf(f func(NumberDataPoint) bool) { // // Must use NewNumberDataPoint function to create new instances. // Important: zero-initialized instance is not valid for use. - -type NumberDataPoint internal.NumberDataPoint - -func newNumberDataPoint(orig *otlpmetrics.NumberDataPoint) NumberDataPoint { - return NumberDataPoint(internal.NewNumberDataPoint(orig)) +type NumberDataPoint struct { + orig *otlpmetrics.NumberDataPoint } -func (ms NumberDataPoint) getOrig() *otlpmetrics.NumberDataPoint { - return internal.GetOrigNumberDataPoint(internal.NumberDataPoint(ms)) +func newNumberDataPoint(orig *otlpmetrics.NumberDataPoint) NumberDataPoint { + return NumberDataPoint{orig} } // NewNumberDataPoint creates a new empty NumberDataPoint. @@ -1190,39 +1155,39 @@ func NewNumberDataPoint() NumberDataPoint { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms NumberDataPoint) MoveTo(dest NumberDataPoint) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.NumberDataPoint{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.NumberDataPoint{} } // Attributes returns the Attributes associated with this NumberDataPoint. func (ms NumberDataPoint) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // StartTimestamp returns the starttimestamp associated with this NumberDataPoint. func (ms NumberDataPoint) StartTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) + return pcommon.Timestamp(ms.orig.StartTimeUnixNano) } // SetStartTimestamp replaces the starttimestamp associated with this NumberDataPoint. func (ms NumberDataPoint) SetStartTimestamp(v pcommon.Timestamp) { - ms.getOrig().StartTimeUnixNano = uint64(v) + ms.orig.StartTimeUnixNano = uint64(v) } // Timestamp returns the timestamp associated with this NumberDataPoint. func (ms NumberDataPoint) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this NumberDataPoint. func (ms NumberDataPoint) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // ValueType returns the type of the value for this NumberDataPoint. // Calling this function on zero-initialized NumberDataPoint will cause a panic. func (ms NumberDataPoint) ValueType() NumberDataPointValueType { - switch ms.getOrig().Value.(type) { + switch ms.orig.Value.(type) { case *otlpmetrics.NumberDataPoint_AsDouble: return NumberDataPointValueTypeDouble case *otlpmetrics.NumberDataPoint_AsInt: @@ -1233,41 +1198,41 @@ func (ms NumberDataPoint) ValueType() NumberDataPointValueType { // DoubleValue returns the double associated with this NumberDataPoint. func (ms NumberDataPoint) DoubleValue() float64 { - return ms.getOrig().GetAsDouble() + return ms.orig.GetAsDouble() } // SetDoubleValue replaces the double associated with this NumberDataPoint. func (ms NumberDataPoint) SetDoubleValue(v float64) { - ms.getOrig().Value = &otlpmetrics.NumberDataPoint_AsDouble{ + ms.orig.Value = &otlpmetrics.NumberDataPoint_AsDouble{ AsDouble: v, } } // IntValue returns the int associated with this NumberDataPoint. func (ms NumberDataPoint) IntValue() int64 { - return ms.getOrig().GetAsInt() + return ms.orig.GetAsInt() } // SetIntValue replaces the int associated with this NumberDataPoint. func (ms NumberDataPoint) SetIntValue(v int64) { - ms.getOrig().Value = &otlpmetrics.NumberDataPoint_AsInt{ + ms.orig.Value = &otlpmetrics.NumberDataPoint_AsInt{ AsInt: v, } } // Exemplars returns the Exemplars associated with this NumberDataPoint. func (ms NumberDataPoint) Exemplars() ExemplarSlice { - return ExemplarSlice(internal.NewExemplarSlice(&ms.getOrig().Exemplars)) + return newExemplarSlice(&ms.orig.Exemplars) } // Flags returns the flags associated with this NumberDataPoint. func (ms NumberDataPoint) Flags() DataPointFlags { - return DataPointFlags(ms.getOrig().Flags) + return DataPointFlags(ms.orig.Flags) } // SetFlags replaces the flags associated with this NumberDataPoint. func (ms NumberDataPoint) SetFlags(v DataPointFlags) { - ms.getOrig().Flags = uint32(v) + ms.orig.Flags = uint32(v) } // CopyTo copies all properties from the current struct overriding the destination. @@ -1293,14 +1258,12 @@ func (ms NumberDataPoint) CopyTo(dest NumberDataPoint) { // // Must use NewHistogramDataPointSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type HistogramDataPointSlice internal.HistogramDataPointSlice - -func newHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) HistogramDataPointSlice { - return HistogramDataPointSlice(internal.NewHistogramDataPointSlice(orig)) +type HistogramDataPointSlice struct { + orig *[]*otlpmetrics.HistogramDataPoint } -func (ms HistogramDataPointSlice) getOrig() *[]*otlpmetrics.HistogramDataPoint { - return internal.GetOrigHistogramDataPointSlice(internal.HistogramDataPointSlice(ms)) +func newHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) HistogramDataPointSlice { + return HistogramDataPointSlice{orig} } // NewHistogramDataPointSlice creates a HistogramDataPointSlice with 0 elements. @@ -1314,7 +1277,7 @@ func NewHistogramDataPointSlice() HistogramDataPointSlice { // // Returns "0" for a newly instance created with "NewHistogramDataPointSlice()". func (es HistogramDataPointSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -1326,27 +1289,27 @@ func (es HistogramDataPointSlice) Len() int { // ... // Do something with the element // } func (es HistogramDataPointSlice) At(ix int) HistogramDataPoint { - return newHistogramDataPoint((*es.getOrig())[ix]) + return newHistogramDataPoint((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newHistogramDataPoint((*es.getOrig())[i]).CopyTo(newHistogramDataPoint((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newHistogramDataPoint((*es.orig)[i]).CopyTo(newHistogramDataPoint((*dest.orig)[i])) } return } origs := make([]otlpmetrics.HistogramDataPoint, srcLen) wrappers := make([]*otlpmetrics.HistogramDataPoint, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newHistogramDataPoint((*es.getOrig())[i]).CopyTo(newHistogramDataPoint(wrappers[i])) + newHistogramDataPoint((*es.orig)[i]).CopyTo(newHistogramDataPoint(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -1362,20 +1325,20 @@ func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { // // Here should set all the values for e. // } func (es HistogramDataPointSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.HistogramDataPoint, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.HistogramDataPoint, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty HistogramDataPoint. // It returns the newly added HistogramDataPoint. func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.HistogramDataPoint{}) + *es.orig = append(*es.orig, &otlpmetrics.HistogramDataPoint{}) return es.At(es.Len() - 1) } @@ -1383,26 +1346,26 @@ func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { // provided less function so that two instances of HistogramDataPointSlice // can be compared. func (es HistogramDataPointSlice) Sort(less func(a, b HistogramDataPoint) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es HistogramDataPointSlice) MoveAndAppendTo(dest HistogramDataPointSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es HistogramDataPointSlice) RemoveIf(f func(HistogramDataPoint) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -1411,11 +1374,11 @@ func (es HistogramDataPointSlice) RemoveIf(f func(HistogramDataPoint) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // HistogramDataPoint is a single data point in a timeseries that describes the time-varying values of a Histogram of values. @@ -1425,15 +1388,12 @@ func (es HistogramDataPointSlice) RemoveIf(f func(HistogramDataPoint) bool) { // // Must use NewHistogramDataPoint function to create new instances. // Important: zero-initialized instance is not valid for use. - -type HistogramDataPoint internal.HistogramDataPoint - -func newHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) HistogramDataPoint { - return HistogramDataPoint(internal.NewHistogramDataPoint(orig)) +type HistogramDataPoint struct { + orig *otlpmetrics.HistogramDataPoint } -func (ms HistogramDataPoint) getOrig() *otlpmetrics.HistogramDataPoint { - return internal.GetOrigHistogramDataPoint(internal.HistogramDataPoint(ms)) +func newHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) HistogramDataPoint { + return HistogramDataPoint{orig} } // NewHistogramDataPoint creates a new empty HistogramDataPoint. @@ -1447,131 +1407,131 @@ func NewHistogramDataPoint() HistogramDataPoint { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms HistogramDataPoint) MoveTo(dest HistogramDataPoint) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.HistogramDataPoint{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.HistogramDataPoint{} } // Attributes returns the Attributes associated with this HistogramDataPoint. func (ms HistogramDataPoint) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // StartTimestamp returns the starttimestamp associated with this HistogramDataPoint. func (ms HistogramDataPoint) StartTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) + return pcommon.Timestamp(ms.orig.StartTimeUnixNano) } // SetStartTimestamp replaces the starttimestamp associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) { - ms.getOrig().StartTimeUnixNano = uint64(v) + ms.orig.StartTimeUnixNano = uint64(v) } // Timestamp returns the timestamp associated with this HistogramDataPoint. func (ms HistogramDataPoint) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // Count returns the count associated with this HistogramDataPoint. func (ms HistogramDataPoint) Count() uint64 { - return ms.getOrig().Count + return ms.orig.Count } // SetCount replaces the count associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetCount(v uint64) { - ms.getOrig().Count = v + ms.orig.Count = v } // Sum returns the sum associated with this HistogramDataPoint. func (ms HistogramDataPoint) Sum() float64 { - return ms.getOrig().GetSum() + return ms.orig.GetSum() } // HasSum returns true if the HistogramDataPoint contains a // Sum value, false otherwise. func (ms HistogramDataPoint) HasSum() bool { - return ms.getOrig().Sum_ != nil + return ms.orig.Sum_ != nil } // SetSum replaces the sum associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetSum(v float64) { - ms.getOrig().Sum_ = &otlpmetrics.HistogramDataPoint_Sum{Sum: v} + ms.orig.Sum_ = &otlpmetrics.HistogramDataPoint_Sum{Sum: v} } // RemoveSum removes the sum associated with this HistogramDataPoint. func (ms HistogramDataPoint) RemoveSum() { - ms.getOrig().Sum_ = nil + ms.orig.Sum_ = nil } // BucketCounts returns the bucketcounts associated with this HistogramDataPoint. func (ms HistogramDataPoint) BucketCounts() pcommon.UInt64Slice { - return pcommon.UInt64Slice(internal.NewUInt64Slice(&ms.getOrig().BucketCounts)) + return pcommon.UInt64Slice(internal.NewUInt64Slice(&ms.orig.BucketCounts)) } // ExplicitBounds returns the explicitbounds associated with this HistogramDataPoint. func (ms HistogramDataPoint) ExplicitBounds() pcommon.Float64Slice { - return pcommon.Float64Slice(internal.NewFloat64Slice(&ms.getOrig().ExplicitBounds)) + return pcommon.Float64Slice(internal.NewFloat64Slice(&ms.orig.ExplicitBounds)) } // Exemplars returns the Exemplars associated with this HistogramDataPoint. func (ms HistogramDataPoint) Exemplars() ExemplarSlice { - return ExemplarSlice(internal.NewExemplarSlice(&ms.getOrig().Exemplars)) + return newExemplarSlice(&ms.orig.Exemplars) } // Flags returns the flags associated with this HistogramDataPoint. func (ms HistogramDataPoint) Flags() DataPointFlags { - return DataPointFlags(ms.getOrig().Flags) + return DataPointFlags(ms.orig.Flags) } // SetFlags replaces the flags associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetFlags(v DataPointFlags) { - ms.getOrig().Flags = uint32(v) + ms.orig.Flags = uint32(v) } // Min returns the min associated with this HistogramDataPoint. func (ms HistogramDataPoint) Min() float64 { - return ms.getOrig().GetMin() + return ms.orig.GetMin() } // HasMin returns true if the HistogramDataPoint contains a // Min value, false otherwise. func (ms HistogramDataPoint) HasMin() bool { - return ms.getOrig().Min_ != nil + return ms.orig.Min_ != nil } // SetMin replaces the min associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetMin(v float64) { - ms.getOrig().Min_ = &otlpmetrics.HistogramDataPoint_Min{Min: v} + ms.orig.Min_ = &otlpmetrics.HistogramDataPoint_Min{Min: v} } // RemoveMin removes the min associated with this HistogramDataPoint. func (ms HistogramDataPoint) RemoveMin() { - ms.getOrig().Min_ = nil + ms.orig.Min_ = nil } // Max returns the max associated with this HistogramDataPoint. func (ms HistogramDataPoint) Max() float64 { - return ms.getOrig().GetMax() + return ms.orig.GetMax() } // HasMax returns true if the HistogramDataPoint contains a // Max value, false otherwise. func (ms HistogramDataPoint) HasMax() bool { - return ms.getOrig().Max_ != nil + return ms.orig.Max_ != nil } // SetMax replaces the max associated with this HistogramDataPoint. func (ms HistogramDataPoint) SetMax(v float64) { - ms.getOrig().Max_ = &otlpmetrics.HistogramDataPoint_Max{Max: v} + ms.orig.Max_ = &otlpmetrics.HistogramDataPoint_Max{Max: v} } // RemoveMax removes the max associated with this HistogramDataPoint. func (ms HistogramDataPoint) RemoveMax() { - ms.getOrig().Max_ = nil + ms.orig.Max_ = nil } // CopyTo copies all properties from the current struct overriding the destination. @@ -1605,14 +1565,12 @@ func (ms HistogramDataPoint) CopyTo(dest HistogramDataPoint) { // // Must use NewExponentialHistogramDataPointSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ExponentialHistogramDataPointSlice internal.ExponentialHistogramDataPointSlice - -func newExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPointSlice { - return ExponentialHistogramDataPointSlice(internal.NewExponentialHistogramDataPointSlice(orig)) +type ExponentialHistogramDataPointSlice struct { + orig *[]*otlpmetrics.ExponentialHistogramDataPoint } -func (ms ExponentialHistogramDataPointSlice) getOrig() *[]*otlpmetrics.ExponentialHistogramDataPoint { - return internal.GetOrigExponentialHistogramDataPointSlice(internal.ExponentialHistogramDataPointSlice(ms)) +func newExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPointSlice { + return ExponentialHistogramDataPointSlice{orig} } // NewExponentialHistogramDataPointSlice creates a ExponentialHistogramDataPointSlice with 0 elements. @@ -1626,7 +1584,7 @@ func NewExponentialHistogramDataPointSlice() ExponentialHistogramDataPointSlice // // Returns "0" for a newly instance created with "NewExponentialHistogramDataPointSlice()". func (es ExponentialHistogramDataPointSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -1638,27 +1596,27 @@ func (es ExponentialHistogramDataPointSlice) Len() int { // ... // Do something with the element // } func (es ExponentialHistogramDataPointSlice) At(ix int) ExponentialHistogramDataPoint { - return newExponentialHistogramDataPoint((*es.getOrig())[ix]) + return newExponentialHistogramDataPoint((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDataPointSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newExponentialHistogramDataPoint((*es.getOrig())[i]).CopyTo(newExponentialHistogramDataPoint((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newExponentialHistogramDataPoint((*es.orig)[i]).CopyTo(newExponentialHistogramDataPoint((*dest.orig)[i])) } return } origs := make([]otlpmetrics.ExponentialHistogramDataPoint, srcLen) wrappers := make([]*otlpmetrics.ExponentialHistogramDataPoint, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newExponentialHistogramDataPoint((*es.getOrig())[i]).CopyTo(newExponentialHistogramDataPoint(wrappers[i])) + newExponentialHistogramDataPoint((*es.orig)[i]).CopyTo(newExponentialHistogramDataPoint(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -1674,20 +1632,20 @@ func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDat // // Here should set all the values for e. // } func (es ExponentialHistogramDataPointSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.ExponentialHistogramDataPoint, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.ExponentialHistogramDataPoint, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ExponentialHistogramDataPoint. // It returns the newly added ExponentialHistogramDataPoint. func (es ExponentialHistogramDataPointSlice) AppendEmpty() ExponentialHistogramDataPoint { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.ExponentialHistogramDataPoint{}) + *es.orig = append(*es.orig, &otlpmetrics.ExponentialHistogramDataPoint{}) return es.At(es.Len() - 1) } @@ -1695,26 +1653,26 @@ func (es ExponentialHistogramDataPointSlice) AppendEmpty() ExponentialHistogramD // provided less function so that two instances of ExponentialHistogramDataPointSlice // can be compared. func (es ExponentialHistogramDataPointSlice) Sort(less func(a, b ExponentialHistogramDataPoint) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ExponentialHistogramDataPointSlice) MoveAndAppendTo(dest ExponentialHistogramDataPointSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ExponentialHistogramDataPointSlice) RemoveIf(f func(ExponentialHistogramDataPoint) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -1723,11 +1681,11 @@ func (es ExponentialHistogramDataPointSlice) RemoveIf(f func(ExponentialHistogra newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ExponentialHistogramDataPoint is a single data point in a timeseries that describes the @@ -1740,15 +1698,12 @@ func (es ExponentialHistogramDataPointSlice) RemoveIf(f func(ExponentialHistogra // // Must use NewExponentialHistogramDataPoint function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ExponentialHistogramDataPoint internal.ExponentialHistogramDataPoint - -func newExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPoint { - return ExponentialHistogramDataPoint(internal.NewExponentialHistogramDataPoint(orig)) +type ExponentialHistogramDataPoint struct { + orig *otlpmetrics.ExponentialHistogramDataPoint } -func (ms ExponentialHistogramDataPoint) getOrig() *otlpmetrics.ExponentialHistogramDataPoint { - return internal.GetOrigExponentialHistogramDataPoint(internal.ExponentialHistogramDataPoint(ms)) +func newExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPoint { + return ExponentialHistogramDataPoint{orig} } // NewExponentialHistogramDataPoint creates a new empty ExponentialHistogramDataPoint. @@ -1762,151 +1717,151 @@ func NewExponentialHistogramDataPoint() ExponentialHistogramDataPoint { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ExponentialHistogramDataPoint) MoveTo(dest ExponentialHistogramDataPoint) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.ExponentialHistogramDataPoint{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.ExponentialHistogramDataPoint{} } // Attributes returns the Attributes associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // StartTimestamp returns the starttimestamp associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) StartTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) + return pcommon.Timestamp(ms.orig.StartTimeUnixNano) } // SetStartTimestamp replaces the starttimestamp associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) { - ms.getOrig().StartTimeUnixNano = uint64(v) + ms.orig.StartTimeUnixNano = uint64(v) } // Timestamp returns the timestamp associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // Count returns the count associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Count() uint64 { - return ms.getOrig().Count + return ms.orig.Count } // SetCount replaces the count associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetCount(v uint64) { - ms.getOrig().Count = v + ms.orig.Count = v } // Sum returns the sum associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Sum() float64 { - return ms.getOrig().GetSum() + return ms.orig.GetSum() } // HasSum returns true if the ExponentialHistogramDataPoint contains a // Sum value, false otherwise. func (ms ExponentialHistogramDataPoint) HasSum() bool { - return ms.getOrig().Sum_ != nil + return ms.orig.Sum_ != nil } // SetSum replaces the sum associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetSum(v float64) { - ms.getOrig().Sum_ = &otlpmetrics.ExponentialHistogramDataPoint_Sum{Sum: v} + ms.orig.Sum_ = &otlpmetrics.ExponentialHistogramDataPoint_Sum{Sum: v} } // RemoveSum removes the sum associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) RemoveSum() { - ms.getOrig().Sum_ = nil + ms.orig.Sum_ = nil } // Scale returns the scale associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Scale() int32 { - return ms.getOrig().Scale + return ms.orig.Scale } // SetScale replaces the scale associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetScale(v int32) { - ms.getOrig().Scale = v + ms.orig.Scale = v } // ZeroCount returns the zerocount associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) ZeroCount() uint64 { - return ms.getOrig().ZeroCount + return ms.orig.ZeroCount } // SetZeroCount replaces the zerocount associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetZeroCount(v uint64) { - ms.getOrig().ZeroCount = v + ms.orig.ZeroCount = v } // Positive returns the positive associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Positive() ExponentialHistogramDataPointBuckets { - return ExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(&ms.getOrig().Positive)) + return newExponentialHistogramDataPointBuckets(&ms.orig.Positive) } // Negative returns the negative associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Negative() ExponentialHistogramDataPointBuckets { - return ExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(&ms.getOrig().Negative)) + return newExponentialHistogramDataPointBuckets(&ms.orig.Negative) } // Exemplars returns the Exemplars associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Exemplars() ExemplarSlice { - return ExemplarSlice(internal.NewExemplarSlice(&ms.getOrig().Exemplars)) + return newExemplarSlice(&ms.orig.Exemplars) } // Flags returns the flags associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Flags() DataPointFlags { - return DataPointFlags(ms.getOrig().Flags) + return DataPointFlags(ms.orig.Flags) } // SetFlags replaces the flags associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetFlags(v DataPointFlags) { - ms.getOrig().Flags = uint32(v) + ms.orig.Flags = uint32(v) } // Min returns the min associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Min() float64 { - return ms.getOrig().GetMin() + return ms.orig.GetMin() } // HasMin returns true if the ExponentialHistogramDataPoint contains a // Min value, false otherwise. func (ms ExponentialHistogramDataPoint) HasMin() bool { - return ms.getOrig().Min_ != nil + return ms.orig.Min_ != nil } // SetMin replaces the min associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetMin(v float64) { - ms.getOrig().Min_ = &otlpmetrics.ExponentialHistogramDataPoint_Min{Min: v} + ms.orig.Min_ = &otlpmetrics.ExponentialHistogramDataPoint_Min{Min: v} } // RemoveMin removes the min associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) RemoveMin() { - ms.getOrig().Min_ = nil + ms.orig.Min_ = nil } // Max returns the max associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Max() float64 { - return ms.getOrig().GetMax() + return ms.orig.GetMax() } // HasMax returns true if the ExponentialHistogramDataPoint contains a // Max value, false otherwise. func (ms ExponentialHistogramDataPoint) HasMax() bool { - return ms.getOrig().Max_ != nil + return ms.orig.Max_ != nil } // SetMax replaces the max associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) SetMax(v float64) { - ms.getOrig().Max_ = &otlpmetrics.ExponentialHistogramDataPoint_Max{Max: v} + ms.orig.Max_ = &otlpmetrics.ExponentialHistogramDataPoint_Max{Max: v} } // RemoveMax removes the max associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) RemoveMax() { - ms.getOrig().Max_ = nil + ms.orig.Max_ = nil } // CopyTo copies all properties from the current struct overriding the destination. @@ -1942,15 +1897,12 @@ func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoin // // Must use NewExponentialHistogramDataPointBuckets function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ExponentialHistogramDataPointBuckets internal.ExponentialHistogramDataPointBuckets - -func newExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) ExponentialHistogramDataPointBuckets { - return ExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(orig)) +type ExponentialHistogramDataPointBuckets struct { + orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets } -func (ms ExponentialHistogramDataPointBuckets) getOrig() *otlpmetrics.ExponentialHistogramDataPoint_Buckets { - return internal.GetOrigExponentialHistogramDataPointBuckets(internal.ExponentialHistogramDataPointBuckets(ms)) +func newExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) ExponentialHistogramDataPointBuckets { + return ExponentialHistogramDataPointBuckets{orig} } // NewExponentialHistogramDataPointBuckets creates a new empty ExponentialHistogramDataPointBuckets. @@ -1964,23 +1916,23 @@ func NewExponentialHistogramDataPointBuckets() ExponentialHistogramDataPointBuck // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ExponentialHistogramDataPointBuckets) MoveTo(dest ExponentialHistogramDataPointBuckets) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.ExponentialHistogramDataPoint_Buckets{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.ExponentialHistogramDataPoint_Buckets{} } // Offset returns the offset associated with this ExponentialHistogramDataPointBuckets. func (ms ExponentialHistogramDataPointBuckets) Offset() int32 { - return ms.getOrig().Offset + return ms.orig.Offset } // SetOffset replaces the offset associated with this ExponentialHistogramDataPointBuckets. func (ms ExponentialHistogramDataPointBuckets) SetOffset(v int32) { - ms.getOrig().Offset = v + ms.orig.Offset = v } // BucketCounts returns the bucketcounts associated with this ExponentialHistogramDataPointBuckets. func (ms ExponentialHistogramDataPointBuckets) BucketCounts() pcommon.UInt64Slice { - return pcommon.UInt64Slice(internal.NewUInt64Slice(&ms.getOrig().BucketCounts)) + return pcommon.UInt64Slice(internal.NewUInt64Slice(&ms.orig.BucketCounts)) } // CopyTo copies all properties from the current struct overriding the destination. @@ -1996,14 +1948,12 @@ func (ms ExponentialHistogramDataPointBuckets) CopyTo(dest ExponentialHistogramD // // Must use NewSummaryDataPointSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type SummaryDataPointSlice internal.SummaryDataPointSlice - -func newSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) SummaryDataPointSlice { - return SummaryDataPointSlice(internal.NewSummaryDataPointSlice(orig)) +type SummaryDataPointSlice struct { + orig *[]*otlpmetrics.SummaryDataPoint } -func (ms SummaryDataPointSlice) getOrig() *[]*otlpmetrics.SummaryDataPoint { - return internal.GetOrigSummaryDataPointSlice(internal.SummaryDataPointSlice(ms)) +func newSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) SummaryDataPointSlice { + return SummaryDataPointSlice{orig} } // NewSummaryDataPointSlice creates a SummaryDataPointSlice with 0 elements. @@ -2017,7 +1967,7 @@ func NewSummaryDataPointSlice() SummaryDataPointSlice { // // Returns "0" for a newly instance created with "NewSummaryDataPointSlice()". func (es SummaryDataPointSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -2029,27 +1979,27 @@ func (es SummaryDataPointSlice) Len() int { // ... // Do something with the element // } func (es SummaryDataPointSlice) At(ix int) SummaryDataPoint { - return newSummaryDataPoint((*es.getOrig())[ix]) + return newSummaryDataPoint((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newSummaryDataPoint((*es.getOrig())[i]).CopyTo(newSummaryDataPoint((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newSummaryDataPoint((*es.orig)[i]).CopyTo(newSummaryDataPoint((*dest.orig)[i])) } return } origs := make([]otlpmetrics.SummaryDataPoint, srcLen) wrappers := make([]*otlpmetrics.SummaryDataPoint, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newSummaryDataPoint((*es.getOrig())[i]).CopyTo(newSummaryDataPoint(wrappers[i])) + newSummaryDataPoint((*es.orig)[i]).CopyTo(newSummaryDataPoint(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -2065,20 +2015,20 @@ func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { // // Here should set all the values for e. // } func (es SummaryDataPointSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.SummaryDataPoint, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.SummaryDataPoint, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty SummaryDataPoint. // It returns the newly added SummaryDataPoint. func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.SummaryDataPoint{}) + *es.orig = append(*es.orig, &otlpmetrics.SummaryDataPoint{}) return es.At(es.Len() - 1) } @@ -2086,26 +2036,26 @@ func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { // provided less function so that two instances of SummaryDataPointSlice // can be compared. func (es SummaryDataPointSlice) Sort(less func(a, b SummaryDataPoint) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SummaryDataPointSlice) MoveAndAppendTo(dest SummaryDataPointSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es SummaryDataPointSlice) RemoveIf(f func(SummaryDataPoint) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -2114,11 +2064,11 @@ func (es SummaryDataPointSlice) RemoveIf(f func(SummaryDataPoint) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // SummaryDataPoint is a single data point in a timeseries that describes the time-varying values of a Summary of double values. @@ -2128,15 +2078,12 @@ func (es SummaryDataPointSlice) RemoveIf(f func(SummaryDataPoint) bool) { // // Must use NewSummaryDataPoint function to create new instances. // Important: zero-initialized instance is not valid for use. - -type SummaryDataPoint internal.SummaryDataPoint - -func newSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) SummaryDataPoint { - return SummaryDataPoint(internal.NewSummaryDataPoint(orig)) +type SummaryDataPoint struct { + orig *otlpmetrics.SummaryDataPoint } -func (ms SummaryDataPoint) getOrig() *otlpmetrics.SummaryDataPoint { - return internal.GetOrigSummaryDataPoint(internal.SummaryDataPoint(ms)) +func newSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) SummaryDataPoint { + return SummaryDataPoint{orig} } // NewSummaryDataPoint creates a new empty SummaryDataPoint. @@ -2150,68 +2097,68 @@ func NewSummaryDataPoint() SummaryDataPoint { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms SummaryDataPoint) MoveTo(dest SummaryDataPoint) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.SummaryDataPoint{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.SummaryDataPoint{} } // Attributes returns the Attributes associated with this SummaryDataPoint. func (ms SummaryDataPoint) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // StartTimestamp returns the starttimestamp associated with this SummaryDataPoint. func (ms SummaryDataPoint) StartTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) + return pcommon.Timestamp(ms.orig.StartTimeUnixNano) } // SetStartTimestamp replaces the starttimestamp associated with this SummaryDataPoint. func (ms SummaryDataPoint) SetStartTimestamp(v pcommon.Timestamp) { - ms.getOrig().StartTimeUnixNano = uint64(v) + ms.orig.StartTimeUnixNano = uint64(v) } // Timestamp returns the timestamp associated with this SummaryDataPoint. func (ms SummaryDataPoint) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this SummaryDataPoint. func (ms SummaryDataPoint) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // Count returns the count associated with this SummaryDataPoint. func (ms SummaryDataPoint) Count() uint64 { - return ms.getOrig().Count + return ms.orig.Count } // SetCount replaces the count associated with this SummaryDataPoint. func (ms SummaryDataPoint) SetCount(v uint64) { - ms.getOrig().Count = v + ms.orig.Count = v } // Sum returns the sum associated with this SummaryDataPoint. func (ms SummaryDataPoint) Sum() float64 { - return ms.getOrig().Sum + return ms.orig.Sum } // SetSum replaces the sum associated with this SummaryDataPoint. func (ms SummaryDataPoint) SetSum(v float64) { - ms.getOrig().Sum = v + ms.orig.Sum = v } // QuantileValues returns the QuantileValues associated with this SummaryDataPoint. func (ms SummaryDataPoint) QuantileValues() SummaryDataPointValueAtQuantileSlice { - return SummaryDataPointValueAtQuantileSlice(internal.NewSummaryDataPointValueAtQuantileSlice(&ms.getOrig().QuantileValues)) + return newSummaryDataPointValueAtQuantileSlice(&ms.orig.QuantileValues) } // Flags returns the flags associated with this SummaryDataPoint. func (ms SummaryDataPoint) Flags() DataPointFlags { - return DataPointFlags(ms.getOrig().Flags) + return DataPointFlags(ms.orig.Flags) } // SetFlags replaces the flags associated with this SummaryDataPoint. func (ms SummaryDataPoint) SetFlags(v DataPointFlags) { - ms.getOrig().Flags = uint32(v) + ms.orig.Flags = uint32(v) } // CopyTo copies all properties from the current struct overriding the destination. @@ -2232,14 +2179,12 @@ func (ms SummaryDataPoint) CopyTo(dest SummaryDataPoint) { // // Must use NewSummaryDataPointValueAtQuantileSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type SummaryDataPointValueAtQuantileSlice internal.SummaryDataPointValueAtQuantileSlice - -func newSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantileSlice { - return SummaryDataPointValueAtQuantileSlice(internal.NewSummaryDataPointValueAtQuantileSlice(orig)) +type SummaryDataPointValueAtQuantileSlice struct { + orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile } -func (ms SummaryDataPointValueAtQuantileSlice) getOrig() *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile { - return internal.GetOrigSummaryDataPointValueAtQuantileSlice(internal.SummaryDataPointValueAtQuantileSlice(ms)) +func newSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantileSlice { + return SummaryDataPointValueAtQuantileSlice{orig} } // NewSummaryDataPointValueAtQuantileSlice creates a SummaryDataPointValueAtQuantileSlice with 0 elements. @@ -2253,7 +2198,7 @@ func NewSummaryDataPointValueAtQuantileSlice() SummaryDataPointValueAtQuantileSl // // Returns "0" for a newly instance created with "NewSummaryDataPointValueAtQuantileSlice()". func (es SummaryDataPointValueAtQuantileSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -2265,27 +2210,27 @@ func (es SummaryDataPointValueAtQuantileSlice) Len() int { // ... // Do something with the element // } func (es SummaryDataPointValueAtQuantileSlice) At(ix int) SummaryDataPointValueAtQuantile { - return newSummaryDataPointValueAtQuantile((*es.getOrig())[ix]) + return newSummaryDataPointValueAtQuantile((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es SummaryDataPointValueAtQuantileSlice) CopyTo(dest SummaryDataPointValueAtQuantileSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newSummaryDataPointValueAtQuantile((*es.getOrig())[i]).CopyTo(newSummaryDataPointValueAtQuantile((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newSummaryDataPointValueAtQuantile((*es.orig)[i]).CopyTo(newSummaryDataPointValueAtQuantile((*dest.orig)[i])) } return } origs := make([]otlpmetrics.SummaryDataPoint_ValueAtQuantile, srcLen) wrappers := make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newSummaryDataPointValueAtQuantile((*es.getOrig())[i]).CopyTo(newSummaryDataPointValueAtQuantile(wrappers[i])) + newSummaryDataPointValueAtQuantile((*es.orig)[i]).CopyTo(newSummaryDataPointValueAtQuantile(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -2301,20 +2246,20 @@ func (es SummaryDataPointValueAtQuantileSlice) CopyTo(dest SummaryDataPointValue // // Here should set all the values for e. // } func (es SummaryDataPointValueAtQuantileSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty SummaryDataPointValueAtQuantile. // It returns the newly added SummaryDataPointValueAtQuantile. func (es SummaryDataPointValueAtQuantileSlice) AppendEmpty() SummaryDataPointValueAtQuantile { - *es.getOrig() = append(*es.getOrig(), &otlpmetrics.SummaryDataPoint_ValueAtQuantile{}) + *es.orig = append(*es.orig, &otlpmetrics.SummaryDataPoint_ValueAtQuantile{}) return es.At(es.Len() - 1) } @@ -2322,26 +2267,26 @@ func (es SummaryDataPointValueAtQuantileSlice) AppendEmpty() SummaryDataPointVal // provided less function so that two instances of SummaryDataPointValueAtQuantileSlice // can be compared. func (es SummaryDataPointValueAtQuantileSlice) Sort(less func(a, b SummaryDataPointValueAtQuantile) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SummaryDataPointValueAtQuantileSlice) MoveAndAppendTo(dest SummaryDataPointValueAtQuantileSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es SummaryDataPointValueAtQuantileSlice) RemoveIf(f func(SummaryDataPointValueAtQuantile) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -2350,11 +2295,11 @@ func (es SummaryDataPointValueAtQuantileSlice) RemoveIf(f func(SummaryDataPointV newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // SummaryDataPointValueAtQuantile is a quantile value within a Summary data point. @@ -2364,15 +2309,12 @@ func (es SummaryDataPointValueAtQuantileSlice) RemoveIf(f func(SummaryDataPointV // // Must use NewSummaryDataPointValueAtQuantile function to create new instances. // Important: zero-initialized instance is not valid for use. - -type SummaryDataPointValueAtQuantile internal.SummaryDataPointValueAtQuantile - -func newSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantile { - return SummaryDataPointValueAtQuantile(internal.NewSummaryDataPointValueAtQuantile(orig)) +type SummaryDataPointValueAtQuantile struct { + orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile } -func (ms SummaryDataPointValueAtQuantile) getOrig() *otlpmetrics.SummaryDataPoint_ValueAtQuantile { - return internal.GetOrigSummaryDataPointValueAtQuantile(internal.SummaryDataPointValueAtQuantile(ms)) +func newSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantile { + return SummaryDataPointValueAtQuantile{orig} } // NewSummaryDataPointValueAtQuantile creates a new empty SummaryDataPointValueAtQuantile. @@ -2386,28 +2328,28 @@ func NewSummaryDataPointValueAtQuantile() SummaryDataPointValueAtQuantile { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms SummaryDataPointValueAtQuantile) MoveTo(dest SummaryDataPointValueAtQuantile) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.SummaryDataPoint_ValueAtQuantile{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.SummaryDataPoint_ValueAtQuantile{} } // Quantile returns the quantile associated with this SummaryDataPointValueAtQuantile. func (ms SummaryDataPointValueAtQuantile) Quantile() float64 { - return ms.getOrig().Quantile + return ms.orig.Quantile } // SetQuantile replaces the quantile associated with this SummaryDataPointValueAtQuantile. func (ms SummaryDataPointValueAtQuantile) SetQuantile(v float64) { - ms.getOrig().Quantile = v + ms.orig.Quantile = v } // Value returns the value associated with this SummaryDataPointValueAtQuantile. func (ms SummaryDataPointValueAtQuantile) Value() float64 { - return ms.getOrig().Value + return ms.orig.Value } // SetValue replaces the value associated with this SummaryDataPointValueAtQuantile. func (ms SummaryDataPointValueAtQuantile) SetValue(v float64) { - ms.getOrig().Value = v + ms.orig.Value = v } // CopyTo copies all properties from the current struct overriding the destination. @@ -2423,28 +2365,26 @@ func (ms SummaryDataPointValueAtQuantile) CopyTo(dest SummaryDataPointValueAtQua // // Must use NewExemplarSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ExemplarSlice internal.ExemplarSlice - -func newExemplarSlice(orig *[]otlpmetrics.Exemplar) ExemplarSlice { - return ExemplarSlice(internal.NewExemplarSlice(orig)) +type ExemplarSlice struct { + orig *[]otlpmetrics.Exemplar } -func (ms ExemplarSlice) getOrig() *[]otlpmetrics.Exemplar { - return internal.GetOrigExemplarSlice(internal.ExemplarSlice(ms)) +func newExemplarSlice(orig *[]otlpmetrics.Exemplar) ExemplarSlice { + return ExemplarSlice{orig} } // NewExemplarSlice creates a ExemplarSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. func NewExemplarSlice() ExemplarSlice { orig := []otlpmetrics.Exemplar(nil) - return ExemplarSlice(internal.NewExemplarSlice(&orig)) + return newExemplarSlice(&orig) } // Len returns the number of elements in the slice. // // Returns "0" for a newly instance created with "NewExemplarSlice()". func (es ExemplarSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -2456,21 +2396,21 @@ func (es ExemplarSlice) Len() int { // ... // Do something with the element // } func (es ExemplarSlice) At(ix int) Exemplar { - return newExemplar(&(*es.getOrig())[ix]) + return newExemplar(&(*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] + (*dest.orig) = (*dest.orig)[:srcLen:destCap] } else { - (*dest.getOrig()) = make([]otlpmetrics.Exemplar, srcLen) + (*dest.orig) = make([]otlpmetrics.Exemplar, srcLen) } - for i := range *es.getOrig() { - newExemplar(&(*es.getOrig())[i]).CopyTo(newExemplar(&(*dest.getOrig())[i])) + for i := range *es.orig { + newExemplar(&(*es.orig)[i]).CopyTo(newExemplar(&(*dest.orig)[i])) } } @@ -2487,40 +2427,40 @@ func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { // // Here should set all the values for e. // } func (es ExemplarSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]otlpmetrics.Exemplar, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]otlpmetrics.Exemplar, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty Exemplar. // It returns the newly added Exemplar. func (es ExemplarSlice) AppendEmpty() Exemplar { - *es.getOrig() = append(*es.getOrig(), otlpmetrics.Exemplar{}) + *es.orig = append(*es.orig, otlpmetrics.Exemplar{}) return es.At(es.Len() - 1) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ExemplarSlice) MoveAndAppendTo(dest ExemplarSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ExemplarSlice) RemoveIf(f func(Exemplar) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -2529,11 +2469,11 @@ func (es ExemplarSlice) RemoveIf(f func(Exemplar) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // Exemplar is a sample input double measurement. @@ -2546,15 +2486,12 @@ func (es ExemplarSlice) RemoveIf(f func(Exemplar) bool) { // // Must use NewExemplar function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Exemplar internal.Exemplar - -func newExemplar(orig *otlpmetrics.Exemplar) Exemplar { - return Exemplar(internal.NewExemplar(orig)) +type Exemplar struct { + orig *otlpmetrics.Exemplar } -func (ms Exemplar) getOrig() *otlpmetrics.Exemplar { - return internal.GetOrigExemplar(internal.Exemplar(ms)) +func newExemplar(orig *otlpmetrics.Exemplar) Exemplar { + return Exemplar{orig} } // NewExemplar creates a new empty Exemplar. @@ -2568,24 +2505,24 @@ func NewExemplar() Exemplar { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Exemplar) MoveTo(dest Exemplar) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpmetrics.Exemplar{} + *dest.orig = *ms.orig + *ms.orig = otlpmetrics.Exemplar{} } // Timestamp returns the timestamp associated with this Exemplar. func (ms Exemplar) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this Exemplar. func (ms Exemplar) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // ValueType returns the type of the value for this Exemplar. // Calling this function on zero-initialized Exemplar will cause a panic. func (ms Exemplar) ValueType() ExemplarValueType { - switch ms.getOrig().Value.(type) { + switch ms.orig.Value.(type) { case *otlpmetrics.Exemplar_AsDouble: return ExemplarValueTypeDouble case *otlpmetrics.Exemplar_AsInt: @@ -2596,51 +2533,51 @@ func (ms Exemplar) ValueType() ExemplarValueType { // DoubleValue returns the double associated with this Exemplar. func (ms Exemplar) DoubleValue() float64 { - return ms.getOrig().GetAsDouble() + return ms.orig.GetAsDouble() } // SetDoubleValue replaces the double associated with this Exemplar. func (ms Exemplar) SetDoubleValue(v float64) { - ms.getOrig().Value = &otlpmetrics.Exemplar_AsDouble{ + ms.orig.Value = &otlpmetrics.Exemplar_AsDouble{ AsDouble: v, } } // IntValue returns the int associated with this Exemplar. func (ms Exemplar) IntValue() int64 { - return ms.getOrig().GetAsInt() + return ms.orig.GetAsInt() } // SetIntValue replaces the int associated with this Exemplar. func (ms Exemplar) SetIntValue(v int64) { - ms.getOrig().Value = &otlpmetrics.Exemplar_AsInt{ + ms.orig.Value = &otlpmetrics.Exemplar_AsInt{ AsInt: v, } } // FilteredAttributes returns the FilteredAttributes associated with this Exemplar. func (ms Exemplar) FilteredAttributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().FilteredAttributes)) + return pcommon.Map(internal.NewMap(&ms.orig.FilteredAttributes)) } // TraceID returns the traceid associated with this Exemplar. func (ms Exemplar) TraceID() pcommon.TraceID { - return pcommon.TraceID(ms.getOrig().TraceId) + return pcommon.TraceID(ms.orig.TraceId) } // SetTraceID replaces the traceid associated with this Exemplar. func (ms Exemplar) SetTraceID(v pcommon.TraceID) { - ms.getOrig().TraceId = data.TraceID(v) + ms.orig.TraceId = data.TraceID(v) } // SpanID returns the spanid associated with this Exemplar. func (ms Exemplar) SpanID() pcommon.SpanID { - return pcommon.SpanID(ms.getOrig().SpanId) + return pcommon.SpanID(ms.orig.SpanId) } // SetSpanID replaces the spanid associated with this Exemplar. func (ms Exemplar) SetSpanID(v pcommon.SpanID) { - ms.getOrig().SpanId = data.SpanID(v) + ms.orig.SpanId = data.SpanID(v) } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/pmetric/generated_metrics_test.go b/pdata/pmetric/generated_metrics_test.go index 8a27d5d2a79..a06517a29d4 100644 --- a/pdata/pmetric/generated_metrics_test.go +++ b/pdata/pmetric/generated_metrics_test.go @@ -36,12 +36,12 @@ func TestResourceMetricsSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newResourceMetrics(&otlpmetrics.ResourceMetrics{}) - testVal := ResourceMetrics(internal.GenerateTestResourceMetrics()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestResourceMetrics() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestResourceMetrics(internal.ResourceMetrics(el)) + fillTestResourceMetrics(el) assert.Equal(t, testVal, el) } } @@ -53,28 +53,28 @@ func TestResourceMetricsSlice_CopyTo(t *testing.T) { assert.Equal(t, NewResourceMetricsSlice(), dest) // Test CopyTo larger slice - ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()).CopyTo(dest) - assert.Equal(t, ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()), dest) + generateTestResourceMetricsSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceMetricsSlice(), dest) // Test CopyTo same size slice - ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()).CopyTo(dest) - assert.Equal(t, ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()), dest) + generateTestResourceMetricsSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceMetricsSlice(), dest) } func TestResourceMetricsSlice_EnsureCapacity(t *testing.T) { - es := ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()) + es := generateTestResourceMetricsSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.ResourceMetrics]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.ResourceMetrics]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -83,36 +83,36 @@ func TestResourceMetricsSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.ResourceMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.ResourceMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestResourceMetricsSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()) + expectedSlice := generateTestResourceMetricsSlice() dest := NewResourceMetricsSlice() - src := ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()) + src := generateTestResourceMetricsSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()), dest) + assert.Equal(t, generateTestResourceMetricsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()), dest) + assert.Equal(t, generateTestResourceMetricsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()).MoveAndAppendTo(dest) + generateTestResourceMetricsSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -129,7 +129,7 @@ func TestResourceMetricsSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()) + filtered := generateTestResourceMetricsSlice() pos := 0 filtered.RemoveIf(func(el ResourceMetrics) bool { pos++ @@ -138,12 +138,26 @@ func TestResourceMetricsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestResourceMetricsSlice() ResourceMetricsSlice { + tv := NewResourceMetricsSlice() + fillTestResourceMetricsSlice(tv) + return tv +} + +func fillTestResourceMetricsSlice(tv ResourceMetricsSlice) { + *tv.orig = make([]*otlpmetrics.ResourceMetrics, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.ResourceMetrics{} + fillTestResourceMetrics(newResourceMetrics((*tv.orig)[i])) + } +} + func TestResourceMetrics_MoveTo(t *testing.T) { - ms := ResourceMetrics(internal.GenerateTestResourceMetrics()) + ms := generateTestResourceMetrics() dest := NewResourceMetrics() ms.MoveTo(dest) assert.Equal(t, NewResourceMetrics(), ms) - assert.Equal(t, ResourceMetrics(internal.GenerateTestResourceMetrics()), dest) + assert.Equal(t, generateTestResourceMetrics(), dest) } func TestResourceMetrics_CopyTo(t *testing.T) { @@ -151,7 +165,7 @@ func TestResourceMetrics_CopyTo(t *testing.T) { orig := NewResourceMetrics() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ResourceMetrics(internal.GenerateTestResourceMetrics()) + orig = generateTestResourceMetrics() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -172,8 +186,20 @@ func TestResourceMetrics_SchemaUrl(t *testing.T) { func TestResourceMetrics_ScopeMetrics(t *testing.T) { ms := NewResourceMetrics() assert.Equal(t, NewScopeMetricsSlice(), ms.ScopeMetrics()) - internal.FillTestScopeMetricsSlice(internal.ScopeMetricsSlice(ms.ScopeMetrics())) - assert.Equal(t, ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()), ms.ScopeMetrics()) + fillTestScopeMetricsSlice(ms.ScopeMetrics()) + assert.Equal(t, generateTestScopeMetricsSlice(), ms.ScopeMetrics()) +} + +func generateTestResourceMetrics() ResourceMetrics { + tv := NewResourceMetrics() + fillTestResourceMetrics(tv) + return tv +} + +func fillTestResourceMetrics(tv ResourceMetrics) { + internal.FillTestResource(internal.NewResource(&tv.orig.Resource)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestScopeMetricsSlice(newScopeMetricsSlice(&tv.orig.ScopeMetrics)) } func TestScopeMetricsSlice(t *testing.T) { @@ -184,12 +210,12 @@ func TestScopeMetricsSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newScopeMetrics(&otlpmetrics.ScopeMetrics{}) - testVal := ScopeMetrics(internal.GenerateTestScopeMetrics()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestScopeMetrics() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestScopeMetrics(internal.ScopeMetrics(el)) + fillTestScopeMetrics(el) assert.Equal(t, testVal, el) } } @@ -201,28 +227,28 @@ func TestScopeMetricsSlice_CopyTo(t *testing.T) { assert.Equal(t, NewScopeMetricsSlice(), dest) // Test CopyTo larger slice - ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()).CopyTo(dest) - assert.Equal(t, ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()), dest) + generateTestScopeMetricsSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeMetricsSlice(), dest) // Test CopyTo same size slice - ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()).CopyTo(dest) - assert.Equal(t, ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()), dest) + generateTestScopeMetricsSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeMetricsSlice(), dest) } func TestScopeMetricsSlice_EnsureCapacity(t *testing.T) { - es := ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()) + es := generateTestScopeMetricsSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.ScopeMetrics]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.ScopeMetrics]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -231,36 +257,36 @@ func TestScopeMetricsSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.ScopeMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.ScopeMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestScopeMetricsSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()) + expectedSlice := generateTestScopeMetricsSlice() dest := NewScopeMetricsSlice() - src := ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()) + src := generateTestScopeMetricsSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()), dest) + assert.Equal(t, generateTestScopeMetricsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()), dest) + assert.Equal(t, generateTestScopeMetricsSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()).MoveAndAppendTo(dest) + generateTestScopeMetricsSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -277,7 +303,7 @@ func TestScopeMetricsSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ScopeMetricsSlice(internal.GenerateTestScopeMetricsSlice()) + filtered := generateTestScopeMetricsSlice() pos := 0 filtered.RemoveIf(func(el ScopeMetrics) bool { pos++ @@ -286,12 +312,26 @@ func TestScopeMetricsSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestScopeMetricsSlice() ScopeMetricsSlice { + tv := NewScopeMetricsSlice() + fillTestScopeMetricsSlice(tv) + return tv +} + +func fillTestScopeMetricsSlice(tv ScopeMetricsSlice) { + *tv.orig = make([]*otlpmetrics.ScopeMetrics, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.ScopeMetrics{} + fillTestScopeMetrics(newScopeMetrics((*tv.orig)[i])) + } +} + func TestScopeMetrics_MoveTo(t *testing.T) { - ms := ScopeMetrics(internal.GenerateTestScopeMetrics()) + ms := generateTestScopeMetrics() dest := NewScopeMetrics() ms.MoveTo(dest) assert.Equal(t, NewScopeMetrics(), ms) - assert.Equal(t, ScopeMetrics(internal.GenerateTestScopeMetrics()), dest) + assert.Equal(t, generateTestScopeMetrics(), dest) } func TestScopeMetrics_CopyTo(t *testing.T) { @@ -299,7 +339,7 @@ func TestScopeMetrics_CopyTo(t *testing.T) { orig := NewScopeMetrics() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ScopeMetrics(internal.GenerateTestScopeMetrics()) + orig = generateTestScopeMetrics() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -320,8 +360,20 @@ func TestScopeMetrics_SchemaUrl(t *testing.T) { func TestScopeMetrics_Metrics(t *testing.T) { ms := NewScopeMetrics() assert.Equal(t, NewMetricSlice(), ms.Metrics()) - internal.FillTestMetricSlice(internal.MetricSlice(ms.Metrics())) - assert.Equal(t, MetricSlice(internal.GenerateTestMetricSlice()), ms.Metrics()) + fillTestMetricSlice(ms.Metrics()) + assert.Equal(t, generateTestMetricSlice(), ms.Metrics()) +} + +func generateTestScopeMetrics() ScopeMetrics { + tv := NewScopeMetrics() + fillTestScopeMetrics(tv) + return tv +} + +func fillTestScopeMetrics(tv ScopeMetrics) { + internal.FillTestInstrumentationScope(internal.NewInstrumentationScope(&tv.orig.Scope)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestMetricSlice(newMetricSlice(&tv.orig.Metrics)) } func TestMetricSlice(t *testing.T) { @@ -332,12 +384,12 @@ func TestMetricSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newMetric(&otlpmetrics.Metric{}) - testVal := Metric(internal.GenerateTestMetric()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestMetric() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestMetric(internal.Metric(el)) + fillTestMetric(el) assert.Equal(t, testVal, el) } } @@ -349,28 +401,28 @@ func TestMetricSlice_CopyTo(t *testing.T) { assert.Equal(t, NewMetricSlice(), dest) // Test CopyTo larger slice - MetricSlice(internal.GenerateTestMetricSlice()).CopyTo(dest) - assert.Equal(t, MetricSlice(internal.GenerateTestMetricSlice()), dest) + generateTestMetricSlice().CopyTo(dest) + assert.Equal(t, generateTestMetricSlice(), dest) // Test CopyTo same size slice - MetricSlice(internal.GenerateTestMetricSlice()).CopyTo(dest) - assert.Equal(t, MetricSlice(internal.GenerateTestMetricSlice()), dest) + generateTestMetricSlice().CopyTo(dest) + assert.Equal(t, generateTestMetricSlice(), dest) } func TestMetricSlice_EnsureCapacity(t *testing.T) { - es := MetricSlice(internal.GenerateTestMetricSlice()) + es := generateTestMetricSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.Metric]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.Metric]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -379,36 +431,36 @@ func TestMetricSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.Metric]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.Metric]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestMetricSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := MetricSlice(internal.GenerateTestMetricSlice()) + expectedSlice := generateTestMetricSlice() dest := NewMetricSlice() - src := MetricSlice(internal.GenerateTestMetricSlice()) + src := generateTestMetricSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, MetricSlice(internal.GenerateTestMetricSlice()), dest) + assert.Equal(t, generateTestMetricSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, MetricSlice(internal.GenerateTestMetricSlice()), dest) + assert.Equal(t, generateTestMetricSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - MetricSlice(internal.GenerateTestMetricSlice()).MoveAndAppendTo(dest) + generateTestMetricSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -425,7 +477,7 @@ func TestMetricSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := MetricSlice(internal.GenerateTestMetricSlice()) + filtered := generateTestMetricSlice() pos := 0 filtered.RemoveIf(func(el Metric) bool { pos++ @@ -434,12 +486,26 @@ func TestMetricSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestMetricSlice() MetricSlice { + tv := NewMetricSlice() + fillTestMetricSlice(tv) + return tv +} + +func fillTestMetricSlice(tv MetricSlice) { + *tv.orig = make([]*otlpmetrics.Metric, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.Metric{} + fillTestMetric(newMetric((*tv.orig)[i])) + } +} + func TestMetric_MoveTo(t *testing.T) { - ms := Metric(internal.GenerateTestMetric()) + ms := generateTestMetric() dest := NewMetric() ms.MoveTo(dest) assert.Equal(t, NewMetric(), ms) - assert.Equal(t, Metric(internal.GenerateTestMetric()), dest) + assert.Equal(t, generateTestMetric(), dest) } func TestMetric_CopyTo(t *testing.T) { @@ -447,7 +513,7 @@ func TestMetric_CopyTo(t *testing.T) { orig := NewMetric() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Metric(internal.GenerateTestMetric()) + orig = generateTestMetric() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -480,14 +546,14 @@ func TestMetric_Type(t *testing.T) { func TestMetric_Gauge(t *testing.T) { ms := NewMetric() - internal.FillTestGauge(internal.Gauge(ms.SetEmptyGauge())) + fillTestGauge(ms.SetEmptyGauge()) assert.Equal(t, MetricTypeGauge, ms.Type()) - assert.Equal(t, Gauge(internal.GenerateTestGauge()), ms.Gauge()) + assert.Equal(t, generateTestGauge(), ms.Gauge()) } func TestMetric_CopyTo_Gauge(t *testing.T) { ms := NewMetric() - internal.FillTestGauge(internal.Gauge(ms.SetEmptyGauge())) + fillTestGauge(ms.SetEmptyGauge()) dest := NewMetric() ms.CopyTo(dest) assert.Equal(t, ms, dest) @@ -495,14 +561,14 @@ func TestMetric_CopyTo_Gauge(t *testing.T) { func TestMetric_Sum(t *testing.T) { ms := NewMetric() - internal.FillTestSum(internal.Sum(ms.SetEmptySum())) + fillTestSum(ms.SetEmptySum()) assert.Equal(t, MetricTypeSum, ms.Type()) - assert.Equal(t, Sum(internal.GenerateTestSum()), ms.Sum()) + assert.Equal(t, generateTestSum(), ms.Sum()) } func TestMetric_CopyTo_Sum(t *testing.T) { ms := NewMetric() - internal.FillTestSum(internal.Sum(ms.SetEmptySum())) + fillTestSum(ms.SetEmptySum()) dest := NewMetric() ms.CopyTo(dest) assert.Equal(t, ms, dest) @@ -510,14 +576,14 @@ func TestMetric_CopyTo_Sum(t *testing.T) { func TestMetric_Histogram(t *testing.T) { ms := NewMetric() - internal.FillTestHistogram(internal.Histogram(ms.SetEmptyHistogram())) + fillTestHistogram(ms.SetEmptyHistogram()) assert.Equal(t, MetricTypeHistogram, ms.Type()) - assert.Equal(t, Histogram(internal.GenerateTestHistogram()), ms.Histogram()) + assert.Equal(t, generateTestHistogram(), ms.Histogram()) } func TestMetric_CopyTo_Histogram(t *testing.T) { ms := NewMetric() - internal.FillTestHistogram(internal.Histogram(ms.SetEmptyHistogram())) + fillTestHistogram(ms.SetEmptyHistogram()) dest := NewMetric() ms.CopyTo(dest) assert.Equal(t, ms, dest) @@ -525,14 +591,14 @@ func TestMetric_CopyTo_Histogram(t *testing.T) { func TestMetric_ExponentialHistogram(t *testing.T) { ms := NewMetric() - internal.FillTestExponentialHistogram(internal.ExponentialHistogram(ms.SetEmptyExponentialHistogram())) + fillTestExponentialHistogram(ms.SetEmptyExponentialHistogram()) assert.Equal(t, MetricTypeExponentialHistogram, ms.Type()) - assert.Equal(t, ExponentialHistogram(internal.GenerateTestExponentialHistogram()), ms.ExponentialHistogram()) + assert.Equal(t, generateTestExponentialHistogram(), ms.ExponentialHistogram()) } func TestMetric_CopyTo_ExponentialHistogram(t *testing.T) { ms := NewMetric() - internal.FillTestExponentialHistogram(internal.ExponentialHistogram(ms.SetEmptyExponentialHistogram())) + fillTestExponentialHistogram(ms.SetEmptyExponentialHistogram()) dest := NewMetric() ms.CopyTo(dest) assert.Equal(t, ms, dest) @@ -540,25 +606,39 @@ func TestMetric_CopyTo_ExponentialHistogram(t *testing.T) { func TestMetric_Summary(t *testing.T) { ms := NewMetric() - internal.FillTestSummary(internal.Summary(ms.SetEmptySummary())) + fillTestSummary(ms.SetEmptySummary()) assert.Equal(t, MetricTypeSummary, ms.Type()) - assert.Equal(t, Summary(internal.GenerateTestSummary()), ms.Summary()) + assert.Equal(t, generateTestSummary(), ms.Summary()) } func TestMetric_CopyTo_Summary(t *testing.T) { ms := NewMetric() - internal.FillTestSummary(internal.Summary(ms.SetEmptySummary())) + fillTestSummary(ms.SetEmptySummary()) dest := NewMetric() ms.CopyTo(dest) assert.Equal(t, ms, dest) } +func generateTestMetric() Metric { + tv := NewMetric() + fillTestMetric(tv) + return tv +} + +func fillTestMetric(tv Metric) { + tv.orig.Name = "test_name" + tv.orig.Description = "test_description" + tv.orig.Unit = "1" + tv.orig.Data = &otlpmetrics.Metric_Sum{Sum: &otlpmetrics.Sum{}} + fillTestSum(newSum(tv.orig.GetSum())) +} + func TestGauge_MoveTo(t *testing.T) { - ms := Gauge(internal.GenerateTestGauge()) + ms := generateTestGauge() dest := NewGauge() ms.MoveTo(dest) assert.Equal(t, NewGauge(), ms) - assert.Equal(t, Gauge(internal.GenerateTestGauge()), dest) + assert.Equal(t, generateTestGauge(), dest) } func TestGauge_CopyTo(t *testing.T) { @@ -566,7 +646,7 @@ func TestGauge_CopyTo(t *testing.T) { orig := NewGauge() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Gauge(internal.GenerateTestGauge()) + orig = generateTestGauge() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -574,16 +654,26 @@ func TestGauge_CopyTo(t *testing.T) { func TestGauge_DataPoints(t *testing.T) { ms := NewGauge() assert.Equal(t, NewNumberDataPointSlice(), ms.DataPoints()) - internal.FillTestNumberDataPointSlice(internal.NumberDataPointSlice(ms.DataPoints())) - assert.Equal(t, NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()), ms.DataPoints()) + fillTestNumberDataPointSlice(ms.DataPoints()) + assert.Equal(t, generateTestNumberDataPointSlice(), ms.DataPoints()) +} + +func generateTestGauge() Gauge { + tv := NewGauge() + fillTestGauge(tv) + return tv +} + +func fillTestGauge(tv Gauge) { + fillTestNumberDataPointSlice(newNumberDataPointSlice(&tv.orig.DataPoints)) } func TestSum_MoveTo(t *testing.T) { - ms := Sum(internal.GenerateTestSum()) + ms := generateTestSum() dest := NewSum() ms.MoveTo(dest) assert.Equal(t, NewSum(), ms) - assert.Equal(t, Sum(internal.GenerateTestSum()), dest) + assert.Equal(t, generateTestSum(), dest) } func TestSum_CopyTo(t *testing.T) { @@ -591,7 +681,7 @@ func TestSum_CopyTo(t *testing.T) { orig := NewSum() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Sum(internal.GenerateTestSum()) + orig = generateTestSum() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -614,16 +704,28 @@ func TestSum_IsMonotonic(t *testing.T) { func TestSum_DataPoints(t *testing.T) { ms := NewSum() assert.Equal(t, NewNumberDataPointSlice(), ms.DataPoints()) - internal.FillTestNumberDataPointSlice(internal.NumberDataPointSlice(ms.DataPoints())) - assert.Equal(t, NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()), ms.DataPoints()) + fillTestNumberDataPointSlice(ms.DataPoints()) + assert.Equal(t, generateTestNumberDataPointSlice(), ms.DataPoints()) +} + +func generateTestSum() Sum { + tv := NewSum() + fillTestSum(tv) + return tv +} + +func fillTestSum(tv Sum) { + tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) + tv.orig.IsMonotonic = true + fillTestNumberDataPointSlice(newNumberDataPointSlice(&tv.orig.DataPoints)) } func TestHistogram_MoveTo(t *testing.T) { - ms := Histogram(internal.GenerateTestHistogram()) + ms := generateTestHistogram() dest := NewHistogram() ms.MoveTo(dest) assert.Equal(t, NewHistogram(), ms) - assert.Equal(t, Histogram(internal.GenerateTestHistogram()), dest) + assert.Equal(t, generateTestHistogram(), dest) } func TestHistogram_CopyTo(t *testing.T) { @@ -631,7 +733,7 @@ func TestHistogram_CopyTo(t *testing.T) { orig := NewHistogram() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Histogram(internal.GenerateTestHistogram()) + orig = generateTestHistogram() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -647,16 +749,27 @@ func TestHistogram_AggregationTemporality(t *testing.T) { func TestHistogram_DataPoints(t *testing.T) { ms := NewHistogram() assert.Equal(t, NewHistogramDataPointSlice(), ms.DataPoints()) - internal.FillTestHistogramDataPointSlice(internal.HistogramDataPointSlice(ms.DataPoints())) - assert.Equal(t, HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()), ms.DataPoints()) + fillTestHistogramDataPointSlice(ms.DataPoints()) + assert.Equal(t, generateTestHistogramDataPointSlice(), ms.DataPoints()) +} + +func generateTestHistogram() Histogram { + tv := NewHistogram() + fillTestHistogram(tv) + return tv +} + +func fillTestHistogram(tv Histogram) { + tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) + fillTestHistogramDataPointSlice(newHistogramDataPointSlice(&tv.orig.DataPoints)) } func TestExponentialHistogram_MoveTo(t *testing.T) { - ms := ExponentialHistogram(internal.GenerateTestExponentialHistogram()) + ms := generateTestExponentialHistogram() dest := NewExponentialHistogram() ms.MoveTo(dest) assert.Equal(t, NewExponentialHistogram(), ms) - assert.Equal(t, ExponentialHistogram(internal.GenerateTestExponentialHistogram()), dest) + assert.Equal(t, generateTestExponentialHistogram(), dest) } func TestExponentialHistogram_CopyTo(t *testing.T) { @@ -664,7 +777,7 @@ func TestExponentialHistogram_CopyTo(t *testing.T) { orig := NewExponentialHistogram() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExponentialHistogram(internal.GenerateTestExponentialHistogram()) + orig = generateTestExponentialHistogram() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -680,16 +793,27 @@ func TestExponentialHistogram_AggregationTemporality(t *testing.T) { func TestExponentialHistogram_DataPoints(t *testing.T) { ms := NewExponentialHistogram() assert.Equal(t, NewExponentialHistogramDataPointSlice(), ms.DataPoints()) - internal.FillTestExponentialHistogramDataPointSlice(internal.ExponentialHistogramDataPointSlice(ms.DataPoints())) - assert.Equal(t, ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()), ms.DataPoints()) + fillTestExponentialHistogramDataPointSlice(ms.DataPoints()) + assert.Equal(t, generateTestExponentialHistogramDataPointSlice(), ms.DataPoints()) +} + +func generateTestExponentialHistogram() ExponentialHistogram { + tv := NewExponentialHistogram() + fillTestExponentialHistogram(tv) + return tv +} + +func fillTestExponentialHistogram(tv ExponentialHistogram) { + tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) + fillTestExponentialHistogramDataPointSlice(newExponentialHistogramDataPointSlice(&tv.orig.DataPoints)) } func TestSummary_MoveTo(t *testing.T) { - ms := Summary(internal.GenerateTestSummary()) + ms := generateTestSummary() dest := NewSummary() ms.MoveTo(dest) assert.Equal(t, NewSummary(), ms) - assert.Equal(t, Summary(internal.GenerateTestSummary()), dest) + assert.Equal(t, generateTestSummary(), dest) } func TestSummary_CopyTo(t *testing.T) { @@ -697,7 +821,7 @@ func TestSummary_CopyTo(t *testing.T) { orig := NewSummary() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Summary(internal.GenerateTestSummary()) + orig = generateTestSummary() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -705,8 +829,18 @@ func TestSummary_CopyTo(t *testing.T) { func TestSummary_DataPoints(t *testing.T) { ms := NewSummary() assert.Equal(t, NewSummaryDataPointSlice(), ms.DataPoints()) - internal.FillTestSummaryDataPointSlice(internal.SummaryDataPointSlice(ms.DataPoints())) - assert.Equal(t, SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()), ms.DataPoints()) + fillTestSummaryDataPointSlice(ms.DataPoints()) + assert.Equal(t, generateTestSummaryDataPointSlice(), ms.DataPoints()) +} + +func generateTestSummary() Summary { + tv := NewSummary() + fillTestSummary(tv) + return tv +} + +func fillTestSummary(tv Summary) { + fillTestSummaryDataPointSlice(newSummaryDataPointSlice(&tv.orig.DataPoints)) } func TestNumberDataPointSlice(t *testing.T) { @@ -717,12 +851,12 @@ func TestNumberDataPointSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newNumberDataPoint(&otlpmetrics.NumberDataPoint{}) - testVal := NumberDataPoint(internal.GenerateTestNumberDataPoint()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestNumberDataPoint() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestNumberDataPoint(internal.NumberDataPoint(el)) + fillTestNumberDataPoint(el) assert.Equal(t, testVal, el) } } @@ -734,28 +868,28 @@ func TestNumberDataPointSlice_CopyTo(t *testing.T) { assert.Equal(t, NewNumberDataPointSlice(), dest) // Test CopyTo larger slice - NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()).CopyTo(dest) - assert.Equal(t, NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()), dest) + generateTestNumberDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestNumberDataPointSlice(), dest) // Test CopyTo same size slice - NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()).CopyTo(dest) - assert.Equal(t, NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()), dest) + generateTestNumberDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestNumberDataPointSlice(), dest) } func TestNumberDataPointSlice_EnsureCapacity(t *testing.T) { - es := NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()) + es := generateTestNumberDataPointSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.NumberDataPoint]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.NumberDataPoint]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -764,36 +898,36 @@ func TestNumberDataPointSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.NumberDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.NumberDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestNumberDataPointSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()) + expectedSlice := generateTestNumberDataPointSlice() dest := NewNumberDataPointSlice() - src := NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()) + src := generateTestNumberDataPointSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()), dest) + assert.Equal(t, generateTestNumberDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()), dest) + assert.Equal(t, generateTestNumberDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()).MoveAndAppendTo(dest) + generateTestNumberDataPointSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -810,7 +944,7 @@ func TestNumberDataPointSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := NumberDataPointSlice(internal.GenerateTestNumberDataPointSlice()) + filtered := generateTestNumberDataPointSlice() pos := 0 filtered.RemoveIf(func(el NumberDataPoint) bool { pos++ @@ -819,12 +953,26 @@ func TestNumberDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestNumberDataPointSlice() NumberDataPointSlice { + tv := NewNumberDataPointSlice() + fillTestNumberDataPointSlice(tv) + return tv +} + +func fillTestNumberDataPointSlice(tv NumberDataPointSlice) { + *tv.orig = make([]*otlpmetrics.NumberDataPoint, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.NumberDataPoint{} + fillTestNumberDataPoint(newNumberDataPoint((*tv.orig)[i])) + } +} + func TestNumberDataPoint_MoveTo(t *testing.T) { - ms := NumberDataPoint(internal.GenerateTestNumberDataPoint()) + ms := generateTestNumberDataPoint() dest := NewNumberDataPoint() ms.MoveTo(dest) assert.Equal(t, NewNumberDataPoint(), ms) - assert.Equal(t, NumberDataPoint(internal.GenerateTestNumberDataPoint()), dest) + assert.Equal(t, generateTestNumberDataPoint(), dest) } func TestNumberDataPoint_CopyTo(t *testing.T) { @@ -832,7 +980,7 @@ func TestNumberDataPoint_CopyTo(t *testing.T) { orig := NewNumberDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = NumberDataPoint(internal.GenerateTestNumberDataPoint()) + orig = generateTestNumberDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -884,8 +1032,8 @@ func TestNumberDataPoint_IntValue(t *testing.T) { func TestNumberDataPoint_Exemplars(t *testing.T) { ms := NewNumberDataPoint() assert.Equal(t, NewExemplarSlice(), ms.Exemplars()) - internal.FillTestExemplarSlice(internal.ExemplarSlice(ms.Exemplars())) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), ms.Exemplars()) + fillTestExemplarSlice(ms.Exemplars()) + assert.Equal(t, generateTestExemplarSlice(), ms.Exemplars()) } func TestNumberDataPoint_Flags(t *testing.T) { @@ -896,6 +1044,21 @@ func TestNumberDataPoint_Flags(t *testing.T) { assert.Equal(t, testValFlags, ms.Flags()) } +func generateTestNumberDataPoint() NumberDataPoint { + tv := NewNumberDataPoint() + fillTestNumberDataPoint(tv) + return tv +} + +func fillTestNumberDataPoint(tv NumberDataPoint) { + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.StartTimeUnixNano = 1234567890 + tv.orig.TimeUnixNano = 1234567890 + tv.orig.Value = &otlpmetrics.NumberDataPoint_AsDouble{AsDouble: float64(17.13)} + fillTestExemplarSlice(newExemplarSlice(&tv.orig.Exemplars)) + tv.orig.Flags = 1 +} + func TestHistogramDataPointSlice(t *testing.T) { es := NewHistogramDataPointSlice() assert.Equal(t, 0, es.Len()) @@ -904,12 +1067,12 @@ func TestHistogramDataPointSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newHistogramDataPoint(&otlpmetrics.HistogramDataPoint{}) - testVal := HistogramDataPoint(internal.GenerateTestHistogramDataPoint()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestHistogramDataPoint() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestHistogramDataPoint(internal.HistogramDataPoint(el)) + fillTestHistogramDataPoint(el) assert.Equal(t, testVal, el) } } @@ -921,28 +1084,28 @@ func TestHistogramDataPointSlice_CopyTo(t *testing.T) { assert.Equal(t, NewHistogramDataPointSlice(), dest) // Test CopyTo larger slice - HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()).CopyTo(dest) - assert.Equal(t, HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()), dest) + generateTestHistogramDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestHistogramDataPointSlice(), dest) // Test CopyTo same size slice - HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()).CopyTo(dest) - assert.Equal(t, HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()), dest) + generateTestHistogramDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestHistogramDataPointSlice(), dest) } func TestHistogramDataPointSlice_EnsureCapacity(t *testing.T) { - es := HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()) + es := generateTestHistogramDataPointSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.HistogramDataPoint]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.HistogramDataPoint]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -951,36 +1114,36 @@ func TestHistogramDataPointSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.HistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.HistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestHistogramDataPointSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()) + expectedSlice := generateTestHistogramDataPointSlice() dest := NewHistogramDataPointSlice() - src := HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()) + src := generateTestHistogramDataPointSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()), dest) + assert.Equal(t, generateTestHistogramDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()), dest) + assert.Equal(t, generateTestHistogramDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()).MoveAndAppendTo(dest) + generateTestHistogramDataPointSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -997,7 +1160,7 @@ func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := HistogramDataPointSlice(internal.GenerateTestHistogramDataPointSlice()) + filtered := generateTestHistogramDataPointSlice() pos := 0 filtered.RemoveIf(func(el HistogramDataPoint) bool { pos++ @@ -1006,12 +1169,26 @@ func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestHistogramDataPointSlice() HistogramDataPointSlice { + tv := NewHistogramDataPointSlice() + fillTestHistogramDataPointSlice(tv) + return tv +} + +func fillTestHistogramDataPointSlice(tv HistogramDataPointSlice) { + *tv.orig = make([]*otlpmetrics.HistogramDataPoint, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.HistogramDataPoint{} + fillTestHistogramDataPoint(newHistogramDataPoint((*tv.orig)[i])) + } +} + func TestHistogramDataPoint_MoveTo(t *testing.T) { - ms := HistogramDataPoint(internal.GenerateTestHistogramDataPoint()) + ms := generateTestHistogramDataPoint() dest := NewHistogramDataPoint() ms.MoveTo(dest) assert.Equal(t, NewHistogramDataPoint(), ms) - assert.Equal(t, HistogramDataPoint(internal.GenerateTestHistogramDataPoint()), dest) + assert.Equal(t, generateTestHistogramDataPoint(), dest) } func TestHistogramDataPoint_CopyTo(t *testing.T) { @@ -1019,7 +1196,7 @@ func TestHistogramDataPoint_CopyTo(t *testing.T) { orig := NewHistogramDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = HistogramDataPoint(internal.GenerateTestHistogramDataPoint()) + orig = generateTestHistogramDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1081,8 +1258,8 @@ func TestHistogramDataPoint_ExplicitBounds(t *testing.T) { func TestHistogramDataPoint_Exemplars(t *testing.T) { ms := NewHistogramDataPoint() assert.Equal(t, NewExemplarSlice(), ms.Exemplars()) - internal.FillTestExemplarSlice(internal.ExemplarSlice(ms.Exemplars())) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), ms.Exemplars()) + fillTestExemplarSlice(ms.Exemplars()) + assert.Equal(t, generateTestExemplarSlice(), ms.Exemplars()) } func TestHistogramDataPoint_Flags(t *testing.T) { @@ -1113,6 +1290,26 @@ func TestHistogramDataPoint_Max(t *testing.T) { assert.False(t, ms.HasMax()) } +func generateTestHistogramDataPoint() HistogramDataPoint { + tv := NewHistogramDataPoint() + fillTestHistogramDataPoint(tv) + return tv +} + +func fillTestHistogramDataPoint(tv HistogramDataPoint) { + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.StartTimeUnixNano = 1234567890 + tv.orig.TimeUnixNano = 1234567890 + tv.orig.Count = uint64(17) + tv.orig.Sum_ = &otlpmetrics.HistogramDataPoint_Sum{Sum: float64(17.13)} + tv.orig.BucketCounts = []uint64{1, 2, 3} + tv.orig.ExplicitBounds = []float64{1, 2, 3} + fillTestExemplarSlice(newExemplarSlice(&tv.orig.Exemplars)) + tv.orig.Flags = 1 + tv.orig.Min_ = &otlpmetrics.HistogramDataPoint_Min{Min: float64(9.23)} + tv.orig.Max_ = &otlpmetrics.HistogramDataPoint_Max{Max: float64(182.55)} +} + func TestExponentialHistogramDataPointSlice(t *testing.T) { es := NewExponentialHistogramDataPointSlice() assert.Equal(t, 0, es.Len()) @@ -1121,12 +1318,12 @@ func TestExponentialHistogramDataPointSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newExponentialHistogramDataPoint(&otlpmetrics.ExponentialHistogramDataPoint{}) - testVal := ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestExponentialHistogramDataPoint() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestExponentialHistogramDataPoint(internal.ExponentialHistogramDataPoint(el)) + fillTestExponentialHistogramDataPoint(el) assert.Equal(t, testVal, el) } } @@ -1138,28 +1335,28 @@ func TestExponentialHistogramDataPointSlice_CopyTo(t *testing.T) { assert.Equal(t, NewExponentialHistogramDataPointSlice(), dest) // Test CopyTo larger slice - ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()).CopyTo(dest) - assert.Equal(t, ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()), dest) + generateTestExponentialHistogramDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestExponentialHistogramDataPointSlice(), dest) // Test CopyTo same size slice - ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()).CopyTo(dest) - assert.Equal(t, ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()), dest) + generateTestExponentialHistogramDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestExponentialHistogramDataPointSlice(), dest) } func TestExponentialHistogramDataPointSlice_EnsureCapacity(t *testing.T) { - es := ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()) + es := generateTestExponentialHistogramDataPointSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.ExponentialHistogramDataPoint]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.ExponentialHistogramDataPoint]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -1168,36 +1365,36 @@ func TestExponentialHistogramDataPointSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.ExponentialHistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.ExponentialHistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestExponentialHistogramDataPointSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()) + expectedSlice := generateTestExponentialHistogramDataPointSlice() dest := NewExponentialHistogramDataPointSlice() - src := ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()) + src := generateTestExponentialHistogramDataPointSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()), dest) + assert.Equal(t, generateTestExponentialHistogramDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()), dest) + assert.Equal(t, generateTestExponentialHistogramDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()).MoveAndAppendTo(dest) + generateTestExponentialHistogramDataPointSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -1214,7 +1411,7 @@ func TestExponentialHistogramDataPointSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ExponentialHistogramDataPointSlice(internal.GenerateTestExponentialHistogramDataPointSlice()) + filtered := generateTestExponentialHistogramDataPointSlice() pos := 0 filtered.RemoveIf(func(el ExponentialHistogramDataPoint) bool { pos++ @@ -1223,12 +1420,26 @@ func TestExponentialHistogramDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestExponentialHistogramDataPointSlice() ExponentialHistogramDataPointSlice { + tv := NewExponentialHistogramDataPointSlice() + fillTestExponentialHistogramDataPointSlice(tv) + return tv +} + +func fillTestExponentialHistogramDataPointSlice(tv ExponentialHistogramDataPointSlice) { + *tv.orig = make([]*otlpmetrics.ExponentialHistogramDataPoint, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.ExponentialHistogramDataPoint{} + fillTestExponentialHistogramDataPoint(newExponentialHistogramDataPoint((*tv.orig)[i])) + } +} + func TestExponentialHistogramDataPoint_MoveTo(t *testing.T) { - ms := ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()) + ms := generateTestExponentialHistogramDataPoint() dest := NewExponentialHistogramDataPoint() ms.MoveTo(dest) assert.Equal(t, NewExponentialHistogramDataPoint(), ms) - assert.Equal(t, ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()), dest) + assert.Equal(t, generateTestExponentialHistogramDataPoint(), dest) } func TestExponentialHistogramDataPoint_CopyTo(t *testing.T) { @@ -1236,7 +1447,7 @@ func TestExponentialHistogramDataPoint_CopyTo(t *testing.T) { orig := NewExponentialHistogramDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()) + orig = generateTestExponentialHistogramDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1297,21 +1508,21 @@ func TestExponentialHistogramDataPoint_ZeroCount(t *testing.T) { func TestExponentialHistogramDataPoint_Positive(t *testing.T) { ms := NewExponentialHistogramDataPoint() - internal.FillTestExponentialHistogramDataPointBuckets(internal.ExponentialHistogramDataPointBuckets(ms.Positive())) - assert.Equal(t, ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()), ms.Positive()) + fillTestExponentialHistogramDataPointBuckets(ms.Positive()) + assert.Equal(t, generateTestExponentialHistogramDataPointBuckets(), ms.Positive()) } func TestExponentialHistogramDataPoint_Negative(t *testing.T) { ms := NewExponentialHistogramDataPoint() - internal.FillTestExponentialHistogramDataPointBuckets(internal.ExponentialHistogramDataPointBuckets(ms.Negative())) - assert.Equal(t, ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()), ms.Negative()) + fillTestExponentialHistogramDataPointBuckets(ms.Negative()) + assert.Equal(t, generateTestExponentialHistogramDataPointBuckets(), ms.Negative()) } func TestExponentialHistogramDataPoint_Exemplars(t *testing.T) { ms := NewExponentialHistogramDataPoint() assert.Equal(t, NewExemplarSlice(), ms.Exemplars()) - internal.FillTestExemplarSlice(internal.ExemplarSlice(ms.Exemplars())) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), ms.Exemplars()) + fillTestExemplarSlice(ms.Exemplars()) + assert.Equal(t, generateTestExemplarSlice(), ms.Exemplars()) } func TestExponentialHistogramDataPoint_Flags(t *testing.T) { @@ -1342,12 +1553,34 @@ func TestExponentialHistogramDataPoint_Max(t *testing.T) { assert.False(t, ms.HasMax()) } +func generateTestExponentialHistogramDataPoint() ExponentialHistogramDataPoint { + tv := NewExponentialHistogramDataPoint() + fillTestExponentialHistogramDataPoint(tv) + return tv +} + +func fillTestExponentialHistogramDataPoint(tv ExponentialHistogramDataPoint) { + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.StartTimeUnixNano = 1234567890 + tv.orig.TimeUnixNano = 1234567890 + tv.orig.Count = uint64(17) + tv.orig.Sum_ = &otlpmetrics.ExponentialHistogramDataPoint_Sum{Sum: float64(17.13)} + tv.orig.Scale = int32(4) + tv.orig.ZeroCount = uint64(201) + fillTestExponentialHistogramDataPointBuckets(newExponentialHistogramDataPointBuckets(&tv.orig.Positive)) + fillTestExponentialHistogramDataPointBuckets(newExponentialHistogramDataPointBuckets(&tv.orig.Negative)) + fillTestExemplarSlice(newExemplarSlice(&tv.orig.Exemplars)) + tv.orig.Flags = 1 + tv.orig.Min_ = &otlpmetrics.ExponentialHistogramDataPoint_Min{Min: float64(9.23)} + tv.orig.Max_ = &otlpmetrics.ExponentialHistogramDataPoint_Max{Max: float64(182.55)} +} + func TestExponentialHistogramDataPointBuckets_MoveTo(t *testing.T) { - ms := ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()) + ms := generateTestExponentialHistogramDataPointBuckets() dest := NewExponentialHistogramDataPointBuckets() ms.MoveTo(dest) assert.Equal(t, NewExponentialHistogramDataPointBuckets(), ms) - assert.Equal(t, ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()), dest) + assert.Equal(t, generateTestExponentialHistogramDataPointBuckets(), dest) } func TestExponentialHistogramDataPointBuckets_CopyTo(t *testing.T) { @@ -1355,7 +1588,7 @@ func TestExponentialHistogramDataPointBuckets_CopyTo(t *testing.T) { orig := NewExponentialHistogramDataPointBuckets() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()) + orig = generateTestExponentialHistogramDataPointBuckets() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1374,6 +1607,17 @@ func TestExponentialHistogramDataPointBuckets_BucketCounts(t *testing.T) { assert.Equal(t, []uint64{1, 2, 3}, ms.BucketCounts().AsRaw()) } +func generateTestExponentialHistogramDataPointBuckets() ExponentialHistogramDataPointBuckets { + tv := NewExponentialHistogramDataPointBuckets() + fillTestExponentialHistogramDataPointBuckets(tv) + return tv +} + +func fillTestExponentialHistogramDataPointBuckets(tv ExponentialHistogramDataPointBuckets) { + tv.orig.Offset = int32(909) + tv.orig.BucketCounts = []uint64{1, 2, 3} +} + func TestSummaryDataPointSlice(t *testing.T) { es := NewSummaryDataPointSlice() assert.Equal(t, 0, es.Len()) @@ -1382,12 +1626,12 @@ func TestSummaryDataPointSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newSummaryDataPoint(&otlpmetrics.SummaryDataPoint{}) - testVal := SummaryDataPoint(internal.GenerateTestSummaryDataPoint()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestSummaryDataPoint() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSummaryDataPoint(internal.SummaryDataPoint(el)) + fillTestSummaryDataPoint(el) assert.Equal(t, testVal, el) } } @@ -1399,28 +1643,28 @@ func TestSummaryDataPointSlice_CopyTo(t *testing.T) { assert.Equal(t, NewSummaryDataPointSlice(), dest) // Test CopyTo larger slice - SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()).CopyTo(dest) - assert.Equal(t, SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()), dest) + generateTestSummaryDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestSummaryDataPointSlice(), dest) // Test CopyTo same size slice - SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()).CopyTo(dest) - assert.Equal(t, SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()), dest) + generateTestSummaryDataPointSlice().CopyTo(dest) + assert.Equal(t, generateTestSummaryDataPointSlice(), dest) } func TestSummaryDataPointSlice_EnsureCapacity(t *testing.T) { - es := SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()) + es := generateTestSummaryDataPointSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.SummaryDataPoint]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.SummaryDataPoint]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -1429,36 +1673,36 @@ func TestSummaryDataPointSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.SummaryDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.SummaryDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestSummaryDataPointSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()) + expectedSlice := generateTestSummaryDataPointSlice() dest := NewSummaryDataPointSlice() - src := SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()) + src := generateTestSummaryDataPointSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()), dest) + assert.Equal(t, generateTestSummaryDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()), dest) + assert.Equal(t, generateTestSummaryDataPointSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()).MoveAndAppendTo(dest) + generateTestSummaryDataPointSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -1475,7 +1719,7 @@ func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := SummaryDataPointSlice(internal.GenerateTestSummaryDataPointSlice()) + filtered := generateTestSummaryDataPointSlice() pos := 0 filtered.RemoveIf(func(el SummaryDataPoint) bool { pos++ @@ -1484,12 +1728,26 @@ func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestSummaryDataPointSlice() SummaryDataPointSlice { + tv := NewSummaryDataPointSlice() + fillTestSummaryDataPointSlice(tv) + return tv +} + +func fillTestSummaryDataPointSlice(tv SummaryDataPointSlice) { + *tv.orig = make([]*otlpmetrics.SummaryDataPoint, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.SummaryDataPoint{} + fillTestSummaryDataPoint(newSummaryDataPoint((*tv.orig)[i])) + } +} + func TestSummaryDataPoint_MoveTo(t *testing.T) { - ms := SummaryDataPoint(internal.GenerateTestSummaryDataPoint()) + ms := generateTestSummaryDataPoint() dest := NewSummaryDataPoint() ms.MoveTo(dest) assert.Equal(t, NewSummaryDataPoint(), ms) - assert.Equal(t, SummaryDataPoint(internal.GenerateTestSummaryDataPoint()), dest) + assert.Equal(t, generateTestSummaryDataPoint(), dest) } func TestSummaryDataPoint_CopyTo(t *testing.T) { @@ -1497,7 +1755,7 @@ func TestSummaryDataPoint_CopyTo(t *testing.T) { orig := NewSummaryDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SummaryDataPoint(internal.GenerateTestSummaryDataPoint()) + orig = generateTestSummaryDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1542,8 +1800,8 @@ func TestSummaryDataPoint_Sum(t *testing.T) { func TestSummaryDataPoint_QuantileValues(t *testing.T) { ms := NewSummaryDataPoint() assert.Equal(t, NewSummaryDataPointValueAtQuantileSlice(), ms.QuantileValues()) - internal.FillTestSummaryDataPointValueAtQuantileSlice(internal.SummaryDataPointValueAtQuantileSlice(ms.QuantileValues())) - assert.Equal(t, SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()), ms.QuantileValues()) + fillTestSummaryDataPointValueAtQuantileSlice(ms.QuantileValues()) + assert.Equal(t, generateTestSummaryDataPointValueAtQuantileSlice(), ms.QuantileValues()) } func TestSummaryDataPoint_Flags(t *testing.T) { @@ -1554,6 +1812,22 @@ func TestSummaryDataPoint_Flags(t *testing.T) { assert.Equal(t, testValFlags, ms.Flags()) } +func generateTestSummaryDataPoint() SummaryDataPoint { + tv := NewSummaryDataPoint() + fillTestSummaryDataPoint(tv) + return tv +} + +func fillTestSummaryDataPoint(tv SummaryDataPoint) { + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.StartTimeUnixNano = 1234567890 + tv.orig.TimeUnixNano = 1234567890 + tv.orig.Count = uint64(17) + tv.orig.Sum = float64(17.13) + fillTestSummaryDataPointValueAtQuantileSlice(newSummaryDataPointValueAtQuantileSlice(&tv.orig.QuantileValues)) + tv.orig.Flags = 1 +} + func TestSummaryDataPointValueAtQuantileSlice(t *testing.T) { es := NewSummaryDataPointValueAtQuantileSlice() assert.Equal(t, 0, es.Len()) @@ -1562,12 +1836,12 @@ func TestSummaryDataPointValueAtQuantileSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newSummaryDataPointValueAtQuantile(&otlpmetrics.SummaryDataPoint_ValueAtQuantile{}) - testVal := SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestSummaryDataPointValueAtQuantile() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSummaryDataPointValueAtQuantile(internal.SummaryDataPointValueAtQuantile(el)) + fillTestSummaryDataPointValueAtQuantile(el) assert.Equal(t, testVal, el) } } @@ -1579,28 +1853,28 @@ func TestSummaryDataPointValueAtQuantileSlice_CopyTo(t *testing.T) { assert.Equal(t, NewSummaryDataPointValueAtQuantileSlice(), dest) // Test CopyTo larger slice - SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()).CopyTo(dest) - assert.Equal(t, SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()), dest) + generateTestSummaryDataPointValueAtQuantileSlice().CopyTo(dest) + assert.Equal(t, generateTestSummaryDataPointValueAtQuantileSlice(), dest) // Test CopyTo same size slice - SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()).CopyTo(dest) - assert.Equal(t, SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()), dest) + generateTestSummaryDataPointValueAtQuantileSlice().CopyTo(dest) + assert.Equal(t, generateTestSummaryDataPointValueAtQuantileSlice(), dest) } func TestSummaryDataPointValueAtQuantileSlice_EnsureCapacity(t *testing.T) { - es := SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()) + es := generateTestSummaryDataPointValueAtQuantileSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.SummaryDataPoint_ValueAtQuantile]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.SummaryDataPoint_ValueAtQuantile]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -1609,36 +1883,36 @@ func TestSummaryDataPointValueAtQuantileSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.SummaryDataPoint_ValueAtQuantile]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlpmetrics.SummaryDataPoint_ValueAtQuantile]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestSummaryDataPointValueAtQuantileSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()) + expectedSlice := generateTestSummaryDataPointValueAtQuantileSlice() dest := NewSummaryDataPointValueAtQuantileSlice() - src := SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()) + src := generateTestSummaryDataPointValueAtQuantileSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()), dest) + assert.Equal(t, generateTestSummaryDataPointValueAtQuantileSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()), dest) + assert.Equal(t, generateTestSummaryDataPointValueAtQuantileSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()).MoveAndAppendTo(dest) + generateTestSummaryDataPointValueAtQuantileSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -1655,7 +1929,7 @@ func TestSummaryDataPointValueAtQuantileSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := SummaryDataPointValueAtQuantileSlice(internal.GenerateTestSummaryDataPointValueAtQuantileSlice()) + filtered := generateTestSummaryDataPointValueAtQuantileSlice() pos := 0 filtered.RemoveIf(func(el SummaryDataPointValueAtQuantile) bool { pos++ @@ -1664,12 +1938,26 @@ func TestSummaryDataPointValueAtQuantileSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestSummaryDataPointValueAtQuantileSlice() SummaryDataPointValueAtQuantileSlice { + tv := NewSummaryDataPointValueAtQuantileSlice() + fillTestSummaryDataPointValueAtQuantileSlice(tv) + return tv +} + +func fillTestSummaryDataPointValueAtQuantileSlice(tv SummaryDataPointValueAtQuantileSlice) { + *tv.orig = make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlpmetrics.SummaryDataPoint_ValueAtQuantile{} + fillTestSummaryDataPointValueAtQuantile(newSummaryDataPointValueAtQuantile((*tv.orig)[i])) + } +} + func TestSummaryDataPointValueAtQuantile_MoveTo(t *testing.T) { - ms := SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()) + ms := generateTestSummaryDataPointValueAtQuantile() dest := NewSummaryDataPointValueAtQuantile() ms.MoveTo(dest) assert.Equal(t, NewSummaryDataPointValueAtQuantile(), ms) - assert.Equal(t, SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()), dest) + assert.Equal(t, generateTestSummaryDataPointValueAtQuantile(), dest) } func TestSummaryDataPointValueAtQuantile_CopyTo(t *testing.T) { @@ -1677,7 +1965,7 @@ func TestSummaryDataPointValueAtQuantile_CopyTo(t *testing.T) { orig := NewSummaryDataPointValueAtQuantile() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()) + orig = generateTestSummaryDataPointValueAtQuantile() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1696,6 +1984,17 @@ func TestSummaryDataPointValueAtQuantile_Value(t *testing.T) { assert.Equal(t, float64(17.13), ms.Value()) } +func generateTestSummaryDataPointValueAtQuantile() SummaryDataPointValueAtQuantile { + tv := NewSummaryDataPointValueAtQuantile() + fillTestSummaryDataPointValueAtQuantile(tv) + return tv +} + +func fillTestSummaryDataPointValueAtQuantile(tv SummaryDataPointValueAtQuantile) { + tv.orig.Quantile = float64(17.13) + tv.orig.Value = float64(17.13) +} + func TestExemplarSlice(t *testing.T) { es := NewExemplarSlice() assert.Equal(t, 0, es.Len()) @@ -1704,12 +2003,12 @@ func TestExemplarSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newExemplar(&otlpmetrics.Exemplar{}) - testVal := Exemplar(internal.GenerateTestExemplar()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestExemplar() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestExemplar(internal.Exemplar(el)) + fillTestExemplar(el) assert.Equal(t, testVal, el) } } @@ -1721,28 +2020,28 @@ func TestExemplarSlice_CopyTo(t *testing.T) { assert.Equal(t, NewExemplarSlice(), dest) // Test CopyTo larger slice - ExemplarSlice(internal.GenerateTestExemplarSlice()).CopyTo(dest) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), dest) + generateTestExemplarSlice().CopyTo(dest) + assert.Equal(t, generateTestExemplarSlice(), dest) // Test CopyTo same size slice - ExemplarSlice(internal.GenerateTestExemplarSlice()).CopyTo(dest) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), dest) + generateTestExemplarSlice().CopyTo(dest) + assert.Equal(t, generateTestExemplarSlice(), dest) } func TestExemplarSlice_EnsureCapacity(t *testing.T) { - es := ExemplarSlice(internal.GenerateTestExemplarSlice()) + es := generateTestExemplarSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlpmetrics.Exemplar]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.Exemplar]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -1751,27 +2050,27 @@ func TestExemplarSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) } func TestExemplarSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ExemplarSlice(internal.GenerateTestExemplarSlice()) + expectedSlice := generateTestExemplarSlice() dest := NewExemplarSlice() - src := ExemplarSlice(internal.GenerateTestExemplarSlice()) + src := generateTestExemplarSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), dest) + assert.Equal(t, generateTestExemplarSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ExemplarSlice(internal.GenerateTestExemplarSlice()), dest) + assert.Equal(t, generateTestExemplarSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ExemplarSlice(internal.GenerateTestExemplarSlice()).MoveAndAppendTo(dest) + generateTestExemplarSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -1788,7 +2087,7 @@ func TestExemplarSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ExemplarSlice(internal.GenerateTestExemplarSlice()) + filtered := generateTestExemplarSlice() pos := 0 filtered.RemoveIf(func(el Exemplar) bool { pos++ @@ -1797,12 +2096,25 @@ func TestExemplarSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestExemplarSlice() ExemplarSlice { + tv := NewExemplarSlice() + fillTestExemplarSlice(tv) + return tv +} + +func fillTestExemplarSlice(tv ExemplarSlice) { + *tv.orig = make([]otlpmetrics.Exemplar, 7) + for i := 0; i < 7; i++ { + fillTestExemplar(newExemplar(&(*tv.orig)[i])) + } +} + func TestExemplar_MoveTo(t *testing.T) { - ms := Exemplar(internal.GenerateTestExemplar()) + ms := generateTestExemplar() dest := NewExemplar() ms.MoveTo(dest) assert.Equal(t, NewExemplar(), ms) - assert.Equal(t, Exemplar(internal.GenerateTestExemplar()), dest) + assert.Equal(t, generateTestExemplar(), dest) } func TestExemplar_CopyTo(t *testing.T) { @@ -1810,7 +2122,7 @@ func TestExemplar_CopyTo(t *testing.T) { orig := NewExemplar() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Exemplar(internal.GenerateTestExemplar()) + orig = generateTestExemplar() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1866,3 +2178,17 @@ func TestExemplar_SpanID(t *testing.T) { ms.SetSpanID(testValSpanID) assert.Equal(t, testValSpanID, ms.SpanID()) } + +func generateTestExemplar() Exemplar { + tv := NewExemplar() + fillTestExemplar(tv) + return tv +} + +func fillTestExemplar(tv Exemplar) { + tv.orig.TimeUnixNano = 1234567890 + tv.orig.Value = &otlpmetrics.Exemplar_AsInt{AsInt: int64(17)} + internal.FillTestMap(internal.NewMap(&tv.orig.FilteredAttributes)) + tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) + tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) +} diff --git a/pdata/pmetric/metrics_test.go b/pdata/pmetric/metrics_test.go index f8cc3e6ef47..e9c814e8ec2 100644 --- a/pdata/pmetric/metrics_test.go +++ b/pdata/pmetric/metrics_test.go @@ -22,7 +22,6 @@ import ( goproto "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/emptypb" - "go.opentelemetry.io/collector/pdata/internal" otlpcollectormetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/metrics/v1" otlpcommon "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1" otlpmetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1" @@ -73,7 +72,7 @@ func TestResourceMetricsWireCompatibility(t *testing.T) { // Generate ResourceMetrics as pdata struct. metrics := NewMetrics() - internal.FillTestResourceMetricsSlice(internal.ResourceMetricsSlice(metrics.ResourceMetrics())) + fillTestResourceMetricsSlice(metrics.ResourceMetrics()) // Marshal its underlying ProtoBuf to wire. wire1, err := gogoproto.Marshal(metrics.getOrig()) @@ -227,11 +226,11 @@ func TestHistogramWithValidSum(t *testing.T) { func TestMetricsMoveTo(t *testing.T) { metrics := NewMetrics() - internal.FillTestResourceMetricsSlice(internal.ResourceMetricsSlice(metrics.ResourceMetrics())) + fillTestResourceMetricsSlice(metrics.ResourceMetrics()) dest := NewMetrics() metrics.MoveTo(dest) assert.EqualValues(t, NewMetrics(), metrics) - assert.EqualValues(t, ResourceMetricsSlice(internal.GenerateTestResourceMetricsSlice()), dest.ResourceMetrics()) + assert.EqualValues(t, generateTestResourceMetricsSlice(), dest.ResourceMetrics()) } func TestOtlpToInternalReadOnly(t *testing.T) { @@ -681,7 +680,7 @@ func TestOtlpToFromInternalExponentialHistogramMutating(t *testing.T) { func TestMetricsCopyTo(t *testing.T) { metrics := NewMetrics() - internal.FillTestResourceMetricsSlice(internal.ResourceMetricsSlice(metrics.ResourceMetrics())) + fillTestResourceMetricsSlice(metrics.ResourceMetrics()) metricsCopy := NewMetrics() metrics.CopyTo(metricsCopy) assert.EqualValues(t, metrics, metricsCopy) diff --git a/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go b/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go index d16203f4e47..9c93f2228ed 100644 --- a/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go +++ b/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go @@ -18,7 +18,6 @@ package pmetricotlp import ( - "go.opentelemetry.io/collector/pdata/internal" otlpcollectormetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/metrics/v1" ) @@ -29,15 +28,12 @@ import ( // // Must use NewExportPartialSuccess function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ExportPartialSuccess internal.MetricsExportPartialSuccess - -func newExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) ExportPartialSuccess { - return ExportPartialSuccess(internal.NewMetricsExportPartialSuccess(orig)) +type ExportPartialSuccess struct { + orig *otlpcollectormetrics.ExportMetricsPartialSuccess } -func (ms ExportPartialSuccess) getOrig() *otlpcollectormetrics.ExportMetricsPartialSuccess { - return internal.GetOrigMetricsExportPartialSuccess(internal.MetricsExportPartialSuccess(ms)) +func newExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) ExportPartialSuccess { + return ExportPartialSuccess{orig} } // NewExportPartialSuccess creates a new empty ExportPartialSuccess. @@ -51,28 +47,28 @@ func NewExportPartialSuccess() ExportPartialSuccess { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ExportPartialSuccess) MoveTo(dest ExportPartialSuccess) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpcollectormetrics.ExportMetricsPartialSuccess{} + *dest.orig = *ms.orig + *ms.orig = otlpcollectormetrics.ExportMetricsPartialSuccess{} } // RejectedDataPoints returns the rejecteddatapoints associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) RejectedDataPoints() int64 { - return ms.getOrig().RejectedDataPoints + return ms.orig.RejectedDataPoints } // SetRejectedDataPoints replaces the rejecteddatapoints associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) SetRejectedDataPoints(v int64) { - ms.getOrig().RejectedDataPoints = v + ms.orig.RejectedDataPoints = v } // ErrorMessage returns the errormessage associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) ErrorMessage() string { - return ms.getOrig().ErrorMessage + return ms.orig.ErrorMessage } // SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) SetErrorMessage(v string) { - ms.getOrig().ErrorMessage = v + ms.orig.ErrorMessage = v } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go b/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go index 8a9742c0194..d1faeb729fb 100644 --- a/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go +++ b/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go @@ -21,16 +21,14 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/pdata/internal" ) func TestExportPartialSuccess_MoveTo(t *testing.T) { - ms := ExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()) + ms := generateTestExportPartialSuccess() dest := NewExportPartialSuccess() ms.MoveTo(dest) assert.Equal(t, NewExportPartialSuccess(), ms) - assert.Equal(t, ExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()), dest) + assert.Equal(t, generateTestExportPartialSuccess(), dest) } func TestExportPartialSuccess_CopyTo(t *testing.T) { @@ -38,7 +36,7 @@ func TestExportPartialSuccess_CopyTo(t *testing.T) { orig := NewExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()) + orig = generateTestExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -56,3 +54,14 @@ func TestExportPartialSuccess_ErrorMessage(t *testing.T) { ms.SetErrorMessage("error message") assert.Equal(t, "error message", ms.ErrorMessage()) } + +func generateTestExportPartialSuccess() ExportPartialSuccess { + tv := NewExportPartialSuccess() + fillTestExportPartialSuccess(tv) + return tv +} + +func fillTestExportPartialSuccess(tv ExportPartialSuccess) { + tv.orig.RejectedDataPoints = int64(13) + tv.orig.ErrorMessage = "error message" +} diff --git a/pdata/pmetric/pmetricotlp/response.go b/pdata/pmetric/pmetricotlp/response.go index 9e9fd549254..e53067e3eeb 100644 --- a/pdata/pmetric/pmetricotlp/response.go +++ b/pdata/pmetric/pmetricotlp/response.go @@ -13,10 +13,10 @@ // limitations under the License. package pmetricotlp // import "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" + import ( "bytes" - "go.opentelemetry.io/collector/pdata/internal" otlpcollectormetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/metrics/v1" "go.opentelemetry.io/collector/pdata/pmetric/internal/pmetricjson" ) @@ -57,5 +57,5 @@ func (ms ExportResponse) UnmarshalJSON(data []byte) error { // PartialSuccess returns the ExportLogsPartialSuccess associated with this ExportResponse. func (ms ExportResponse) PartialSuccess() ExportPartialSuccess { - return ExportPartialSuccess(internal.NewMetricsExportPartialSuccess(&ms.orig.PartialSuccess)) + return newExportPartialSuccess(&ms.orig.PartialSuccess) } diff --git a/pdata/ptrace/generated_traces.go b/pdata/ptrace/generated_traces.go index b84d11404b6..f3463dc5cb1 100644 --- a/pdata/ptrace/generated_traces.go +++ b/pdata/ptrace/generated_traces.go @@ -33,14 +33,12 @@ import ( // // Must use NewResourceSpansSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ResourceSpansSlice internal.ResourceSpansSlice - -func newResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) ResourceSpansSlice { - return ResourceSpansSlice(internal.NewResourceSpansSlice(orig)) +type ResourceSpansSlice struct { + orig *[]*otlptrace.ResourceSpans } -func (ms ResourceSpansSlice) getOrig() *[]*otlptrace.ResourceSpans { - return internal.GetOrigResourceSpansSlice(internal.ResourceSpansSlice(ms)) +func newResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) ResourceSpansSlice { + return ResourceSpansSlice{orig} } // NewResourceSpansSlice creates a ResourceSpansSlice with 0 elements. @@ -54,7 +52,7 @@ func NewResourceSpansSlice() ResourceSpansSlice { // // Returns "0" for a newly instance created with "NewResourceSpansSlice()". func (es ResourceSpansSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -66,27 +64,27 @@ func (es ResourceSpansSlice) Len() int { // ... // Do something with the element // } func (es ResourceSpansSlice) At(ix int) ResourceSpans { - return newResourceSpans((*es.getOrig())[ix]) + return newResourceSpans((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newResourceSpans((*es.getOrig())[i]).CopyTo(newResourceSpans((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newResourceSpans((*es.orig)[i]).CopyTo(newResourceSpans((*dest.orig)[i])) } return } origs := make([]otlptrace.ResourceSpans, srcLen) wrappers := make([]*otlptrace.ResourceSpans, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newResourceSpans((*es.getOrig())[i]).CopyTo(newResourceSpans(wrappers[i])) + newResourceSpans((*es.orig)[i]).CopyTo(newResourceSpans(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -102,20 +100,20 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { // // Here should set all the values for e. // } func (es ResourceSpansSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlptrace.ResourceSpans, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlptrace.ResourceSpans, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ResourceSpans. // It returns the newly added ResourceSpans. func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { - *es.getOrig() = append(*es.getOrig(), &otlptrace.ResourceSpans{}) + *es.orig = append(*es.orig, &otlptrace.ResourceSpans{}) return es.At(es.Len() - 1) } @@ -123,26 +121,26 @@ func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { // provided less function so that two instances of ResourceSpansSlice // can be compared. func (es ResourceSpansSlice) Sort(less func(a, b ResourceSpans) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceSpansSlice) MoveAndAppendTo(dest ResourceSpansSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ResourceSpansSlice) RemoveIf(f func(ResourceSpans) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -151,11 +149,11 @@ func (es ResourceSpansSlice) RemoveIf(f func(ResourceSpans) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ResourceSpans is a collection of spans from a Resource. @@ -165,15 +163,12 @@ func (es ResourceSpansSlice) RemoveIf(f func(ResourceSpans) bool) { // // Must use NewResourceSpans function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ResourceSpans internal.ResourceSpans - -func newResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans { - return ResourceSpans(internal.NewResourceSpans(orig)) +type ResourceSpans struct { + orig *otlptrace.ResourceSpans } -func (ms ResourceSpans) getOrig() *otlptrace.ResourceSpans { - return internal.GetOrigResourceSpans(internal.ResourceSpans(ms)) +func newResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans { + return ResourceSpans{orig} } // NewResourceSpans creates a new empty ResourceSpans. @@ -187,28 +182,28 @@ func NewResourceSpans() ResourceSpans { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ResourceSpans) MoveTo(dest ResourceSpans) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlptrace.ResourceSpans{} + *dest.orig = *ms.orig + *ms.orig = otlptrace.ResourceSpans{} } // Resource returns the resource associated with this ResourceSpans. func (ms ResourceSpans) Resource() pcommon.Resource { - return pcommon.Resource(internal.NewResource(&ms.getOrig().Resource)) + return pcommon.Resource(internal.NewResource(&ms.orig.Resource)) } // SchemaUrl returns the schemaurl associated with this ResourceSpans. func (ms ResourceSpans) SchemaUrl() string { - return ms.getOrig().SchemaUrl + return ms.orig.SchemaUrl } // SetSchemaUrl replaces the schemaurl associated with this ResourceSpans. func (ms ResourceSpans) SetSchemaUrl(v string) { - ms.getOrig().SchemaUrl = v + ms.orig.SchemaUrl = v } // ScopeSpans returns the ScopeSpans associated with this ResourceSpans. func (ms ResourceSpans) ScopeSpans() ScopeSpansSlice { - return ScopeSpansSlice(internal.NewScopeSpansSlice(&ms.getOrig().ScopeSpans)) + return newScopeSpansSlice(&ms.orig.ScopeSpans) } // CopyTo copies all properties from the current struct overriding the destination. @@ -225,14 +220,12 @@ func (ms ResourceSpans) CopyTo(dest ResourceSpans) { // // Must use NewScopeSpansSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type ScopeSpansSlice internal.ScopeSpansSlice - -func newScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) ScopeSpansSlice { - return ScopeSpansSlice(internal.NewScopeSpansSlice(orig)) +type ScopeSpansSlice struct { + orig *[]*otlptrace.ScopeSpans } -func (ms ScopeSpansSlice) getOrig() *[]*otlptrace.ScopeSpans { - return internal.GetOrigScopeSpansSlice(internal.ScopeSpansSlice(ms)) +func newScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) ScopeSpansSlice { + return ScopeSpansSlice{orig} } // NewScopeSpansSlice creates a ScopeSpansSlice with 0 elements. @@ -246,7 +239,7 @@ func NewScopeSpansSlice() ScopeSpansSlice { // // Returns "0" for a newly instance created with "NewScopeSpansSlice()". func (es ScopeSpansSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -258,27 +251,27 @@ func (es ScopeSpansSlice) Len() int { // ... // Do something with the element // } func (es ScopeSpansSlice) At(ix int) ScopeSpans { - return newScopeSpans((*es.getOrig())[ix]) + return newScopeSpans((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newScopeSpans((*es.getOrig())[i]).CopyTo(newScopeSpans((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newScopeSpans((*es.orig)[i]).CopyTo(newScopeSpans((*dest.orig)[i])) } return } origs := make([]otlptrace.ScopeSpans, srcLen) wrappers := make([]*otlptrace.ScopeSpans, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newScopeSpans((*es.getOrig())[i]).CopyTo(newScopeSpans(wrappers[i])) + newScopeSpans((*es.orig)[i]).CopyTo(newScopeSpans(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -294,20 +287,20 @@ func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { // // Here should set all the values for e. // } func (es ScopeSpansSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlptrace.ScopeSpans, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlptrace.ScopeSpans, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty ScopeSpans. // It returns the newly added ScopeSpans. func (es ScopeSpansSlice) AppendEmpty() ScopeSpans { - *es.getOrig() = append(*es.getOrig(), &otlptrace.ScopeSpans{}) + *es.orig = append(*es.orig, &otlptrace.ScopeSpans{}) return es.At(es.Len() - 1) } @@ -315,26 +308,26 @@ func (es ScopeSpansSlice) AppendEmpty() ScopeSpans { // provided less function so that two instances of ScopeSpansSlice // can be compared. func (es ScopeSpansSlice) Sort(less func(a, b ScopeSpans) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ScopeSpansSlice) MoveAndAppendTo(dest ScopeSpansSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es ScopeSpansSlice) RemoveIf(f func(ScopeSpans) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -343,11 +336,11 @@ func (es ScopeSpansSlice) RemoveIf(f func(ScopeSpans) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // ScopeSpans is a collection of spans from a LibraryInstrumentation. @@ -357,15 +350,12 @@ func (es ScopeSpansSlice) RemoveIf(f func(ScopeSpans) bool) { // // Must use NewScopeSpans function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ScopeSpans internal.ScopeSpans - -func newScopeSpans(orig *otlptrace.ScopeSpans) ScopeSpans { - return ScopeSpans(internal.NewScopeSpans(orig)) +type ScopeSpans struct { + orig *otlptrace.ScopeSpans } -func (ms ScopeSpans) getOrig() *otlptrace.ScopeSpans { - return internal.GetOrigScopeSpans(internal.ScopeSpans(ms)) +func newScopeSpans(orig *otlptrace.ScopeSpans) ScopeSpans { + return ScopeSpans{orig} } // NewScopeSpans creates a new empty ScopeSpans. @@ -379,28 +369,28 @@ func NewScopeSpans() ScopeSpans { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ScopeSpans) MoveTo(dest ScopeSpans) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlptrace.ScopeSpans{} + *dest.orig = *ms.orig + *ms.orig = otlptrace.ScopeSpans{} } // Scope returns the scope associated with this ScopeSpans. func (ms ScopeSpans) Scope() pcommon.InstrumentationScope { - return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.getOrig().Scope)) + return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.orig.Scope)) } // SchemaUrl returns the schemaurl associated with this ScopeSpans. func (ms ScopeSpans) SchemaUrl() string { - return ms.getOrig().SchemaUrl + return ms.orig.SchemaUrl } // SetSchemaUrl replaces the schemaurl associated with this ScopeSpans. func (ms ScopeSpans) SetSchemaUrl(v string) { - ms.getOrig().SchemaUrl = v + ms.orig.SchemaUrl = v } // Spans returns the Spans associated with this ScopeSpans. func (ms ScopeSpans) Spans() SpanSlice { - return SpanSlice(internal.NewSpanSlice(&ms.getOrig().Spans)) + return newSpanSlice(&ms.orig.Spans) } // CopyTo copies all properties from the current struct overriding the destination. @@ -417,14 +407,12 @@ func (ms ScopeSpans) CopyTo(dest ScopeSpans) { // // Must use NewSpanSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type SpanSlice internal.SpanSlice - -func newSpanSlice(orig *[]*otlptrace.Span) SpanSlice { - return SpanSlice(internal.NewSpanSlice(orig)) +type SpanSlice struct { + orig *[]*otlptrace.Span } -func (ms SpanSlice) getOrig() *[]*otlptrace.Span { - return internal.GetOrigSpanSlice(internal.SpanSlice(ms)) +func newSpanSlice(orig *[]*otlptrace.Span) SpanSlice { + return SpanSlice{orig} } // NewSpanSlice creates a SpanSlice with 0 elements. @@ -438,7 +426,7 @@ func NewSpanSlice() SpanSlice { // // Returns "0" for a newly instance created with "NewSpanSlice()". func (es SpanSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -450,27 +438,27 @@ func (es SpanSlice) Len() int { // ... // Do something with the element // } func (es SpanSlice) At(ix int) Span { - return newSpan((*es.getOrig())[ix]) + return newSpan((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es SpanSlice) CopyTo(dest SpanSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newSpan((*es.getOrig())[i]).CopyTo(newSpan((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newSpan((*es.orig)[i]).CopyTo(newSpan((*dest.orig)[i])) } return } origs := make([]otlptrace.Span, srcLen) wrappers := make([]*otlptrace.Span, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newSpan((*es.getOrig())[i]).CopyTo(newSpan(wrappers[i])) + newSpan((*es.orig)[i]).CopyTo(newSpan(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -486,20 +474,20 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { // // Here should set all the values for e. // } func (es SpanSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlptrace.Span, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlptrace.Span, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty Span. // It returns the newly added Span. func (es SpanSlice) AppendEmpty() Span { - *es.getOrig() = append(*es.getOrig(), &otlptrace.Span{}) + *es.orig = append(*es.orig, &otlptrace.Span{}) return es.At(es.Len() - 1) } @@ -507,26 +495,26 @@ func (es SpanSlice) AppendEmpty() Span { // provided less function so that two instances of SpanSlice // can be compared. func (es SpanSlice) Sort(less func(a, b Span) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanSlice) MoveAndAppendTo(dest SpanSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es SpanSlice) RemoveIf(f func(Span) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -535,11 +523,11 @@ func (es SpanSlice) RemoveIf(f func(Span) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // Span represents a single operation within a trace. @@ -550,15 +538,12 @@ func (es SpanSlice) RemoveIf(f func(Span) bool) { // // Must use NewSpan function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Span internal.Span - -func newSpan(orig *otlptrace.Span) Span { - return Span(internal.NewSpan(orig)) +type Span struct { + orig *otlptrace.Span } -func (ms Span) getOrig() *otlptrace.Span { - return internal.GetOrigSpan(internal.Span(ms)) +func newSpan(orig *otlptrace.Span) Span { + return Span{orig} } // NewSpan creates a new empty Span. @@ -572,133 +557,133 @@ func NewSpan() Span { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Span) MoveTo(dest Span) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlptrace.Span{} + *dest.orig = *ms.orig + *ms.orig = otlptrace.Span{} } // TraceID returns the traceid associated with this Span. func (ms Span) TraceID() pcommon.TraceID { - return pcommon.TraceID(ms.getOrig().TraceId) + return pcommon.TraceID(ms.orig.TraceId) } // SetTraceID replaces the traceid associated with this Span. func (ms Span) SetTraceID(v pcommon.TraceID) { - ms.getOrig().TraceId = data.TraceID(v) + ms.orig.TraceId = data.TraceID(v) } // SpanID returns the spanid associated with this Span. func (ms Span) SpanID() pcommon.SpanID { - return pcommon.SpanID(ms.getOrig().SpanId) + return pcommon.SpanID(ms.orig.SpanId) } // SetSpanID replaces the spanid associated with this Span. func (ms Span) SetSpanID(v pcommon.SpanID) { - ms.getOrig().SpanId = data.SpanID(v) + ms.orig.SpanId = data.SpanID(v) } // TraceState returns the tracestate associated with this Span. func (ms Span) TraceState() pcommon.TraceState { - return pcommon.TraceState(internal.NewTraceState(&ms.getOrig().TraceState)) + return pcommon.TraceState(internal.NewTraceState(&ms.orig.TraceState)) } // ParentSpanID returns the parentspanid associated with this Span. func (ms Span) ParentSpanID() pcommon.SpanID { - return pcommon.SpanID(ms.getOrig().ParentSpanId) + return pcommon.SpanID(ms.orig.ParentSpanId) } // SetParentSpanID replaces the parentspanid associated with this Span. func (ms Span) SetParentSpanID(v pcommon.SpanID) { - ms.getOrig().ParentSpanId = data.SpanID(v) + ms.orig.ParentSpanId = data.SpanID(v) } // Name returns the name associated with this Span. func (ms Span) Name() string { - return ms.getOrig().Name + return ms.orig.Name } // SetName replaces the name associated with this Span. func (ms Span) SetName(v string) { - ms.getOrig().Name = v + ms.orig.Name = v } // Kind returns the kind associated with this Span. func (ms Span) Kind() SpanKind { - return SpanKind(ms.getOrig().Kind) + return SpanKind(ms.orig.Kind) } // SetKind replaces the kind associated with this Span. func (ms Span) SetKind(v SpanKind) { - ms.getOrig().Kind = otlptrace.Span_SpanKind(v) + ms.orig.Kind = otlptrace.Span_SpanKind(v) } // StartTimestamp returns the starttimestamp associated with this Span. func (ms Span) StartTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) + return pcommon.Timestamp(ms.orig.StartTimeUnixNano) } // SetStartTimestamp replaces the starttimestamp associated with this Span. func (ms Span) SetStartTimestamp(v pcommon.Timestamp) { - ms.getOrig().StartTimeUnixNano = uint64(v) + ms.orig.StartTimeUnixNano = uint64(v) } // EndTimestamp returns the endtimestamp associated with this Span. func (ms Span) EndTimestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().EndTimeUnixNano) + return pcommon.Timestamp(ms.orig.EndTimeUnixNano) } // SetEndTimestamp replaces the endtimestamp associated with this Span. func (ms Span) SetEndTimestamp(v pcommon.Timestamp) { - ms.getOrig().EndTimeUnixNano = uint64(v) + ms.orig.EndTimeUnixNano = uint64(v) } // Attributes returns the Attributes associated with this Span. func (ms Span) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // DroppedAttributesCount returns the droppedattributescount associated with this Span. func (ms Span) DroppedAttributesCount() uint32 { - return ms.getOrig().DroppedAttributesCount + return ms.orig.DroppedAttributesCount } // SetDroppedAttributesCount replaces the droppedattributescount associated with this Span. func (ms Span) SetDroppedAttributesCount(v uint32) { - ms.getOrig().DroppedAttributesCount = v + ms.orig.DroppedAttributesCount = v } // Events returns the Events associated with this Span. func (ms Span) Events() SpanEventSlice { - return SpanEventSlice(internal.NewSpanEventSlice(&ms.getOrig().Events)) + return newSpanEventSlice(&ms.orig.Events) } // DroppedEventsCount returns the droppedeventscount associated with this Span. func (ms Span) DroppedEventsCount() uint32 { - return ms.getOrig().DroppedEventsCount + return ms.orig.DroppedEventsCount } // SetDroppedEventsCount replaces the droppedeventscount associated with this Span. func (ms Span) SetDroppedEventsCount(v uint32) { - ms.getOrig().DroppedEventsCount = v + ms.orig.DroppedEventsCount = v } // Links returns the Links associated with this Span. func (ms Span) Links() SpanLinkSlice { - return SpanLinkSlice(internal.NewSpanLinkSlice(&ms.getOrig().Links)) + return newSpanLinkSlice(&ms.orig.Links) } // DroppedLinksCount returns the droppedlinkscount associated with this Span. func (ms Span) DroppedLinksCount() uint32 { - return ms.getOrig().DroppedLinksCount + return ms.orig.DroppedLinksCount } // SetDroppedLinksCount replaces the droppedlinkscount associated with this Span. func (ms Span) SetDroppedLinksCount(v uint32) { - ms.getOrig().DroppedLinksCount = v + ms.orig.DroppedLinksCount = v } // Status returns the status associated with this Span. func (ms Span) Status() Status { - return Status(internal.NewStatus(&ms.getOrig().Status)) + return newStatus(&ms.orig.Status) } // CopyTo copies all properties from the current struct overriding the destination. @@ -727,14 +712,12 @@ func (ms Span) CopyTo(dest Span) { // // Must use NewSpanEventSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type SpanEventSlice internal.SpanEventSlice - -func newSpanEventSlice(orig *[]*otlptrace.Span_Event) SpanEventSlice { - return SpanEventSlice(internal.NewSpanEventSlice(orig)) +type SpanEventSlice struct { + orig *[]*otlptrace.Span_Event } -func (ms SpanEventSlice) getOrig() *[]*otlptrace.Span_Event { - return internal.GetOrigSpanEventSlice(internal.SpanEventSlice(ms)) +func newSpanEventSlice(orig *[]*otlptrace.Span_Event) SpanEventSlice { + return SpanEventSlice{orig} } // NewSpanEventSlice creates a SpanEventSlice with 0 elements. @@ -748,7 +731,7 @@ func NewSpanEventSlice() SpanEventSlice { // // Returns "0" for a newly instance created with "NewSpanEventSlice()". func (es SpanEventSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -760,27 +743,27 @@ func (es SpanEventSlice) Len() int { // ... // Do something with the element // } func (es SpanEventSlice) At(ix int) SpanEvent { - return newSpanEvent((*es.getOrig())[ix]) + return newSpanEvent((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newSpanEvent((*es.getOrig())[i]).CopyTo(newSpanEvent((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newSpanEvent((*es.orig)[i]).CopyTo(newSpanEvent((*dest.orig)[i])) } return } origs := make([]otlptrace.Span_Event, srcLen) wrappers := make([]*otlptrace.Span_Event, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newSpanEvent((*es.getOrig())[i]).CopyTo(newSpanEvent(wrappers[i])) + newSpanEvent((*es.orig)[i]).CopyTo(newSpanEvent(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -796,20 +779,20 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { // // Here should set all the values for e. // } func (es SpanEventSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlptrace.Span_Event, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlptrace.Span_Event, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty SpanEvent. // It returns the newly added SpanEvent. func (es SpanEventSlice) AppendEmpty() SpanEvent { - *es.getOrig() = append(*es.getOrig(), &otlptrace.Span_Event{}) + *es.orig = append(*es.orig, &otlptrace.Span_Event{}) return es.At(es.Len() - 1) } @@ -817,26 +800,26 @@ func (es SpanEventSlice) AppendEmpty() SpanEvent { // provided less function so that two instances of SpanEventSlice // can be compared. func (es SpanEventSlice) Sort(less func(a, b SpanEvent) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanEventSlice) MoveAndAppendTo(dest SpanEventSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es SpanEventSlice) RemoveIf(f func(SpanEvent) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -845,11 +828,11 @@ func (es SpanEventSlice) RemoveIf(f func(SpanEvent) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // SpanEvent is a time-stamped annotation of the span, consisting of user-supplied @@ -860,15 +843,12 @@ func (es SpanEventSlice) RemoveIf(f func(SpanEvent) bool) { // // Must use NewSpanEvent function to create new instances. // Important: zero-initialized instance is not valid for use. - -type SpanEvent internal.SpanEvent - -func newSpanEvent(orig *otlptrace.Span_Event) SpanEvent { - return SpanEvent(internal.NewSpanEvent(orig)) +type SpanEvent struct { + orig *otlptrace.Span_Event } -func (ms SpanEvent) getOrig() *otlptrace.Span_Event { - return internal.GetOrigSpanEvent(internal.SpanEvent(ms)) +func newSpanEvent(orig *otlptrace.Span_Event) SpanEvent { + return SpanEvent{orig} } // NewSpanEvent creates a new empty SpanEvent. @@ -882,43 +862,43 @@ func NewSpanEvent() SpanEvent { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms SpanEvent) MoveTo(dest SpanEvent) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlptrace.Span_Event{} + *dest.orig = *ms.orig + *ms.orig = otlptrace.Span_Event{} } // Timestamp returns the timestamp associated with this SpanEvent. func (ms SpanEvent) Timestamp() pcommon.Timestamp { - return pcommon.Timestamp(ms.getOrig().TimeUnixNano) + return pcommon.Timestamp(ms.orig.TimeUnixNano) } // SetTimestamp replaces the timestamp associated with this SpanEvent. func (ms SpanEvent) SetTimestamp(v pcommon.Timestamp) { - ms.getOrig().TimeUnixNano = uint64(v) + ms.orig.TimeUnixNano = uint64(v) } // Name returns the name associated with this SpanEvent. func (ms SpanEvent) Name() string { - return ms.getOrig().Name + return ms.orig.Name } // SetName replaces the name associated with this SpanEvent. func (ms SpanEvent) SetName(v string) { - ms.getOrig().Name = v + ms.orig.Name = v } // Attributes returns the Attributes associated with this SpanEvent. func (ms SpanEvent) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // DroppedAttributesCount returns the droppedattributescount associated with this SpanEvent. func (ms SpanEvent) DroppedAttributesCount() uint32 { - return ms.getOrig().DroppedAttributesCount + return ms.orig.DroppedAttributesCount } // SetDroppedAttributesCount replaces the droppedattributescount associated with this SpanEvent. func (ms SpanEvent) SetDroppedAttributesCount(v uint32) { - ms.getOrig().DroppedAttributesCount = v + ms.orig.DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. @@ -936,14 +916,12 @@ func (ms SpanEvent) CopyTo(dest SpanEvent) { // // Must use NewSpanLinkSlice function to create new instances. // Important: zero-initialized instance is not valid for use. -type SpanLinkSlice internal.SpanLinkSlice - -func newSpanLinkSlice(orig *[]*otlptrace.Span_Link) SpanLinkSlice { - return SpanLinkSlice(internal.NewSpanLinkSlice(orig)) +type SpanLinkSlice struct { + orig *[]*otlptrace.Span_Link } -func (ms SpanLinkSlice) getOrig() *[]*otlptrace.Span_Link { - return internal.GetOrigSpanLinkSlice(internal.SpanLinkSlice(ms)) +func newSpanLinkSlice(orig *[]*otlptrace.Span_Link) SpanLinkSlice { + return SpanLinkSlice{orig} } // NewSpanLinkSlice creates a SpanLinkSlice with 0 elements. @@ -957,7 +935,7 @@ func NewSpanLinkSlice() SpanLinkSlice { // // Returns "0" for a newly instance created with "NewSpanLinkSlice()". func (es SpanLinkSlice) Len() int { - return len(*es.getOrig()) + return len(*es.orig) } // At returns the element at the given index. @@ -969,27 +947,27 @@ func (es SpanLinkSlice) Len() int { // ... // Do something with the element // } func (es SpanLinkSlice) At(ix int) SpanLink { - return newSpanLink((*es.getOrig())[ix]) + return newSpanLink((*es.orig)[ix]) } // CopyTo copies all elements from the current slice overriding the destination. func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { srcLen := es.Len() - destCap := cap(*dest.getOrig()) + destCap := cap(*dest.orig) if srcLen <= destCap { - (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] - for i := range *es.getOrig() { - newSpanLink((*es.getOrig())[i]).CopyTo(newSpanLink((*dest.getOrig())[i])) + (*dest.orig) = (*dest.orig)[:srcLen:destCap] + for i := range *es.orig { + newSpanLink((*es.orig)[i]).CopyTo(newSpanLink((*dest.orig)[i])) } return } origs := make([]otlptrace.Span_Link, srcLen) wrappers := make([]*otlptrace.Span_Link, srcLen) - for i := range *es.getOrig() { + for i := range *es.orig { wrappers[i] = &origs[i] - newSpanLink((*es.getOrig())[i]).CopyTo(newSpanLink(wrappers[i])) + newSpanLink((*es.orig)[i]).CopyTo(newSpanLink(wrappers[i])) } - *dest.getOrig() = wrappers + *dest.orig = wrappers } // EnsureCapacity is an operation that ensures the slice has at least the specified capacity. @@ -1005,20 +983,20 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { // // Here should set all the values for e. // } func (es SpanLinkSlice) EnsureCapacity(newCap int) { - oldCap := cap(*es.getOrig()) + oldCap := cap(*es.orig) if newCap <= oldCap { return } - newOrig := make([]*otlptrace.Span_Link, len(*es.getOrig()), newCap) - copy(newOrig, *es.getOrig()) - *es.getOrig() = newOrig + newOrig := make([]*otlptrace.Span_Link, len(*es.orig), newCap) + copy(newOrig, *es.orig) + *es.orig = newOrig } // AppendEmpty will append to the end of the slice an empty SpanLink. // It returns the newly added SpanLink. func (es SpanLinkSlice) AppendEmpty() SpanLink { - *es.getOrig() = append(*es.getOrig(), &otlptrace.Span_Link{}) + *es.orig = append(*es.orig, &otlptrace.Span_Link{}) return es.At(es.Len() - 1) } @@ -1026,26 +1004,26 @@ func (es SpanLinkSlice) AppendEmpty() SpanLink { // provided less function so that two instances of SpanLinkSlice // can be compared. func (es SpanLinkSlice) Sort(less func(a, b SpanLink) bool) { - sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanLinkSlice) MoveAndAppendTo(dest SpanLinkSlice) { - if *dest.getOrig() == nil { + if *dest.orig == nil { // We can simply move the entire vector and avoid any allocations. - *dest.getOrig() = *es.getOrig() + *dest.orig = *es.orig } else { - *dest.getOrig() = append(*dest.getOrig(), *es.getOrig()...) + *dest.orig = append(*dest.orig, *es.orig...) } - *es.getOrig() = nil + *es.orig = nil } // RemoveIf calls f sequentially for each element present in the slice. // If f returns true, the element is removed from the slice. func (es SpanLinkSlice) RemoveIf(f func(SpanLink) bool) { newLen := 0 - for i := 0; i < len(*es.getOrig()); i++ { + for i := 0; i < len(*es.orig); i++ { if f(es.At(i)) { continue } @@ -1054,11 +1032,11 @@ func (es SpanLinkSlice) RemoveIf(f func(SpanLink) bool) { newLen++ continue } - (*es.getOrig())[newLen] = (*es.getOrig())[i] + (*es.orig)[newLen] = (*es.orig)[i] newLen++ } // TODO: Prevent memory leak by erasing truncated values. - *es.getOrig() = (*es.getOrig())[:newLen] + *es.orig = (*es.orig)[:newLen] } // SpanLink is a pointer from the current span to another span in the same trace or in a @@ -1070,15 +1048,12 @@ func (es SpanLinkSlice) RemoveIf(f func(SpanLink) bool) { // // Must use NewSpanLink function to create new instances. // Important: zero-initialized instance is not valid for use. - -type SpanLink internal.SpanLink - -func newSpanLink(orig *otlptrace.Span_Link) SpanLink { - return SpanLink(internal.NewSpanLink(orig)) +type SpanLink struct { + orig *otlptrace.Span_Link } -func (ms SpanLink) getOrig() *otlptrace.Span_Link { - return internal.GetOrigSpanLink(internal.SpanLink(ms)) +func newSpanLink(orig *otlptrace.Span_Link) SpanLink { + return SpanLink{orig} } // NewSpanLink creates a new empty SpanLink. @@ -1092,48 +1067,48 @@ func NewSpanLink() SpanLink { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms SpanLink) MoveTo(dest SpanLink) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlptrace.Span_Link{} + *dest.orig = *ms.orig + *ms.orig = otlptrace.Span_Link{} } // TraceID returns the traceid associated with this SpanLink. func (ms SpanLink) TraceID() pcommon.TraceID { - return pcommon.TraceID(ms.getOrig().TraceId) + return pcommon.TraceID(ms.orig.TraceId) } // SetTraceID replaces the traceid associated with this SpanLink. func (ms SpanLink) SetTraceID(v pcommon.TraceID) { - ms.getOrig().TraceId = data.TraceID(v) + ms.orig.TraceId = data.TraceID(v) } // SpanID returns the spanid associated with this SpanLink. func (ms SpanLink) SpanID() pcommon.SpanID { - return pcommon.SpanID(ms.getOrig().SpanId) + return pcommon.SpanID(ms.orig.SpanId) } // SetSpanID replaces the spanid associated with this SpanLink. func (ms SpanLink) SetSpanID(v pcommon.SpanID) { - ms.getOrig().SpanId = data.SpanID(v) + ms.orig.SpanId = data.SpanID(v) } // TraceState returns the tracestate associated with this SpanLink. func (ms SpanLink) TraceState() pcommon.TraceState { - return pcommon.TraceState(internal.NewTraceState(&ms.getOrig().TraceState)) + return pcommon.TraceState(internal.NewTraceState(&ms.orig.TraceState)) } // Attributes returns the Attributes associated with this SpanLink. func (ms SpanLink) Attributes() pcommon.Map { - return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) + return pcommon.Map(internal.NewMap(&ms.orig.Attributes)) } // DroppedAttributesCount returns the droppedattributescount associated with this SpanLink. func (ms SpanLink) DroppedAttributesCount() uint32 { - return ms.getOrig().DroppedAttributesCount + return ms.orig.DroppedAttributesCount } // SetDroppedAttributesCount replaces the droppedattributescount associated with this SpanLink. func (ms SpanLink) SetDroppedAttributesCount(v uint32) { - ms.getOrig().DroppedAttributesCount = v + ms.orig.DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. @@ -1153,15 +1128,12 @@ func (ms SpanLink) CopyTo(dest SpanLink) { // // Must use NewStatus function to create new instances. // Important: zero-initialized instance is not valid for use. - -type Status internal.Status - -func newStatus(orig *otlptrace.Status) Status { - return Status(internal.NewStatus(orig)) +type Status struct { + orig *otlptrace.Status } -func (ms Status) getOrig() *otlptrace.Status { - return internal.GetOrigStatus(internal.Status(ms)) +func newStatus(orig *otlptrace.Status) Status { + return Status{orig} } // NewStatus creates a new empty Status. @@ -1175,28 +1147,28 @@ func NewStatus() Status { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms Status) MoveTo(dest Status) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlptrace.Status{} + *dest.orig = *ms.orig + *ms.orig = otlptrace.Status{} } // Code returns the code associated with this Status. func (ms Status) Code() StatusCode { - return StatusCode(ms.getOrig().Code) + return StatusCode(ms.orig.Code) } // SetCode replaces the code associated with this Status. func (ms Status) SetCode(v StatusCode) { - ms.getOrig().Code = otlptrace.Status_StatusCode(v) + ms.orig.Code = otlptrace.Status_StatusCode(v) } // Message returns the message associated with this Status. func (ms Status) Message() string { - return ms.getOrig().Message + return ms.orig.Message } // SetMessage replaces the message associated with this Status. func (ms Status) SetMessage(v string) { - ms.getOrig().Message = v + ms.orig.Message = v } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/ptrace/generated_traces_test.go b/pdata/ptrace/generated_traces_test.go index 51abb471ebe..7653bc8ffa9 100644 --- a/pdata/ptrace/generated_traces_test.go +++ b/pdata/ptrace/generated_traces_test.go @@ -36,12 +36,12 @@ func TestResourceSpansSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newResourceSpans(&otlptrace.ResourceSpans{}) - testVal := ResourceSpans(internal.GenerateTestResourceSpans()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestResourceSpans() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestResourceSpans(internal.ResourceSpans(el)) + fillTestResourceSpans(el) assert.Equal(t, testVal, el) } } @@ -53,28 +53,28 @@ func TestResourceSpansSlice_CopyTo(t *testing.T) { assert.Equal(t, NewResourceSpansSlice(), dest) // Test CopyTo larger slice - ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()).CopyTo(dest) - assert.Equal(t, ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()), dest) + generateTestResourceSpansSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceSpansSlice(), dest) // Test CopyTo same size slice - ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()).CopyTo(dest) - assert.Equal(t, ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()), dest) + generateTestResourceSpansSlice().CopyTo(dest) + assert.Equal(t, generateTestResourceSpansSlice(), dest) } func TestResourceSpansSlice_EnsureCapacity(t *testing.T) { - es := ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()) + es := generateTestResourceSpansSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlptrace.ResourceSpans]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlptrace.ResourceSpans]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -83,36 +83,36 @@ func TestResourceSpansSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.ResourceSpans]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlptrace.ResourceSpans]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestResourceSpansSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()) + expectedSlice := generateTestResourceSpansSlice() dest := NewResourceSpansSlice() - src := ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()) + src := generateTestResourceSpansSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()), dest) + assert.Equal(t, generateTestResourceSpansSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()), dest) + assert.Equal(t, generateTestResourceSpansSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()).MoveAndAppendTo(dest) + generateTestResourceSpansSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -129,7 +129,7 @@ func TestResourceSpansSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()) + filtered := generateTestResourceSpansSlice() pos := 0 filtered.RemoveIf(func(el ResourceSpans) bool { pos++ @@ -138,12 +138,26 @@ func TestResourceSpansSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestResourceSpansSlice() ResourceSpansSlice { + tv := NewResourceSpansSlice() + fillTestResourceSpansSlice(tv) + return tv +} + +func fillTestResourceSpansSlice(tv ResourceSpansSlice) { + *tv.orig = make([]*otlptrace.ResourceSpans, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlptrace.ResourceSpans{} + fillTestResourceSpans(newResourceSpans((*tv.orig)[i])) + } +} + func TestResourceSpans_MoveTo(t *testing.T) { - ms := ResourceSpans(internal.GenerateTestResourceSpans()) + ms := generateTestResourceSpans() dest := NewResourceSpans() ms.MoveTo(dest) assert.Equal(t, NewResourceSpans(), ms) - assert.Equal(t, ResourceSpans(internal.GenerateTestResourceSpans()), dest) + assert.Equal(t, generateTestResourceSpans(), dest) } func TestResourceSpans_CopyTo(t *testing.T) { @@ -151,7 +165,7 @@ func TestResourceSpans_CopyTo(t *testing.T) { orig := NewResourceSpans() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ResourceSpans(internal.GenerateTestResourceSpans()) + orig = generateTestResourceSpans() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -172,8 +186,20 @@ func TestResourceSpans_SchemaUrl(t *testing.T) { func TestResourceSpans_ScopeSpans(t *testing.T) { ms := NewResourceSpans() assert.Equal(t, NewScopeSpansSlice(), ms.ScopeSpans()) - internal.FillTestScopeSpansSlice(internal.ScopeSpansSlice(ms.ScopeSpans())) - assert.Equal(t, ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()), ms.ScopeSpans()) + fillTestScopeSpansSlice(ms.ScopeSpans()) + assert.Equal(t, generateTestScopeSpansSlice(), ms.ScopeSpans()) +} + +func generateTestResourceSpans() ResourceSpans { + tv := NewResourceSpans() + fillTestResourceSpans(tv) + return tv +} + +func fillTestResourceSpans(tv ResourceSpans) { + internal.FillTestResource(internal.NewResource(&tv.orig.Resource)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestScopeSpansSlice(newScopeSpansSlice(&tv.orig.ScopeSpans)) } func TestScopeSpansSlice(t *testing.T) { @@ -184,12 +210,12 @@ func TestScopeSpansSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newScopeSpans(&otlptrace.ScopeSpans{}) - testVal := ScopeSpans(internal.GenerateTestScopeSpans()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestScopeSpans() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestScopeSpans(internal.ScopeSpans(el)) + fillTestScopeSpans(el) assert.Equal(t, testVal, el) } } @@ -201,28 +227,28 @@ func TestScopeSpansSlice_CopyTo(t *testing.T) { assert.Equal(t, NewScopeSpansSlice(), dest) // Test CopyTo larger slice - ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()).CopyTo(dest) - assert.Equal(t, ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()), dest) + generateTestScopeSpansSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeSpansSlice(), dest) // Test CopyTo same size slice - ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()).CopyTo(dest) - assert.Equal(t, ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()), dest) + generateTestScopeSpansSlice().CopyTo(dest) + assert.Equal(t, generateTestScopeSpansSlice(), dest) } func TestScopeSpansSlice_EnsureCapacity(t *testing.T) { - es := ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()) + es := generateTestScopeSpansSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlptrace.ScopeSpans]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlptrace.ScopeSpans]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -231,36 +257,36 @@ func TestScopeSpansSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.ScopeSpans]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlptrace.ScopeSpans]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestScopeSpansSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()) + expectedSlice := generateTestScopeSpansSlice() dest := NewScopeSpansSlice() - src := ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()) + src := generateTestScopeSpansSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()), dest) + assert.Equal(t, generateTestScopeSpansSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()), dest) + assert.Equal(t, generateTestScopeSpansSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()).MoveAndAppendTo(dest) + generateTestScopeSpansSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -277,7 +303,7 @@ func TestScopeSpansSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := ScopeSpansSlice(internal.GenerateTestScopeSpansSlice()) + filtered := generateTestScopeSpansSlice() pos := 0 filtered.RemoveIf(func(el ScopeSpans) bool { pos++ @@ -286,12 +312,26 @@ func TestScopeSpansSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestScopeSpansSlice() ScopeSpansSlice { + tv := NewScopeSpansSlice() + fillTestScopeSpansSlice(tv) + return tv +} + +func fillTestScopeSpansSlice(tv ScopeSpansSlice) { + *tv.orig = make([]*otlptrace.ScopeSpans, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlptrace.ScopeSpans{} + fillTestScopeSpans(newScopeSpans((*tv.orig)[i])) + } +} + func TestScopeSpans_MoveTo(t *testing.T) { - ms := ScopeSpans(internal.GenerateTestScopeSpans()) + ms := generateTestScopeSpans() dest := NewScopeSpans() ms.MoveTo(dest) assert.Equal(t, NewScopeSpans(), ms) - assert.Equal(t, ScopeSpans(internal.GenerateTestScopeSpans()), dest) + assert.Equal(t, generateTestScopeSpans(), dest) } func TestScopeSpans_CopyTo(t *testing.T) { @@ -299,7 +339,7 @@ func TestScopeSpans_CopyTo(t *testing.T) { orig := NewScopeSpans() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ScopeSpans(internal.GenerateTestScopeSpans()) + orig = generateTestScopeSpans() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -320,8 +360,20 @@ func TestScopeSpans_SchemaUrl(t *testing.T) { func TestScopeSpans_Spans(t *testing.T) { ms := NewScopeSpans() assert.Equal(t, NewSpanSlice(), ms.Spans()) - internal.FillTestSpanSlice(internal.SpanSlice(ms.Spans())) - assert.Equal(t, SpanSlice(internal.GenerateTestSpanSlice()), ms.Spans()) + fillTestSpanSlice(ms.Spans()) + assert.Equal(t, generateTestSpanSlice(), ms.Spans()) +} + +func generateTestScopeSpans() ScopeSpans { + tv := NewScopeSpans() + fillTestScopeSpans(tv) + return tv +} + +func fillTestScopeSpans(tv ScopeSpans) { + internal.FillTestInstrumentationScope(internal.NewInstrumentationScope(&tv.orig.Scope)) + tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" + fillTestSpanSlice(newSpanSlice(&tv.orig.Spans)) } func TestSpanSlice(t *testing.T) { @@ -332,12 +384,12 @@ func TestSpanSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newSpan(&otlptrace.Span{}) - testVal := Span(internal.GenerateTestSpan()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestSpan() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSpan(internal.Span(el)) + fillTestSpan(el) assert.Equal(t, testVal, el) } } @@ -349,28 +401,28 @@ func TestSpanSlice_CopyTo(t *testing.T) { assert.Equal(t, NewSpanSlice(), dest) // Test CopyTo larger slice - SpanSlice(internal.GenerateTestSpanSlice()).CopyTo(dest) - assert.Equal(t, SpanSlice(internal.GenerateTestSpanSlice()), dest) + generateTestSpanSlice().CopyTo(dest) + assert.Equal(t, generateTestSpanSlice(), dest) // Test CopyTo same size slice - SpanSlice(internal.GenerateTestSpanSlice()).CopyTo(dest) - assert.Equal(t, SpanSlice(internal.GenerateTestSpanSlice()), dest) + generateTestSpanSlice().CopyTo(dest) + assert.Equal(t, generateTestSpanSlice(), dest) } func TestSpanSlice_EnsureCapacity(t *testing.T) { - es := SpanSlice(internal.GenerateTestSpanSlice()) + es := generateTestSpanSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlptrace.Span]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlptrace.Span]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -379,36 +431,36 @@ func TestSpanSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.Span]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlptrace.Span]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestSpanSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := SpanSlice(internal.GenerateTestSpanSlice()) + expectedSlice := generateTestSpanSlice() dest := NewSpanSlice() - src := SpanSlice(internal.GenerateTestSpanSlice()) + src := generateTestSpanSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, SpanSlice(internal.GenerateTestSpanSlice()), dest) + assert.Equal(t, generateTestSpanSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, SpanSlice(internal.GenerateTestSpanSlice()), dest) + assert.Equal(t, generateTestSpanSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - SpanSlice(internal.GenerateTestSpanSlice()).MoveAndAppendTo(dest) + generateTestSpanSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -425,7 +477,7 @@ func TestSpanSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := SpanSlice(internal.GenerateTestSpanSlice()) + filtered := generateTestSpanSlice() pos := 0 filtered.RemoveIf(func(el Span) bool { pos++ @@ -434,12 +486,26 @@ func TestSpanSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestSpanSlice() SpanSlice { + tv := NewSpanSlice() + fillTestSpanSlice(tv) + return tv +} + +func fillTestSpanSlice(tv SpanSlice) { + *tv.orig = make([]*otlptrace.Span, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlptrace.Span{} + fillTestSpan(newSpan((*tv.orig)[i])) + } +} + func TestSpan_MoveTo(t *testing.T) { - ms := Span(internal.GenerateTestSpan()) + ms := generateTestSpan() dest := NewSpan() ms.MoveTo(dest) assert.Equal(t, NewSpan(), ms) - assert.Equal(t, Span(internal.GenerateTestSpan()), dest) + assert.Equal(t, generateTestSpan(), dest) } func TestSpan_CopyTo(t *testing.T) { @@ -447,7 +513,7 @@ func TestSpan_CopyTo(t *testing.T) { orig := NewSpan() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Span(internal.GenerateTestSpan()) + orig = generateTestSpan() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -530,8 +596,8 @@ func TestSpan_DroppedAttributesCount(t *testing.T) { func TestSpan_Events(t *testing.T) { ms := NewSpan() assert.Equal(t, NewSpanEventSlice(), ms.Events()) - internal.FillTestSpanEventSlice(internal.SpanEventSlice(ms.Events())) - assert.Equal(t, SpanEventSlice(internal.GenerateTestSpanEventSlice()), ms.Events()) + fillTestSpanEventSlice(ms.Events()) + assert.Equal(t, generateTestSpanEventSlice(), ms.Events()) } func TestSpan_DroppedEventsCount(t *testing.T) { @@ -544,8 +610,8 @@ func TestSpan_DroppedEventsCount(t *testing.T) { func TestSpan_Links(t *testing.T) { ms := NewSpan() assert.Equal(t, NewSpanLinkSlice(), ms.Links()) - internal.FillTestSpanLinkSlice(internal.SpanLinkSlice(ms.Links())) - assert.Equal(t, SpanLinkSlice(internal.GenerateTestSpanLinkSlice()), ms.Links()) + fillTestSpanLinkSlice(ms.Links()) + assert.Equal(t, generateTestSpanLinkSlice(), ms.Links()) } func TestSpan_DroppedLinksCount(t *testing.T) { @@ -557,8 +623,32 @@ func TestSpan_DroppedLinksCount(t *testing.T) { func TestSpan_Status(t *testing.T) { ms := NewSpan() - internal.FillTestStatus(internal.Status(ms.Status())) - assert.Equal(t, Status(internal.GenerateTestStatus()), ms.Status()) + fillTestStatus(ms.Status()) + assert.Equal(t, generateTestStatus(), ms.Status()) +} + +func generateTestSpan() Span { + tv := NewSpan() + fillTestSpan(tv) + return tv +} + +func fillTestSpan(tv Span) { + tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) + tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) + internal.FillTestTraceState(internal.NewTraceState(&tv.orig.TraceState)) + tv.orig.ParentSpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) + tv.orig.Name = "test_name" + tv.orig.Kind = otlptrace.Span_SpanKind(3) + tv.orig.StartTimeUnixNano = 1234567890 + tv.orig.EndTimeUnixNano = 1234567890 + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.DroppedAttributesCount = uint32(17) + fillTestSpanEventSlice(newSpanEventSlice(&tv.orig.Events)) + tv.orig.DroppedEventsCount = uint32(17) + fillTestSpanLinkSlice(newSpanLinkSlice(&tv.orig.Links)) + tv.orig.DroppedLinksCount = uint32(17) + fillTestStatus(newStatus(&tv.orig.Status)) } func TestSpanEventSlice(t *testing.T) { @@ -569,12 +659,12 @@ func TestSpanEventSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newSpanEvent(&otlptrace.Span_Event{}) - testVal := SpanEvent(internal.GenerateTestSpanEvent()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestSpanEvent() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSpanEvent(internal.SpanEvent(el)) + fillTestSpanEvent(el) assert.Equal(t, testVal, el) } } @@ -586,28 +676,28 @@ func TestSpanEventSlice_CopyTo(t *testing.T) { assert.Equal(t, NewSpanEventSlice(), dest) // Test CopyTo larger slice - SpanEventSlice(internal.GenerateTestSpanEventSlice()).CopyTo(dest) - assert.Equal(t, SpanEventSlice(internal.GenerateTestSpanEventSlice()), dest) + generateTestSpanEventSlice().CopyTo(dest) + assert.Equal(t, generateTestSpanEventSlice(), dest) // Test CopyTo same size slice - SpanEventSlice(internal.GenerateTestSpanEventSlice()).CopyTo(dest) - assert.Equal(t, SpanEventSlice(internal.GenerateTestSpanEventSlice()), dest) + generateTestSpanEventSlice().CopyTo(dest) + assert.Equal(t, generateTestSpanEventSlice(), dest) } func TestSpanEventSlice_EnsureCapacity(t *testing.T) { - es := SpanEventSlice(internal.GenerateTestSpanEventSlice()) + es := generateTestSpanEventSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlptrace.Span_Event]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlptrace.Span_Event]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -616,36 +706,36 @@ func TestSpanEventSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.Span_Event]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlptrace.Span_Event]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestSpanEventSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := SpanEventSlice(internal.GenerateTestSpanEventSlice()) + expectedSlice := generateTestSpanEventSlice() dest := NewSpanEventSlice() - src := SpanEventSlice(internal.GenerateTestSpanEventSlice()) + src := generateTestSpanEventSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, SpanEventSlice(internal.GenerateTestSpanEventSlice()), dest) + assert.Equal(t, generateTestSpanEventSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, SpanEventSlice(internal.GenerateTestSpanEventSlice()), dest) + assert.Equal(t, generateTestSpanEventSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - SpanEventSlice(internal.GenerateTestSpanEventSlice()).MoveAndAppendTo(dest) + generateTestSpanEventSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -662,7 +752,7 @@ func TestSpanEventSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := SpanEventSlice(internal.GenerateTestSpanEventSlice()) + filtered := generateTestSpanEventSlice() pos := 0 filtered.RemoveIf(func(el SpanEvent) bool { pos++ @@ -671,12 +761,26 @@ func TestSpanEventSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestSpanEventSlice() SpanEventSlice { + tv := NewSpanEventSlice() + fillTestSpanEventSlice(tv) + return tv +} + +func fillTestSpanEventSlice(tv SpanEventSlice) { + *tv.orig = make([]*otlptrace.Span_Event, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlptrace.Span_Event{} + fillTestSpanEvent(newSpanEvent((*tv.orig)[i])) + } +} + func TestSpanEvent_MoveTo(t *testing.T) { - ms := SpanEvent(internal.GenerateTestSpanEvent()) + ms := generateTestSpanEvent() dest := NewSpanEvent() ms.MoveTo(dest) assert.Equal(t, NewSpanEvent(), ms) - assert.Equal(t, SpanEvent(internal.GenerateTestSpanEvent()), dest) + assert.Equal(t, generateTestSpanEvent(), dest) } func TestSpanEvent_CopyTo(t *testing.T) { @@ -684,7 +788,7 @@ func TestSpanEvent_CopyTo(t *testing.T) { orig := NewSpanEvent() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SpanEvent(internal.GenerateTestSpanEvent()) + orig = generateTestSpanEvent() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -718,6 +822,19 @@ func TestSpanEvent_DroppedAttributesCount(t *testing.T) { assert.Equal(t, uint32(17), ms.DroppedAttributesCount()) } +func generateTestSpanEvent() SpanEvent { + tv := NewSpanEvent() + fillTestSpanEvent(tv) + return tv +} + +func fillTestSpanEvent(tv SpanEvent) { + tv.orig.TimeUnixNano = 1234567890 + tv.orig.Name = "test_name" + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.DroppedAttributesCount = uint32(17) +} + func TestSpanLinkSlice(t *testing.T) { es := NewSpanLinkSlice() assert.Equal(t, 0, es.Len()) @@ -726,12 +843,12 @@ func TestSpanLinkSlice(t *testing.T) { es.EnsureCapacity(7) emptyVal := newSpanLink(&otlptrace.Span_Link{}) - testVal := SpanLink(internal.GenerateTestSpanLink()) - assert.Equal(t, 7, cap(*es.getOrig())) + testVal := generateTestSpanLink() + assert.Equal(t, 7, cap(*es.orig)) for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSpanLink(internal.SpanLink(el)) + fillTestSpanLink(el) assert.Equal(t, testVal, el) } } @@ -743,28 +860,28 @@ func TestSpanLinkSlice_CopyTo(t *testing.T) { assert.Equal(t, NewSpanLinkSlice(), dest) // Test CopyTo larger slice - SpanLinkSlice(internal.GenerateTestSpanLinkSlice()).CopyTo(dest) - assert.Equal(t, SpanLinkSlice(internal.GenerateTestSpanLinkSlice()), dest) + generateTestSpanLinkSlice().CopyTo(dest) + assert.Equal(t, generateTestSpanLinkSlice(), dest) // Test CopyTo same size slice - SpanLinkSlice(internal.GenerateTestSpanLinkSlice()).CopyTo(dest) - assert.Equal(t, SpanLinkSlice(internal.GenerateTestSpanLinkSlice()), dest) + generateTestSpanLinkSlice().CopyTo(dest) + assert.Equal(t, generateTestSpanLinkSlice(), dest) } func TestSpanLinkSlice_EnsureCapacity(t *testing.T) { - es := SpanLinkSlice(internal.GenerateTestSpanLinkSlice()) + es := generateTestSpanLinkSlice() // Test ensure smaller capacity. const ensureSmallLen = 4 expectedEs := make(map[*otlptrace.Span_Link]bool) for i := 0; i < es.Len(); i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, es.Len(), len(expectedEs)) es.EnsureCapacity(ensureSmallLen) assert.Less(t, ensureSmallLen, es.Len()) foundEs := make(map[*otlptrace.Span_Link]bool, es.Len()) for i := 0; i < es.Len(); i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) @@ -773,36 +890,36 @@ func TestSpanLinkSlice_EnsureCapacity(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.Span_Link]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[es.At(i).getOrig()] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.EnsureCapacity(ensureLargeLen) - assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) + assert.Equal(t, ensureLargeLen, cap(*es.orig)) foundEs = make(map[*otlptrace.Span_Link]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[es.At(i).getOrig()] = true + foundEs[es.At(i).orig] = true } assert.Equal(t, expectedEs, foundEs) } func TestSpanLinkSlice_MoveAndAppendTo(t *testing.T) { // Test MoveAndAppendTo to empty - expectedSlice := SpanLinkSlice(internal.GenerateTestSpanLinkSlice()) + expectedSlice := generateTestSpanLinkSlice() dest := NewSpanLinkSlice() - src := SpanLinkSlice(internal.GenerateTestSpanLinkSlice()) + src := generateTestSpanLinkSlice() src.MoveAndAppendTo(dest) - assert.Equal(t, SpanLinkSlice(internal.GenerateTestSpanLinkSlice()), dest) + assert.Equal(t, generateTestSpanLinkSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo empty slice src.MoveAndAppendTo(dest) - assert.Equal(t, SpanLinkSlice(internal.GenerateTestSpanLinkSlice()), dest) + assert.Equal(t, generateTestSpanLinkSlice(), dest) assert.Equal(t, 0, src.Len()) assert.Equal(t, expectedSlice.Len(), dest.Len()) // Test MoveAndAppendTo not empty slice - SpanLinkSlice(internal.GenerateTestSpanLinkSlice()).MoveAndAppendTo(dest) + generateTestSpanLinkSlice().MoveAndAppendTo(dest) assert.Equal(t, 2*expectedSlice.Len(), dest.Len()) for i := 0; i < expectedSlice.Len(); i++ { assert.Equal(t, expectedSlice.At(i), dest.At(i)) @@ -819,7 +936,7 @@ func TestSpanLinkSlice_RemoveIf(t *testing.T) { }) // Test RemoveIf - filtered := SpanLinkSlice(internal.GenerateTestSpanLinkSlice()) + filtered := generateTestSpanLinkSlice() pos := 0 filtered.RemoveIf(func(el SpanLink) bool { pos++ @@ -828,12 +945,26 @@ func TestSpanLinkSlice_RemoveIf(t *testing.T) { assert.Equal(t, 5, filtered.Len()) } +func generateTestSpanLinkSlice() SpanLinkSlice { + tv := NewSpanLinkSlice() + fillTestSpanLinkSlice(tv) + return tv +} + +func fillTestSpanLinkSlice(tv SpanLinkSlice) { + *tv.orig = make([]*otlptrace.Span_Link, 7) + for i := 0; i < 7; i++ { + (*tv.orig)[i] = &otlptrace.Span_Link{} + fillTestSpanLink(newSpanLink((*tv.orig)[i])) + } +} + func TestSpanLink_MoveTo(t *testing.T) { - ms := SpanLink(internal.GenerateTestSpanLink()) + ms := generateTestSpanLink() dest := NewSpanLink() ms.MoveTo(dest) assert.Equal(t, NewSpanLink(), ms) - assert.Equal(t, SpanLink(internal.GenerateTestSpanLink()), dest) + assert.Equal(t, generateTestSpanLink(), dest) } func TestSpanLink_CopyTo(t *testing.T) { @@ -841,7 +972,7 @@ func TestSpanLink_CopyTo(t *testing.T) { orig := NewSpanLink() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SpanLink(internal.GenerateTestSpanLink()) + orig = generateTestSpanLink() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -882,12 +1013,26 @@ func TestSpanLink_DroppedAttributesCount(t *testing.T) { assert.Equal(t, uint32(17), ms.DroppedAttributesCount()) } +func generateTestSpanLink() SpanLink { + tv := NewSpanLink() + fillTestSpanLink(tv) + return tv +} + +func fillTestSpanLink(tv SpanLink) { + tv.orig.TraceId = data.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) + tv.orig.SpanId = data.SpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) + internal.FillTestTraceState(internal.NewTraceState(&tv.orig.TraceState)) + internal.FillTestMap(internal.NewMap(&tv.orig.Attributes)) + tv.orig.DroppedAttributesCount = uint32(17) +} + func TestStatus_MoveTo(t *testing.T) { - ms := Status(internal.GenerateTestStatus()) + ms := generateTestStatus() dest := NewStatus() ms.MoveTo(dest) assert.Equal(t, NewStatus(), ms) - assert.Equal(t, Status(internal.GenerateTestStatus()), dest) + assert.Equal(t, generateTestStatus(), dest) } func TestStatus_CopyTo(t *testing.T) { @@ -895,7 +1040,7 @@ func TestStatus_CopyTo(t *testing.T) { orig := NewStatus() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Status(internal.GenerateTestStatus()) + orig = generateTestStatus() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -914,3 +1059,14 @@ func TestStatus_Message(t *testing.T) { ms.SetMessage("cancelled") assert.Equal(t, "cancelled", ms.Message()) } + +func generateTestStatus() Status { + tv := NewStatus() + fillTestStatus(tv) + return tv +} + +func fillTestStatus(tv Status) { + tv.orig.Code = 1 + tv.orig.Message = "cancelled" +} diff --git a/pdata/ptrace/ptraceotlp/generated_traces_otlp.go b/pdata/ptrace/ptraceotlp/generated_traces_otlp.go index 682a033f5cc..f7d7c77fed4 100644 --- a/pdata/ptrace/ptraceotlp/generated_traces_otlp.go +++ b/pdata/ptrace/ptraceotlp/generated_traces_otlp.go @@ -18,7 +18,6 @@ package ptraceotlp import ( - "go.opentelemetry.io/collector/pdata/internal" otlpcollectortrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/trace/v1" ) @@ -29,15 +28,12 @@ import ( // // Must use NewExportPartialSuccess function to create new instances. // Important: zero-initialized instance is not valid for use. - -type ExportPartialSuccess internal.TracesExportPartialSuccess - -func newExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) ExportPartialSuccess { - return ExportPartialSuccess(internal.NewTracesExportPartialSuccess(orig)) +type ExportPartialSuccess struct { + orig *otlpcollectortrace.ExportTracePartialSuccess } -func (ms ExportPartialSuccess) getOrig() *otlpcollectortrace.ExportTracePartialSuccess { - return internal.GetOrigTracesExportPartialSuccess(internal.TracesExportPartialSuccess(ms)) +func newExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) ExportPartialSuccess { + return ExportPartialSuccess{orig} } // NewExportPartialSuccess creates a new empty ExportPartialSuccess. @@ -51,28 +47,28 @@ func NewExportPartialSuccess() ExportPartialSuccess { // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value func (ms ExportPartialSuccess) MoveTo(dest ExportPartialSuccess) { - *dest.getOrig() = *ms.getOrig() - *ms.getOrig() = otlpcollectortrace.ExportTracePartialSuccess{} + *dest.orig = *ms.orig + *ms.orig = otlpcollectortrace.ExportTracePartialSuccess{} } // RejectedSpans returns the rejectedspans associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) RejectedSpans() int64 { - return ms.getOrig().RejectedSpans + return ms.orig.RejectedSpans } // SetRejectedSpans replaces the rejectedspans associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) SetRejectedSpans(v int64) { - ms.getOrig().RejectedSpans = v + ms.orig.RejectedSpans = v } // ErrorMessage returns the errormessage associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) ErrorMessage() string { - return ms.getOrig().ErrorMessage + return ms.orig.ErrorMessage } // SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. func (ms ExportPartialSuccess) SetErrorMessage(v string) { - ms.getOrig().ErrorMessage = v + ms.orig.ErrorMessage = v } // CopyTo copies all properties from the current struct overriding the destination. diff --git a/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go b/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go index b7f3b32eacc..119ac2d223a 100644 --- a/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go +++ b/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go @@ -21,16 +21,14 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/collector/pdata/internal" ) func TestExportPartialSuccess_MoveTo(t *testing.T) { - ms := ExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()) + ms := generateTestExportPartialSuccess() dest := NewExportPartialSuccess() ms.MoveTo(dest) assert.Equal(t, NewExportPartialSuccess(), ms) - assert.Equal(t, ExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()), dest) + assert.Equal(t, generateTestExportPartialSuccess(), dest) } func TestExportPartialSuccess_CopyTo(t *testing.T) { @@ -38,7 +36,7 @@ func TestExportPartialSuccess_CopyTo(t *testing.T) { orig := NewExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()) + orig = generateTestExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -56,3 +54,14 @@ func TestExportPartialSuccess_ErrorMessage(t *testing.T) { ms.SetErrorMessage("error message") assert.Equal(t, "error message", ms.ErrorMessage()) } + +func generateTestExportPartialSuccess() ExportPartialSuccess { + tv := NewExportPartialSuccess() + fillTestExportPartialSuccess(tv) + return tv +} + +func fillTestExportPartialSuccess(tv ExportPartialSuccess) { + tv.orig.RejectedSpans = int64(13) + tv.orig.ErrorMessage = "error message" +} diff --git a/pdata/ptrace/ptraceotlp/response.go b/pdata/ptrace/ptraceotlp/response.go index 93554524d81..69906d40e85 100644 --- a/pdata/ptrace/ptraceotlp/response.go +++ b/pdata/ptrace/ptraceotlp/response.go @@ -13,10 +13,10 @@ // limitations under the License. package ptraceotlp // import "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" + import ( "bytes" - "go.opentelemetry.io/collector/pdata/internal" otlpcollectortrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/trace/v1" "go.opentelemetry.io/collector/pdata/ptrace/internal/ptracejson" ) @@ -57,5 +57,5 @@ func (ms ExportResponse) UnmarshalJSON(data []byte) error { // PartialSuccess returns the ExportLogsPartialSuccess associated with this ExportResponse. func (ms ExportResponse) PartialSuccess() ExportPartialSuccess { - return ExportPartialSuccess(internal.NewTracesExportPartialSuccess(&ms.orig.PartialSuccess)) + return newExportPartialSuccess(&ms.orig.PartialSuccess) } diff --git a/pdata/ptrace/traces_test.go b/pdata/ptrace/traces_test.go index 7bd460407b6..1b99aff0b81 100644 --- a/pdata/ptrace/traces_test.go +++ b/pdata/ptrace/traces_test.go @@ -22,7 +22,6 @@ import ( goproto "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/emptypb" - "go.opentelemetry.io/collector/pdata/internal" otlpcollectortrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/trace/v1" otlptrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/trace/v1" ) @@ -91,7 +90,7 @@ func TestResourceSpansWireCompatibility(t *testing.T) { // Generate ResourceSpans as pdata struct. traces := NewTraces() - internal.FillTestResourceSpansSlice(internal.ResourceSpansSlice(traces.ResourceSpans())) + fillTestResourceSpansSlice(traces.ResourceSpans()) // Marshal its underlying ProtoBuf to wire. wire1, err := gogoproto.Marshal(traces.getOrig()) @@ -120,16 +119,16 @@ func TestResourceSpansWireCompatibility(t *testing.T) { func TestTracesMoveTo(t *testing.T) { traces := NewTraces() - internal.FillTestResourceSpansSlice(internal.ResourceSpansSlice(traces.ResourceSpans())) + fillTestResourceSpansSlice(traces.ResourceSpans()) dest := NewTraces() traces.MoveTo(dest) assert.EqualValues(t, NewTraces(), traces) - assert.EqualValues(t, ResourceSpansSlice(internal.GenerateTestResourceSpansSlice()), dest.ResourceSpans()) + assert.EqualValues(t, generateTestResourceSpansSlice(), dest.ResourceSpans()) } func TestTracesCopyTo(t *testing.T) { traces := NewTraces() - internal.FillTestResourceSpansSlice(internal.ResourceSpansSlice(traces.ResourceSpans())) + fillTestResourceSpansSlice(traces.ResourceSpans()) tracesCopy := NewTraces() traces.CopyTo(tracesCopy) assert.EqualValues(t, traces, tracesCopy)