From 42771a9a6843298b16ed3f3b480662250622ba2a Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 13 Dec 2022 23:57:21 -0800 Subject: [PATCH] [DRAFT] [pdata] Prototype immutable/mutable pdata --- .../cmd/pdatagen/internal/base_fields.go | 63 +- .../cmd/pdatagen/internal/base_slices.go | 126 +- .../cmd/pdatagen/internal/base_structs.go | 56 +- .../internal/primitive_slice_structs.go | 54 +- pdata/internal/generated_wrapper_common.go | 40 +- pdata/internal/generated_wrapper_logs.go | 126 +- pdata/internal/generated_wrapper_logs_otlp.go | 18 +- pdata/internal/generated_wrapper_metrics.go | 492 +++++-- .../generated_wrapper_metrics_otlp.go | 18 +- .../generated_wrapper_primitive_slice.go | 36 + pdata/internal/generated_wrapper_resource.go | 20 +- pdata/internal/generated_wrapper_traces.go | 232 +++- .../internal/generated_wrapper_traces_otlp.go | 18 +- pdata/internal/wrapper_common.go | 40 +- pdata/pcommon/common.go | 178 ++- pdata/pcommon/generated_common.go | 92 +- pdata/pcommon/generated_common_test.go | 8 +- pdata/pcommon/generated_primitive_slice.go | 126 +- pdata/pcommon/generated_resource.go | 35 +- pdata/pcommon/generated_resource_test.go | 6 +- pdata/plog/generated_logs.go | 298 +++- pdata/plog/generated_logs_test.go | 24 +- pdata/plog/plogotlp/generated_logs_otlp.go | 37 +- .../plog/plogotlp/generated_logs_otlp_test.go | 6 +- pdata/pmetric/generated_metrics.go | 1222 ++++++++++++++--- pdata/pmetric/generated_metrics_test.go | 108 +- pdata/pmetric/metrics.go | 14 +- .../pmetricotlp/generated_metrics_otlp.go | 37 +- .../generated_metrics_otlp_test.go | 6 +- pdata/ptrace/generated_traces.go | 553 ++++++-- pdata/ptrace/generated_traces_test.go | 46 +- .../ptraceotlp/generated_traces_otlp.go | 37 +- .../ptraceotlp/generated_traces_otlp_test.go | 6 +- 33 files changed, 3331 insertions(+), 847 deletions(-) diff --git a/pdata/internal/cmd/pdatagen/internal/base_fields.go b/pdata/internal/cmd/pdatagen/internal/base_fields.go index 26bcb65c0a7..bfdfc8c53ea 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_fields.go +++ b/pdata/internal/cmd/pdatagen/internal/base_fields.go @@ -23,6 +23,11 @@ import ( const accessorSliceTemplate = `// ${fieldName} returns the ${fieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${fieldName})) +} + +// ${fieldName} returns the ${fieldName} associated with this ${structName}. +func (ms Mutable${structName}) ${fieldName}() ${packageName}Mutable${returnType} { + return ${packageName}Mutable${returnType}(internal.NewMutable${returnType}(&ms.getOrig().${fieldName})) }` const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { @@ -35,6 +40,11 @@ const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testi const accessorsMessageValueTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { return ${packageName}${returnType}(internal.New${returnType}(&ms.getOrig().${fieldName})) +} + +// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. +func (ms Mutable${structName}) ${fieldName}() ${packageName}Mutable${returnType} { + return ${packageName}Mutable${returnType}(internal.NewMutable${returnType}(&ms.getOrig().${fieldName})) }` const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { @@ -48,14 +58,24 @@ func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { return ms.getOrig().${fieldName} } +// Mutable${fieldName} returns the ${lowerFieldName} associated with this ${structName}. +func (ms Mutable${structName}) ${fieldName}() ${packageName}${returnType} { + return ms.getOrig().${fieldName} +} + // Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}. -func (ms ${structName}) Set${fieldName}(v ${returnType}) { +func (ms Mutable${structName}) Set${fieldName}(v ${returnType}) { ms.getOrig().${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})) +} + +// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. +func (ms Mutable${structName}) ${fieldName}() ${packageName}Mutable${returnType} { + return ${packageName}Mutable${returnType}(internal.NewMutable${returnType}(&ms.getOrig().${fieldName})) }` const oneOfTypeAccessorHeaderTemplate = `// ${typeFuncName} returns the type of the ${lowerOriginFieldName} for this ${structName}. @@ -87,11 +107,11 @@ func (ms ${structName}) ${fieldName}() ${returnType} { // // After this, ${originOneOfTypeFuncName}() function will return ${typeName}". // -// Calling this function on zero-initialized ${structName} will cause a panic. -func (ms ${structName}) SetEmpty${fieldName}() ${returnType} { +// Calling this function on zero-initialized Mutable${structName} will cause a panic. +func (ms Mutable${structName}) SetEmpty${fieldName}() Mutable${returnType} { val := &${originFieldPackageName}.${fieldName}{} ms.getOrig().${originOneOfFieldName} = &${originStructType}{${fieldName}: val} - return new${returnType}(val) + return newMutable${returnType}(val) }` const accessorsOneOfMessageTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { @@ -117,8 +137,12 @@ func (ms ${structName}) ${accessorFieldName}() ${returnType} { return ms.getOrig().Get${originFieldName}() } +func (ms Mutable${structName}) ${accessorFieldName}() ${returnType} { + return ms.getOrig().Get${originFieldName}() +} + // Set${accessorFieldName} replaces the ${lowerFieldName} associated with this ${structName}. -func (ms ${structName}) Set${accessorFieldName}(v ${returnType}) { +func (ms Mutable${structName}) Set${accessorFieldName}(v ${returnType}) { ms.getOrig().${originOneOfFieldName} = &${originStructType}{ ${originFieldName}: v, } @@ -144,8 +168,13 @@ func (ms ${structName}) ${fieldName}() ${packageName}${returnType} { return ${packageName}${returnType}(ms.getOrig().${originFieldName}) } +// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. +func (ms Mutable${structName}) ${fieldName}() ${packageName}${returnType} { + return ${packageName}${returnType}(ms.getOrig().${originFieldName}) +} + // Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}. -func (ms ${structName}) Set${fieldName}(v ${packageName}${returnType}) { +func (ms Mutable${structName}) Set${fieldName}(v ${packageName}${returnType}) { ms.getOrig().${originFieldName} = ${rawType}(v) }` @@ -169,19 +198,31 @@ func (ms ${structName}) ${fieldName}() ${returnType} { return ms.getOrig().Get${fieldName}() } +// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. +func (ms Mutable${structName}) ${fieldName}() ${returnType} { + return ms.getOrig().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 } +// Has${fieldName} returns true if the ${structName} contains a +// ${fieldName} value, false otherwise. +func (ms Mutable${structName}) Has${fieldName}() bool { + return ms.getOrig().${fieldName}_ != nil +} + + // Set${fieldName} replaces the ${lowerFieldName} associated with this ${structName}. -func (ms ${structName}) Set${fieldName}(v ${returnType}) { +func (ms Mutable${structName}) Set${fieldName}(v ${returnType}) { ms.getOrig().${fieldName}_ = &${originStructType}{${fieldName}: v} } // Remove${fieldName} removes the ${lowerFieldName} associated with this ${structName}. -func (ms ${structName}) Remove${fieldName}() { +func (ms Mutable${structName}) Remove${fieldName}() { ms.getOrig().${fieldName}_ = nil }` @@ -251,7 +292,7 @@ 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 + "))") + sb.WriteString("\tFillTest" + sf.returnSlice.getName() + "(NewMutable" + sf.returnSlice.getName() + "(&tv.orig." + sf.fieldName + "))") } func (sf *sliceField) generateCopyToValue(_ baseStruct, sb *bytes.Buffer) { @@ -308,7 +349,7 @@ 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 + "))") + sb.WriteString("\tFillTest" + mf.returnMessage.getName() + "(NewMutable" + mf.returnMessage.getName() + "(&tv.orig." + mf.fieldName + "))") } func (mf *messageValueField) generateCopyToValue(_ baseStruct, sb *bytes.Buffer) { @@ -749,7 +790,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 + "(NewMutable" + omv.fieldName + "(tv.orig.Get" + omv.fieldName + "()))") } func (omv *oneOfMessageValue) generateCopyToValue(of *oneOfField, sb *bytes.Buffer) { diff --git a/pdata/internal/cmd/pdatagen/internal/base_slices.go b/pdata/internal/cmd/pdatagen/internal/base_slices.go index b866100ef6c..7e4a4064659 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_slices.go +++ b/pdata/internal/cmd/pdatagen/internal/base_slices.go @@ -22,7 +22,7 @@ import ( 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}) { +func (es Mutable${structName}) MoveAndAppendTo(dest Mutable${structName}) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -34,7 +34,7 @@ func (es ${structName}) MoveAndAppendTo(dest ${structName}) { // 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) { +func (es Mutable${structName}) RemoveIf(f func(Mutable${elementName}) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -106,19 +106,29 @@ const slicePtrTemplate = `// ${structName} logically represents a slice of ${ele // Important: zero-initialized instance is not valid for use. type ${structName} internal.${structName} +type Mutable${structName} internal.Mutable${structName} + func new${structName}(orig *[]*${originName}) ${structName} { return ${structName}(internal.New${structName}(orig)) } +func newMutable${structName}(orig *[]*${originName}) Mutable${structName} { + return Mutable${structName}(internal.New${structName}(orig)) +} + func (ms ${structName}) getOrig() *[]*${originName} { return internal.GetOrig${structName}(internal.${structName}(ms)) } +func (ms Mutable${structName}) getOrig() *[]*${originName} { + return internal.GetMutableOrig${structName}(internal.Mutable${structName}(ms)) +} + // New${structName} creates a ${structName} with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func New${structName}() ${structName} { +func New${structName}() Mutable${structName} { orig := []*${originName}(nil) - return new${structName}(&orig) + return newMutable${structName}(&orig) } // Len returns the number of elements in the slice. @@ -128,6 +138,10 @@ func (es ${structName}) Len() int { return len(*es.getOrig()) } +func (es Mutable${structName}) 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: @@ -139,14 +153,18 @@ func (es ${structName}) At(ix int) ${elementName} { return new${elementName}((*es.getOrig())[ix]) } +func (es Mutable${structName}) At(ix int) Mutable${elementName} { + return newMutable${elementName}((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ${structName}) CopyTo(dest ${structName}) { +func (es ${structName}) CopyTo(dest Mutable${structName}) { srcLen := es.Len() destCap := cap(*dest.getOrig()) 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])) + new${elementName}((*es.getOrig())[i]).CopyTo(newMutable${elementName}((*dest.getOrig())[i])) } return } @@ -154,11 +172,16 @@ func (es ${structName}) CopyTo(dest ${structName}) { wrappers := make([]*${originName}, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - new${elementName}((*es.getOrig())[i]).CopyTo(new${elementName}(wrappers[i])) + new${elementName}((*es.getOrig())[i]).CopyTo(newMutable${elementName}(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es Mutable${structName}) CopyTo(dest Mutable${structName}) { + new${structName}(es.getOrig()).CopyTo(dest) +} + // 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. @@ -170,7 +193,7 @@ func (es ${structName}) CopyTo(dest ${structName}) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ${structName}) EnsureCapacity(newCap int) { +func (es Mutable${structName}) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -183,7 +206,7 @@ func (es ${structName}) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ${elementName}. // It returns the newly added ${elementName}. -func (es ${structName}) AppendEmpty() ${elementName} { +func (es Mutable${structName}) AppendEmpty() Mutable${elementName} { *es.getOrig() = append(*es.getOrig(), &${originName}{}) return es.At(es.Len() - 1) } @@ -191,7 +214,7 @@ func (es ${structName}) AppendEmpty() ${elementName} { // Sort sorts the ${elementName} elements within ${structName} given the // provided less function so that two instances of ${structName} // can be compared. -func (es ${structName}) Sort(less func(a, b ${elementName}) bool) { +func (es Mutable${structName}) Sort(less func(a, b Mutable${elementName}) bool) { sort.SliceStable(*es.getOrig(), func(i, j int) bool { return less(es.At(i), es.At(j)) }) } ` @@ -209,7 +232,7 @@ const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTest${elementName}(internal.${elementName}(el)) + internal.FillTest${elementName}(internal.Mutable${elementName}(el)) assert.Equal(t, testVal, el) } } @@ -263,18 +286,18 @@ func Test${structName}_EnsureCapacity(t *testing.T) { assert.Equal(t, expectedEs, foundEs) }` -const slicePtrGenerateTest = `func GenerateTest${structName}() ${structName} { +const slicePtrGenerateTest = `func GenerateTest${structName}() Mutable${structName} { orig := []*${originName}{} - tv := New${structName}(&orig) + tv := NewMutable${structName}(&orig) FillTest${structName}(tv) return tv } -func FillTest${structName}(tv ${structName}) { +func FillTest${structName}(tv Mutable${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}(NewMutable${elementName}((*tv.orig)[i])) } }` @@ -283,12 +306,24 @@ type ${structName} struct { orig *[]*${originName} } +type Mutable${structName} struct { + orig *[]*${originName} +} + func GetOrig${structName}(ms ${structName}) *[]*${originName} { return ms.orig } +func GetMutableOrig${structName}(ms Mutable${structName}) *[]*${originName} { + return ms.orig +} + func New${structName}(orig *[]*${originName}) ${structName} { return ${structName}{orig: orig} +} + +func NewMutable${structName}(orig *[]*${originName}) Mutable${structName} { + return Mutable${structName}{orig: orig} }` const sliceValueTemplate = `// ${structName} logically represents a slice of ${elementName}. @@ -300,19 +335,33 @@ const sliceValueTemplate = `// ${structName} logically represents a slice of ${e // Important: zero-initialized instance is not valid for use. type ${structName} internal.${structName} +type Mutable${structName} internal.Mutable${structName} + func new${structName}(orig *[]${originName}) ${structName} { return ${structName}(internal.New${structName}(orig)) } +func newMutable${structName}(orig *[]${originName}) Mutable${structName} { + return Mutable${structName}(internal.New${structName}(orig)) +} + func (ms ${structName}) getOrig() *[]${originName} { return internal.GetOrig${structName}(internal.${structName}(ms)) } +func (ms Mutable${structName}) getOrig() *[]${originName} { + return internal.GetMutableOrig${structName}(internal.Mutable${structName}(ms)) +} + +func (ms Mutable${structName}) immutable() ${structName} { + return new${structName}(ms.getOrig()) +} + // New${structName} creates a ${structName} with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func New${structName}() ${structName} { +func New${structName}() Mutable${structName} { orig := []${originName}(nil) - return ${structName}(internal.New${structName}(&orig)) + return Mutable${structName}(internal.New${structName}(&orig)) } // Len returns the number of elements in the slice. @@ -322,6 +371,10 @@ func (es ${structName}) Len() int { return len(*es.getOrig()) } +func (es Mutable${structName}) Len() int { + return newMutable${structName}(es.getOrig()).Len() +} + // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: @@ -333,8 +386,12 @@ func (es ${structName}) At(ix int) ${elementName} { return new${elementName}(&(*es.getOrig())[ix]) } +func (es Mutable${structName}) At(ix int) Mutable${elementName} { + return newMutable${elementName}(&(*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ${structName}) CopyTo(dest ${structName}) { +func (es ${structName}) CopyTo(dest Mutable${structName}) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { @@ -344,10 +401,15 @@ func (es ${structName}) CopyTo(dest ${structName}) { } for i := range *es.getOrig() { - new${elementName}(&(*es.getOrig())[i]).CopyTo(new${elementName}(&(*dest.getOrig())[i])) + new${elementName}(&(*es.getOrig())[i]).CopyTo(newMutable${elementName}(&(*dest.getOrig())[i])) } } +// CopyTo copies all elements from the current slice overriding the destination. +func (es Mutable${structName}) CopyTo(dest Mutable${structName}) { + new${structName}(es.getOrig()).CopyTo(dest) +} + // 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. @@ -359,7 +421,7 @@ func (es ${structName}) CopyTo(dest ${structName}) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ${structName}) EnsureCapacity(newCap int) { +func (es Mutable${structName}) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -372,7 +434,7 @@ func (es ${structName}) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ${elementName}. // It returns the newly added ${elementName}. -func (es ${structName}) AppendEmpty() ${elementName} { +func (es Mutable${structName}) AppendEmpty() Mutable${elementName} { *es.getOrig() = append(*es.getOrig(), ${originName}{}) return es.At(es.Len() - 1) }` @@ -390,7 +452,7 @@ const sliceValueTestTemplate = `func Test${structName}(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTest${elementName}(internal.${elementName}(el)) + internal.FillTest${elementName}(internal.Mutable${elementName}(el)) assert.Equal(t, testVal, el) } } @@ -435,17 +497,17 @@ func Test${structName}_EnsureCapacity(t *testing.T) { assert.Equal(t, ensureLargeLen, cap(*es.getOrig())) }` -const sliceValueGenerateTest = `func GenerateTest${structName}() ${structName} { +const sliceValueGenerateTest = `func GenerateTest${structName}() Mutable${structName} { orig := []${originName}{} - tv := New${structName}(&orig) + tv := NewMutable${structName}(&orig) FillTest${structName}(tv) return tv } -func FillTest${structName}(tv ${structName}) { +func FillTest${structName}(tv Mutable${structName}) { *tv.orig = make([]${originName}, 7) for i := 0; i < 7; i++ { - FillTest${elementName}(New${elementName}(&(*tv.orig)[i])) + FillTest${elementName}(NewMutable${elementName}(&(*tv.orig)[i])) } }` @@ -454,12 +516,24 @@ type ${structName} struct { orig *[]${originName} } +type Mutable${structName} struct { + orig *[]${originName} +} + func GetOrig${structName}(ms ${structName}) *[]${originName} { return ms.orig } +func GetMutableOrig${structName}(ms Mutable${structName}) *[]${originName} { + return ms.orig +} + func New${structName}(orig *[]${originName}) ${structName} { return ${structName}{orig: orig} +} + +func NewMutable${structName}(orig *[]${originName}) Mutable${structName} { + return Mutable${structName}{orig: orig} }` type baseSlice interface { diff --git a/pdata/internal/cmd/pdatagen/internal/base_structs.go b/pdata/internal/cmd/pdatagen/internal/base_structs.go index 38a1f58de96..558f46cd04a 100644 --- a/pdata/internal/cmd/pdatagen/internal/base_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/base_structs.go @@ -29,41 +29,56 @@ const messageValueTemplate = `${description} type ${structName} internal.${internalStructName} +type Mutable${structName} internal.Mutable${internalStructName} + func new${structName}(orig *${originName}) ${structName} { return ${structName}(internal.New${internalStructName}(orig)) } +func newMutable${structName}(orig *${originName}) Mutable${structName} { + return Mutable${structName}(internal.New${internalStructName}(orig)) +} + func (ms ${structName}) getOrig() *${originName} { return internal.GetOrig${internalStructName}(internal.${internalStructName}(ms)) } +func (ms Mutable${structName}) getOrig() *${originName} { + return internal.GetMutableOrig${internalStructName}(internal.Mutable${internalStructName}(ms)) +} + // New${structName} creates a new empty ${structName}. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func New${structName}() ${structName} { - return new${structName}(&${originName}{}) +func New${structName}() Mutable${structName} { + return newMutable${structName}(&${originName}{}) } // 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}) { +func (ms Mutable${structName}) MoveTo(dest Mutable${structName}) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = ${originName}{} }` const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct overriding the destination. -func (ms ${structName}) CopyTo(dest ${structName}) {` +func (ms ${structName}) CopyTo(dest Mutable${structName}) {` const messageValueCopyToFooterTemplate = `}` +const messageMutableValueCopyToTemplate = `// CopyTo copies all properties from the current struct overriding the destination. +func (ms Mutable${structName}) CopyTo(dest Mutable${structName}) { + new${structName}(ms.getOrig()).CopyTo(dest) +}` + const messageValueTestTemplate = ` func Test${structName}_MoveTo(t *testing.T) { - ms := ${structName}(internal.GenerateTest${internalStructName}()) + ms := Mutable${structName}{internal.GenerateTest${internalStructName}()} dest := New${structName}() ms.MoveTo(dest) assert.Equal(t, New${structName}(), ms) - assert.Equal(t, ${structName}(internal.GenerateTest${internalStructName}()), dest) + assert.Equal(t, Mutable${structName}(internal.GenerateTest${internalStructName}()), dest) } func Test${structName}_CopyTo(t *testing.T) { @@ -71,19 +86,19 @@ func Test${structName}_CopyTo(t *testing.T) { orig := New${structName}() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ${structName}(internal.GenerateTest${internalStructName}()) + orig = Mutable${structName}(internal.GenerateTest${internalStructName}()) orig.CopyTo(ms) assert.Equal(t, orig, ms) }` -const messageValueGenerateTestTemplate = `func GenerateTest${internalStructName}() ${internalStructName} { +const messageValueGenerateTestTemplate = `func GenerateTest${internalStructName}() Mutable${internalStructName} { orig := ${originName}{} - tv := New${internalStructName}(&orig) + tv := NewMutable${internalStructName}(&orig) FillTest${internalStructName}(tv) return tv }` -const messageValueFillTestHeaderTemplate = `func FillTest${internalStructName}(tv ${internalStructName}) {` +const messageValueFillTestHeaderTemplate = `func FillTest${internalStructName}(tv Mutable${internalStructName}) {` const messageValueFillTestFooterTemplate = `}` const messageValueAliasTemplate = ` @@ -91,12 +106,24 @@ type ${internalStructName} struct { orig *${originName} } +type Mutable${internalStructName} struct { + orig *${originName} +} + func GetOrig${internalStructName}(ms ${internalStructName}) *${originName} { return ms.orig } +func GetMutableOrig${internalStructName}(ms Mutable${internalStructName}) *${originName} { + return ms.orig +} + func New${internalStructName}(orig *${originName}) ${internalStructName} { return ${internalStructName}{orig: orig} +} + +func NewMutable${internalStructName}(orig *${originName}) Mutable${internalStructName} { + return Mutable${internalStructName}{orig: orig} }` const newLine = "\n" @@ -177,6 +204,15 @@ func (ms *messageValueStruct) generateStruct(sb *bytes.Buffer) { sb.WriteString(os.Expand(messageValueCopyToFooterTemplate, func(name string) string { panic(name) })) + sb.WriteString(newLine + newLine) + sb.WriteString(os.Expand(messageMutableValueCopyToTemplate, func(name string) string { + switch name { + case "structName": + return ms.structName + default: + panic(name) + } + })) } func (ms *messageValueStruct) generateTests(sb *bytes.Buffer) { diff --git a/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go b/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go index ca814a046d5..e6262e8d744 100644 --- a/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/primitive_slice_structs.go @@ -27,14 +27,24 @@ const primitiveSliceTemplate = `// ${structName} represents a []${itemType} slic // Important: zero-initialized instance is not valid for use. type ${structName} internal.${structName} +type Mutable${structName} internal.Mutable${structName} + func (ms ${structName}) getOrig() *[]${itemType} { return internal.GetOrig${structName}(internal.${structName}(ms)) } +func (ms Mutable${structName}) getOrig() *[]${itemType} { + return internal.GetMutableOrig${structName}(internal.Mutable${structName}(ms)) +} + +func (ms Mutable${structName}) immutable() ${structName} { + return ${structName}(internal.New${structName}(ms.getOrig())) +} + // New${structName} creates a new empty ${structName}. -func New${structName}() ${structName} { +func New${structName}() Mutable${structName} { orig := []${itemType}(nil) - return ${structName}(internal.New${structName}(&orig)) + return Mutable${structName}(internal.NewMutable${structName}(&orig)) } // AsRaw returns a copy of the []${itemType} slice. @@ -42,8 +52,12 @@ func (ms ${structName}) AsRaw() []${itemType} { return copy${structName}(nil, *ms.getOrig()) } +func (ms Mutable${structName}) AsRaw() []${itemType} { + return ms.immutable().AsRaw() +} + // FromRaw copies raw []${itemType} into the slice ${structName}. -func (ms ${structName}) FromRaw(val []${itemType}) { +func (ms Mutable${structName}) FromRaw(val []${itemType}) { *ms.getOrig() = copy${structName}(*ms.getOrig(), val) } @@ -53,15 +67,23 @@ func (ms ${structName}) Len() int { return len(*ms.getOrig()) } +func (ms Mutable${structName}) Len() int { + return ms.immutable().Len() +} + // At returns an item from particular index. // Equivalent of ${lowerStructName}[i]. func (ms ${structName}) At(i int) ${itemType} { return (*ms.getOrig())[i] } +func (ms Mutable${structName}) At(i int) ${itemType} { + return ms.immutable().At(i) +} + // SetAt sets ${itemType} item at particular index. // Equivalent of ${lowerStructName}[i] = val -func (ms ${structName}) SetAt(i int, val ${itemType}) { +func (ms Mutable${structName}) SetAt(i int, val ${itemType}) { (*ms.getOrig())[i] = val } @@ -71,7 +93,7 @@ func (ms ${structName}) SetAt(i int, val ${itemType}) { // buf := make([]${itemType}, len(${lowerStructName}), newCap) // copy(buf, ${lowerStructName}) // ${lowerStructName} = buf -func (ms ${structName}) EnsureCapacity(newCap int) { +func (ms Mutable${structName}) EnsureCapacity(newCap int) { oldCap := cap(*ms.getOrig()) if newCap <= oldCap { return @@ -84,22 +106,26 @@ func (ms ${structName}) EnsureCapacity(newCap int) { // Append appends extra elements to ${structName}. // Equivalent of ${lowerStructName} = append(${lowerStructName}, elms...) -func (ms ${structName}) Append(elms ...${itemType}) { +func (ms Mutable${structName}) Append(elms ...${itemType}) { *ms.getOrig() = append(*ms.getOrig(), elms...) } // MoveTo moves all elements from the current slice overriding the destination and // resetting the current instance to its zero value. -func (ms ${structName}) MoveTo(dest ${structName}) { +func (ms Mutable${structName}) MoveTo(dest Mutable${structName}) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = nil } // CopyTo copies all elements from the current slice overriding the destination. -func (ms ${structName}) CopyTo(dest ${structName}) { +func (ms ${structName}) CopyTo(dest Mutable${structName}) { *dest.getOrig() = copy${structName}(*dest.getOrig(), *ms.getOrig()) } +func (ms Mutable${structName}) CopyTo(dest Mutable${structName}) { + ms.immutable().CopyTo(dest) +} + func copy${structName}(dst, src []${itemType}) []${itemType} { dst = dst[:0] return append(dst, src...) @@ -157,12 +183,24 @@ type ${structName} struct { orig *[]${itemType} } +type Mutable${structName} struct { + mo *[]${itemType} +} + func GetOrig${structName}(ms ${structName}) *[]${itemType} { return ms.orig } +func GetMutableOrig${structName}(ms Mutable${structName}) *[]${itemType} { + return ms.mo +} + func New${structName}(orig *[]${itemType}) ${structName} { return ${structName}{orig: orig} +} + +func NewMutable${structName}(orig *[]${itemType}) Mutable${structName} { + return Mutable${structName}{mo: orig} }` type primitiveSliceStruct struct { diff --git a/pdata/internal/generated_wrapper_common.go b/pdata/internal/generated_wrapper_common.go index 28c256c871c..078e53e39d9 100644 --- a/pdata/internal/generated_wrapper_common.go +++ b/pdata/internal/generated_wrapper_common.go @@ -25,50 +25,74 @@ type InstrumentationScope struct { orig *otlpcommon.InstrumentationScope } +type MutableInstrumentationScope struct { + orig *otlpcommon.InstrumentationScope +} + func GetOrigInstrumentationScope(ms InstrumentationScope) *otlpcommon.InstrumentationScope { return ms.orig } +func GetMutableOrigInstrumentationScope(ms MutableInstrumentationScope) *otlpcommon.InstrumentationScope { + return ms.orig +} + func NewInstrumentationScope(orig *otlpcommon.InstrumentationScope) InstrumentationScope { return InstrumentationScope{orig: orig} } +func NewMutableInstrumentationScope(orig *otlpcommon.InstrumentationScope) MutableInstrumentationScope { + return MutableInstrumentationScope{orig: orig} +} + type Slice struct { orig *[]otlpcommon.AnyValue } +type MutableSlice struct { + orig *[]otlpcommon.AnyValue +} + func GetOrigSlice(ms Slice) *[]otlpcommon.AnyValue { return ms.orig } +func GetMutableOrigSlice(ms MutableSlice) *[]otlpcommon.AnyValue { + return ms.orig +} + func NewSlice(orig *[]otlpcommon.AnyValue) Slice { return Slice{orig: orig} } -func GenerateTestInstrumentationScope() InstrumentationScope { +func NewMutableSlice(orig *[]otlpcommon.AnyValue) MutableSlice { + return MutableSlice{orig: orig} +} + +func GenerateTestInstrumentationScope() MutableInstrumentationScope { orig := otlpcommon.InstrumentationScope{} - tv := NewInstrumentationScope(&orig) + tv := NewMutableInstrumentationScope(&orig) FillTestInstrumentationScope(tv) return tv } -func FillTestInstrumentationScope(tv InstrumentationScope) { +func FillTestInstrumentationScope(tv MutableInstrumentationScope) { tv.orig.Name = "test_name" tv.orig.Version = "test_version" - FillTestMap(NewMap(&tv.orig.Attributes)) + FillTestMap(NewMutableMap(&tv.orig.Attributes)) tv.orig.DroppedAttributesCount = uint32(17) } -func GenerateTestSlice() Slice { +func GenerateTestSlice() MutableSlice { orig := []otlpcommon.AnyValue{} - tv := NewSlice(&orig) + tv := NewMutableSlice(&orig) FillTestSlice(tv) return tv } -func FillTestSlice(tv Slice) { +func FillTestSlice(tv MutableSlice) { *tv.orig = make([]otlpcommon.AnyValue, 7) for i := 0; i < 7; i++ { - FillTestValue(NewValue(&(*tv.orig)[i])) + FillTestValue(NewMutableValue(&(*tv.orig)[i])) } } diff --git a/pdata/internal/generated_wrapper_logs.go b/pdata/internal/generated_wrapper_logs.go index 9c94a4237ca..4df6198278b 100644 --- a/pdata/internal/generated_wrapper_logs.go +++ b/pdata/internal/generated_wrapper_logs.go @@ -26,153 +26,225 @@ type ResourceLogsSlice struct { orig *[]*otlplogs.ResourceLogs } +type MutableResourceLogsSlice struct { + orig *[]*otlplogs.ResourceLogs +} + func GetOrigResourceLogsSlice(ms ResourceLogsSlice) *[]*otlplogs.ResourceLogs { return ms.orig } +func GetMutableOrigResourceLogsSlice(ms MutableResourceLogsSlice) *[]*otlplogs.ResourceLogs { + return ms.orig +} + func NewResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) ResourceLogsSlice { return ResourceLogsSlice{orig: orig} } +func NewMutableResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) MutableResourceLogsSlice { + return MutableResourceLogsSlice{orig: orig} +} + type ResourceLogs struct { orig *otlplogs.ResourceLogs } +type MutableResourceLogs struct { + orig *otlplogs.ResourceLogs +} + func GetOrigResourceLogs(ms ResourceLogs) *otlplogs.ResourceLogs { return ms.orig } +func GetMutableOrigResourceLogs(ms MutableResourceLogs) *otlplogs.ResourceLogs { + return ms.orig +} + func NewResourceLogs(orig *otlplogs.ResourceLogs) ResourceLogs { return ResourceLogs{orig: orig} } +func NewMutableResourceLogs(orig *otlplogs.ResourceLogs) MutableResourceLogs { + return MutableResourceLogs{orig: orig} +} + type ScopeLogsSlice struct { orig *[]*otlplogs.ScopeLogs } +type MutableScopeLogsSlice struct { + orig *[]*otlplogs.ScopeLogs +} + func GetOrigScopeLogsSlice(ms ScopeLogsSlice) *[]*otlplogs.ScopeLogs { return ms.orig } +func GetMutableOrigScopeLogsSlice(ms MutableScopeLogsSlice) *[]*otlplogs.ScopeLogs { + return ms.orig +} + func NewScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) ScopeLogsSlice { return ScopeLogsSlice{orig: orig} } +func NewMutableScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) MutableScopeLogsSlice { + return MutableScopeLogsSlice{orig: orig} +} + type ScopeLogs struct { orig *otlplogs.ScopeLogs } +type MutableScopeLogs struct { + orig *otlplogs.ScopeLogs +} + func GetOrigScopeLogs(ms ScopeLogs) *otlplogs.ScopeLogs { return ms.orig } +func GetMutableOrigScopeLogs(ms MutableScopeLogs) *otlplogs.ScopeLogs { + return ms.orig +} + func NewScopeLogs(orig *otlplogs.ScopeLogs) ScopeLogs { return ScopeLogs{orig: orig} } +func NewMutableScopeLogs(orig *otlplogs.ScopeLogs) MutableScopeLogs { + return MutableScopeLogs{orig: orig} +} + type LogRecordSlice struct { orig *[]*otlplogs.LogRecord } +type MutableLogRecordSlice struct { + orig *[]*otlplogs.LogRecord +} + func GetOrigLogRecordSlice(ms LogRecordSlice) *[]*otlplogs.LogRecord { return ms.orig } +func GetMutableOrigLogRecordSlice(ms MutableLogRecordSlice) *[]*otlplogs.LogRecord { + return ms.orig +} + func NewLogRecordSlice(orig *[]*otlplogs.LogRecord) LogRecordSlice { return LogRecordSlice{orig: orig} } +func NewMutableLogRecordSlice(orig *[]*otlplogs.LogRecord) MutableLogRecordSlice { + return MutableLogRecordSlice{orig: orig} +} + type LogRecord struct { orig *otlplogs.LogRecord } +type MutableLogRecord struct { + orig *otlplogs.LogRecord +} + func GetOrigLogRecord(ms LogRecord) *otlplogs.LogRecord { return ms.orig } +func GetMutableOrigLogRecord(ms MutableLogRecord) *otlplogs.LogRecord { + return ms.orig +} + func NewLogRecord(orig *otlplogs.LogRecord) LogRecord { return LogRecord{orig: orig} } -func GenerateTestResourceLogsSlice() ResourceLogsSlice { +func NewMutableLogRecord(orig *otlplogs.LogRecord) MutableLogRecord { + return MutableLogRecord{orig: orig} +} + +func GenerateTestResourceLogsSlice() MutableResourceLogsSlice { orig := []*otlplogs.ResourceLogs{} - tv := NewResourceLogsSlice(&orig) + tv := NewMutableResourceLogsSlice(&orig) FillTestResourceLogsSlice(tv) return tv } -func FillTestResourceLogsSlice(tv ResourceLogsSlice) { +func FillTestResourceLogsSlice(tv MutableResourceLogsSlice) { *tv.orig = make([]*otlplogs.ResourceLogs, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlplogs.ResourceLogs{} - FillTestResourceLogs(NewResourceLogs((*tv.orig)[i])) + FillTestResourceLogs(NewMutableResourceLogs((*tv.orig)[i])) } } -func GenerateTestResourceLogs() ResourceLogs { +func GenerateTestResourceLogs() MutableResourceLogs { orig := otlplogs.ResourceLogs{} - tv := NewResourceLogs(&orig) + tv := NewMutableResourceLogs(&orig) FillTestResourceLogs(tv) return tv } -func FillTestResourceLogs(tv ResourceLogs) { - FillTestResource(NewResource(&tv.orig.Resource)) +func FillTestResourceLogs(tv MutableResourceLogs) { + FillTestResource(NewMutableResource(&tv.orig.Resource)) tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestScopeLogsSlice(NewScopeLogsSlice(&tv.orig.ScopeLogs)) + FillTestScopeLogsSlice(NewMutableScopeLogsSlice(&tv.orig.ScopeLogs)) } -func GenerateTestScopeLogsSlice() ScopeLogsSlice { +func GenerateTestScopeLogsSlice() MutableScopeLogsSlice { orig := []*otlplogs.ScopeLogs{} - tv := NewScopeLogsSlice(&orig) + tv := NewMutableScopeLogsSlice(&orig) FillTestScopeLogsSlice(tv) return tv } -func FillTestScopeLogsSlice(tv ScopeLogsSlice) { +func FillTestScopeLogsSlice(tv MutableScopeLogsSlice) { *tv.orig = make([]*otlplogs.ScopeLogs, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlplogs.ScopeLogs{} - FillTestScopeLogs(NewScopeLogs((*tv.orig)[i])) + FillTestScopeLogs(NewMutableScopeLogs((*tv.orig)[i])) } } -func GenerateTestScopeLogs() ScopeLogs { +func GenerateTestScopeLogs() MutableScopeLogs { orig := otlplogs.ScopeLogs{} - tv := NewScopeLogs(&orig) + tv := NewMutableScopeLogs(&orig) FillTestScopeLogs(tv) return tv } -func FillTestScopeLogs(tv ScopeLogs) { - FillTestInstrumentationScope(NewInstrumentationScope(&tv.orig.Scope)) +func FillTestScopeLogs(tv MutableScopeLogs) { + FillTestInstrumentationScope(NewMutableInstrumentationScope(&tv.orig.Scope)) tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestLogRecordSlice(NewLogRecordSlice(&tv.orig.LogRecords)) + FillTestLogRecordSlice(NewMutableLogRecordSlice(&tv.orig.LogRecords)) } -func GenerateTestLogRecordSlice() LogRecordSlice { +func GenerateTestLogRecordSlice() MutableLogRecordSlice { orig := []*otlplogs.LogRecord{} - tv := NewLogRecordSlice(&orig) + tv := NewMutableLogRecordSlice(&orig) FillTestLogRecordSlice(tv) return tv } -func FillTestLogRecordSlice(tv LogRecordSlice) { +func FillTestLogRecordSlice(tv MutableLogRecordSlice) { *tv.orig = make([]*otlplogs.LogRecord, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlplogs.LogRecord{} - FillTestLogRecord(NewLogRecord((*tv.orig)[i])) + FillTestLogRecord(NewMutableLogRecord((*tv.orig)[i])) } } -func GenerateTestLogRecord() LogRecord { +func GenerateTestLogRecord() MutableLogRecord { orig := otlplogs.LogRecord{} - tv := NewLogRecord(&orig) + tv := NewMutableLogRecord(&orig) FillTestLogRecord(tv) return tv } -func FillTestLogRecord(tv LogRecord) { +func FillTestLogRecord(tv MutableLogRecord) { 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}) @@ -180,7 +252,7 @@ func FillTestLogRecord(tv LogRecord) { tv.orig.Flags = 1 tv.orig.SeverityText = "INFO" tv.orig.SeverityNumber = otlplogs.SeverityNumber(5) - FillTestValue(NewValue(&tv.orig.Body)) - FillTestMap(NewMap(&tv.orig.Attributes)) + FillTestValue(NewMutableValue(&tv.orig.Body)) + FillTestMap(NewMutableMap(&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 index eb2109f0a92..608f0b3d1e0 100644 --- a/pdata/internal/generated_wrapper_logs_otlp.go +++ b/pdata/internal/generated_wrapper_logs_otlp.go @@ -25,22 +25,34 @@ type LogsExportPartialSuccess struct { orig *otlpcollectorlog.ExportLogsPartialSuccess } +type MutableLogsExportPartialSuccess struct { + orig *otlpcollectorlog.ExportLogsPartialSuccess +} + func GetOrigLogsExportPartialSuccess(ms LogsExportPartialSuccess) *otlpcollectorlog.ExportLogsPartialSuccess { return ms.orig } +func GetMutableOrigLogsExportPartialSuccess(ms MutableLogsExportPartialSuccess) *otlpcollectorlog.ExportLogsPartialSuccess { + return ms.orig +} + func NewLogsExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) LogsExportPartialSuccess { return LogsExportPartialSuccess{orig: orig} } -func GenerateTestLogsExportPartialSuccess() LogsExportPartialSuccess { +func NewMutableLogsExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) MutableLogsExportPartialSuccess { + return MutableLogsExportPartialSuccess{orig: orig} +} + +func GenerateTestLogsExportPartialSuccess() MutableLogsExportPartialSuccess { orig := otlpcollectorlog.ExportLogsPartialSuccess{} - tv := NewLogsExportPartialSuccess(&orig) + tv := NewMutableLogsExportPartialSuccess(&orig) FillTestLogsExportPartialSuccess(tv) return tv } -func FillTestLogsExportPartialSuccess(tv LogsExportPartialSuccess) { +func FillTestLogsExportPartialSuccess(tv MutableLogsExportPartialSuccess) { 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 index 1345b0cab30..401bb7e7935 100644 --- a/pdata/internal/generated_wrapper_metrics.go +++ b/pdata/internal/generated_wrapper_metrics.go @@ -26,636 +26,924 @@ type ResourceMetricsSlice struct { orig *[]*otlpmetrics.ResourceMetrics } +type MutableResourceMetricsSlice struct { + orig *[]*otlpmetrics.ResourceMetrics +} + func GetOrigResourceMetricsSlice(ms ResourceMetricsSlice) *[]*otlpmetrics.ResourceMetrics { return ms.orig } +func GetMutableOrigResourceMetricsSlice(ms MutableResourceMetricsSlice) *[]*otlpmetrics.ResourceMetrics { + return ms.orig +} + func NewResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) ResourceMetricsSlice { return ResourceMetricsSlice{orig: orig} } +func NewMutableResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) MutableResourceMetricsSlice { + return MutableResourceMetricsSlice{orig: orig} +} + type ResourceMetrics struct { orig *otlpmetrics.ResourceMetrics } +type MutableResourceMetrics struct { + orig *otlpmetrics.ResourceMetrics +} + func GetOrigResourceMetrics(ms ResourceMetrics) *otlpmetrics.ResourceMetrics { return ms.orig } +func GetMutableOrigResourceMetrics(ms MutableResourceMetrics) *otlpmetrics.ResourceMetrics { + return ms.orig +} + func NewResourceMetrics(orig *otlpmetrics.ResourceMetrics) ResourceMetrics { return ResourceMetrics{orig: orig} } +func NewMutableResourceMetrics(orig *otlpmetrics.ResourceMetrics) MutableResourceMetrics { + return MutableResourceMetrics{orig: orig} +} + type ScopeMetricsSlice struct { orig *[]*otlpmetrics.ScopeMetrics } +type MutableScopeMetricsSlice struct { + orig *[]*otlpmetrics.ScopeMetrics +} + func GetOrigScopeMetricsSlice(ms ScopeMetricsSlice) *[]*otlpmetrics.ScopeMetrics { return ms.orig } +func GetMutableOrigScopeMetricsSlice(ms MutableScopeMetricsSlice) *[]*otlpmetrics.ScopeMetrics { + return ms.orig +} + func NewScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) ScopeMetricsSlice { return ScopeMetricsSlice{orig: orig} } +func NewMutableScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) MutableScopeMetricsSlice { + return MutableScopeMetricsSlice{orig: orig} +} + type ScopeMetrics struct { orig *otlpmetrics.ScopeMetrics } +type MutableScopeMetrics struct { + orig *otlpmetrics.ScopeMetrics +} + func GetOrigScopeMetrics(ms ScopeMetrics) *otlpmetrics.ScopeMetrics { return ms.orig } +func GetMutableOrigScopeMetrics(ms MutableScopeMetrics) *otlpmetrics.ScopeMetrics { + return ms.orig +} + func NewScopeMetrics(orig *otlpmetrics.ScopeMetrics) ScopeMetrics { return ScopeMetrics{orig: orig} } +func NewMutableScopeMetrics(orig *otlpmetrics.ScopeMetrics) MutableScopeMetrics { + return MutableScopeMetrics{orig: orig} +} + type MetricSlice struct { orig *[]*otlpmetrics.Metric } +type MutableMetricSlice struct { + orig *[]*otlpmetrics.Metric +} + func GetOrigMetricSlice(ms MetricSlice) *[]*otlpmetrics.Metric { return ms.orig } +func GetMutableOrigMetricSlice(ms MutableMetricSlice) *[]*otlpmetrics.Metric { + return ms.orig +} + func NewMetricSlice(orig *[]*otlpmetrics.Metric) MetricSlice { return MetricSlice{orig: orig} } +func NewMutableMetricSlice(orig *[]*otlpmetrics.Metric) MutableMetricSlice { + return MutableMetricSlice{orig: orig} +} + type Metric struct { orig *otlpmetrics.Metric } +type MutableMetric struct { + orig *otlpmetrics.Metric +} + func GetOrigMetric(ms Metric) *otlpmetrics.Metric { return ms.orig } +func GetMutableOrigMetric(ms MutableMetric) *otlpmetrics.Metric { + return ms.orig +} + func NewMetric(orig *otlpmetrics.Metric) Metric { return Metric{orig: orig} } +func NewMutableMetric(orig *otlpmetrics.Metric) MutableMetric { + return MutableMetric{orig: orig} +} + type Gauge struct { orig *otlpmetrics.Gauge } +type MutableGauge struct { + orig *otlpmetrics.Gauge +} + func GetOrigGauge(ms Gauge) *otlpmetrics.Gauge { return ms.orig } +func GetMutableOrigGauge(ms MutableGauge) *otlpmetrics.Gauge { + return ms.orig +} + func NewGauge(orig *otlpmetrics.Gauge) Gauge { return Gauge{orig: orig} } +func NewMutableGauge(orig *otlpmetrics.Gauge) MutableGauge { + return MutableGauge{orig: orig} +} + type Sum struct { orig *otlpmetrics.Sum } +type MutableSum struct { + orig *otlpmetrics.Sum +} + func GetOrigSum(ms Sum) *otlpmetrics.Sum { return ms.orig } +func GetMutableOrigSum(ms MutableSum) *otlpmetrics.Sum { + return ms.orig +} + func NewSum(orig *otlpmetrics.Sum) Sum { return Sum{orig: orig} } +func NewMutableSum(orig *otlpmetrics.Sum) MutableSum { + return MutableSum{orig: orig} +} + type Histogram struct { orig *otlpmetrics.Histogram } +type MutableHistogram struct { + orig *otlpmetrics.Histogram +} + func GetOrigHistogram(ms Histogram) *otlpmetrics.Histogram { return ms.orig } +func GetMutableOrigHistogram(ms MutableHistogram) *otlpmetrics.Histogram { + return ms.orig +} + func NewHistogram(orig *otlpmetrics.Histogram) Histogram { return Histogram{orig: orig} } +func NewMutableHistogram(orig *otlpmetrics.Histogram) MutableHistogram { + return MutableHistogram{orig: orig} +} + type ExponentialHistogram struct { orig *otlpmetrics.ExponentialHistogram } +type MutableExponentialHistogram struct { + orig *otlpmetrics.ExponentialHistogram +} + func GetOrigExponentialHistogram(ms ExponentialHistogram) *otlpmetrics.ExponentialHistogram { return ms.orig } +func GetMutableOrigExponentialHistogram(ms MutableExponentialHistogram) *otlpmetrics.ExponentialHistogram { + return ms.orig +} + func NewExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) ExponentialHistogram { return ExponentialHistogram{orig: orig} } +func NewMutableExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) MutableExponentialHistogram { + return MutableExponentialHistogram{orig: orig} +} + type Summary struct { orig *otlpmetrics.Summary } +type MutableSummary struct { + orig *otlpmetrics.Summary +} + func GetOrigSummary(ms Summary) *otlpmetrics.Summary { return ms.orig } +func GetMutableOrigSummary(ms MutableSummary) *otlpmetrics.Summary { + return ms.orig +} + func NewSummary(orig *otlpmetrics.Summary) Summary { return Summary{orig: orig} } +func NewMutableSummary(orig *otlpmetrics.Summary) MutableSummary { + return MutableSummary{orig: orig} +} + type NumberDataPointSlice struct { orig *[]*otlpmetrics.NumberDataPoint } +type MutableNumberDataPointSlice struct { + orig *[]*otlpmetrics.NumberDataPoint +} + func GetOrigNumberDataPointSlice(ms NumberDataPointSlice) *[]*otlpmetrics.NumberDataPoint { return ms.orig } +func GetMutableOrigNumberDataPointSlice(ms MutableNumberDataPointSlice) *[]*otlpmetrics.NumberDataPoint { + return ms.orig +} + func NewNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) NumberDataPointSlice { return NumberDataPointSlice{orig: orig} } +func NewMutableNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) MutableNumberDataPointSlice { + return MutableNumberDataPointSlice{orig: orig} +} + type NumberDataPoint struct { orig *otlpmetrics.NumberDataPoint } +type MutableNumberDataPoint struct { + orig *otlpmetrics.NumberDataPoint +} + func GetOrigNumberDataPoint(ms NumberDataPoint) *otlpmetrics.NumberDataPoint { return ms.orig } +func GetMutableOrigNumberDataPoint(ms MutableNumberDataPoint) *otlpmetrics.NumberDataPoint { + return ms.orig +} + func NewNumberDataPoint(orig *otlpmetrics.NumberDataPoint) NumberDataPoint { return NumberDataPoint{orig: orig} } +func NewMutableNumberDataPoint(orig *otlpmetrics.NumberDataPoint) MutableNumberDataPoint { + return MutableNumberDataPoint{orig: orig} +} + type HistogramDataPointSlice struct { orig *[]*otlpmetrics.HistogramDataPoint } +type MutableHistogramDataPointSlice struct { + orig *[]*otlpmetrics.HistogramDataPoint +} + func GetOrigHistogramDataPointSlice(ms HistogramDataPointSlice) *[]*otlpmetrics.HistogramDataPoint { return ms.orig } +func GetMutableOrigHistogramDataPointSlice(ms MutableHistogramDataPointSlice) *[]*otlpmetrics.HistogramDataPoint { + return ms.orig +} + func NewHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) HistogramDataPointSlice { return HistogramDataPointSlice{orig: orig} } +func NewMutableHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) MutableHistogramDataPointSlice { + return MutableHistogramDataPointSlice{orig: orig} +} + type HistogramDataPoint struct { orig *otlpmetrics.HistogramDataPoint } +type MutableHistogramDataPoint struct { + orig *otlpmetrics.HistogramDataPoint +} + func GetOrigHistogramDataPoint(ms HistogramDataPoint) *otlpmetrics.HistogramDataPoint { return ms.orig } +func GetMutableOrigHistogramDataPoint(ms MutableHistogramDataPoint) *otlpmetrics.HistogramDataPoint { + return ms.orig +} + func NewHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) HistogramDataPoint { return HistogramDataPoint{orig: orig} } +func NewMutableHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) MutableHistogramDataPoint { + return MutableHistogramDataPoint{orig: orig} +} + type ExponentialHistogramDataPointSlice struct { orig *[]*otlpmetrics.ExponentialHistogramDataPoint } +type MutableExponentialHistogramDataPointSlice struct { + orig *[]*otlpmetrics.ExponentialHistogramDataPoint +} + func GetOrigExponentialHistogramDataPointSlice(ms ExponentialHistogramDataPointSlice) *[]*otlpmetrics.ExponentialHistogramDataPoint { return ms.orig } +func GetMutableOrigExponentialHistogramDataPointSlice(ms MutableExponentialHistogramDataPointSlice) *[]*otlpmetrics.ExponentialHistogramDataPoint { + return ms.orig +} + func NewExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPointSlice { return ExponentialHistogramDataPointSlice{orig: orig} } +func NewMutableExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) MutableExponentialHistogramDataPointSlice { + return MutableExponentialHistogramDataPointSlice{orig: orig} +} + type ExponentialHistogramDataPoint struct { orig *otlpmetrics.ExponentialHistogramDataPoint } +type MutableExponentialHistogramDataPoint struct { + orig *otlpmetrics.ExponentialHistogramDataPoint +} + func GetOrigExponentialHistogramDataPoint(ms ExponentialHistogramDataPoint) *otlpmetrics.ExponentialHistogramDataPoint { return ms.orig } +func GetMutableOrigExponentialHistogramDataPoint(ms MutableExponentialHistogramDataPoint) *otlpmetrics.ExponentialHistogramDataPoint { + return ms.orig +} + func NewExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPoint { return ExponentialHistogramDataPoint{orig: orig} } +func NewMutableExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) MutableExponentialHistogramDataPoint { + return MutableExponentialHistogramDataPoint{orig: orig} +} + type ExponentialHistogramDataPointBuckets struct { orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets } +type MutableExponentialHistogramDataPointBuckets struct { + orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets +} + func GetOrigExponentialHistogramDataPointBuckets(ms ExponentialHistogramDataPointBuckets) *otlpmetrics.ExponentialHistogramDataPoint_Buckets { return ms.orig } +func GetMutableOrigExponentialHistogramDataPointBuckets(ms MutableExponentialHistogramDataPointBuckets) *otlpmetrics.ExponentialHistogramDataPoint_Buckets { + return ms.orig +} + func NewExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) ExponentialHistogramDataPointBuckets { return ExponentialHistogramDataPointBuckets{orig: orig} } +func NewMutableExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) MutableExponentialHistogramDataPointBuckets { + return MutableExponentialHistogramDataPointBuckets{orig: orig} +} + type SummaryDataPointSlice struct { orig *[]*otlpmetrics.SummaryDataPoint } +type MutableSummaryDataPointSlice struct { + orig *[]*otlpmetrics.SummaryDataPoint +} + func GetOrigSummaryDataPointSlice(ms SummaryDataPointSlice) *[]*otlpmetrics.SummaryDataPoint { return ms.orig } +func GetMutableOrigSummaryDataPointSlice(ms MutableSummaryDataPointSlice) *[]*otlpmetrics.SummaryDataPoint { + return ms.orig +} + func NewSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) SummaryDataPointSlice { return SummaryDataPointSlice{orig: orig} } +func NewMutableSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) MutableSummaryDataPointSlice { + return MutableSummaryDataPointSlice{orig: orig} +} + type SummaryDataPoint struct { orig *otlpmetrics.SummaryDataPoint } +type MutableSummaryDataPoint struct { + orig *otlpmetrics.SummaryDataPoint +} + func GetOrigSummaryDataPoint(ms SummaryDataPoint) *otlpmetrics.SummaryDataPoint { return ms.orig } +func GetMutableOrigSummaryDataPoint(ms MutableSummaryDataPoint) *otlpmetrics.SummaryDataPoint { + return ms.orig +} + func NewSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) SummaryDataPoint { return SummaryDataPoint{orig: orig} } +func NewMutableSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) MutableSummaryDataPoint { + return MutableSummaryDataPoint{orig: orig} +} + type SummaryDataPointValueAtQuantileSlice struct { orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile } +type MutableSummaryDataPointValueAtQuantileSlice struct { + orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile +} + func GetOrigSummaryDataPointValueAtQuantileSlice(ms SummaryDataPointValueAtQuantileSlice) *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile { return ms.orig } +func GetMutableOrigSummaryDataPointValueAtQuantileSlice(ms MutableSummaryDataPointValueAtQuantileSlice) *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile { + return ms.orig +} + func NewSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantileSlice { return SummaryDataPointValueAtQuantileSlice{orig: orig} } +func NewMutableSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) MutableSummaryDataPointValueAtQuantileSlice { + return MutableSummaryDataPointValueAtQuantileSlice{orig: orig} +} + type SummaryDataPointValueAtQuantile struct { orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile } +type MutableSummaryDataPointValueAtQuantile struct { + orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile +} + func GetOrigSummaryDataPointValueAtQuantile(ms SummaryDataPointValueAtQuantile) *otlpmetrics.SummaryDataPoint_ValueAtQuantile { return ms.orig } +func GetMutableOrigSummaryDataPointValueAtQuantile(ms MutableSummaryDataPointValueAtQuantile) *otlpmetrics.SummaryDataPoint_ValueAtQuantile { + return ms.orig +} + func NewSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantile { return SummaryDataPointValueAtQuantile{orig: orig} } +func NewMutableSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) MutableSummaryDataPointValueAtQuantile { + return MutableSummaryDataPointValueAtQuantile{orig: orig} +} + type ExemplarSlice struct { orig *[]otlpmetrics.Exemplar } +type MutableExemplarSlice struct { + orig *[]otlpmetrics.Exemplar +} + func GetOrigExemplarSlice(ms ExemplarSlice) *[]otlpmetrics.Exemplar { return ms.orig } +func GetMutableOrigExemplarSlice(ms MutableExemplarSlice) *[]otlpmetrics.Exemplar { + return ms.orig +} + func NewExemplarSlice(orig *[]otlpmetrics.Exemplar) ExemplarSlice { return ExemplarSlice{orig: orig} } +func NewMutableExemplarSlice(orig *[]otlpmetrics.Exemplar) MutableExemplarSlice { + return MutableExemplarSlice{orig: orig} +} + type Exemplar struct { orig *otlpmetrics.Exemplar } +type MutableExemplar struct { + orig *otlpmetrics.Exemplar +} + func GetOrigExemplar(ms Exemplar) *otlpmetrics.Exemplar { return ms.orig } +func GetMutableOrigExemplar(ms MutableExemplar) *otlpmetrics.Exemplar { + return ms.orig +} + func NewExemplar(orig *otlpmetrics.Exemplar) Exemplar { return Exemplar{orig: orig} } -func GenerateTestResourceMetricsSlice() ResourceMetricsSlice { +func NewMutableExemplar(orig *otlpmetrics.Exemplar) MutableExemplar { + return MutableExemplar{orig: orig} +} + +func GenerateTestResourceMetricsSlice() MutableResourceMetricsSlice { orig := []*otlpmetrics.ResourceMetrics{} - tv := NewResourceMetricsSlice(&orig) + tv := NewMutableResourceMetricsSlice(&orig) FillTestResourceMetricsSlice(tv) return tv } -func FillTestResourceMetricsSlice(tv ResourceMetricsSlice) { +func FillTestResourceMetricsSlice(tv MutableResourceMetricsSlice) { *tv.orig = make([]*otlpmetrics.ResourceMetrics, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.ResourceMetrics{} - FillTestResourceMetrics(NewResourceMetrics((*tv.orig)[i])) + FillTestResourceMetrics(NewMutableResourceMetrics((*tv.orig)[i])) } } -func GenerateTestResourceMetrics() ResourceMetrics { +func GenerateTestResourceMetrics() MutableResourceMetrics { orig := otlpmetrics.ResourceMetrics{} - tv := NewResourceMetrics(&orig) + tv := NewMutableResourceMetrics(&orig) FillTestResourceMetrics(tv) return tv } -func FillTestResourceMetrics(tv ResourceMetrics) { - FillTestResource(NewResource(&tv.orig.Resource)) +func FillTestResourceMetrics(tv MutableResourceMetrics) { + FillTestResource(NewMutableResource(&tv.orig.Resource)) tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestScopeMetricsSlice(NewScopeMetricsSlice(&tv.orig.ScopeMetrics)) + FillTestScopeMetricsSlice(NewMutableScopeMetricsSlice(&tv.orig.ScopeMetrics)) } -func GenerateTestScopeMetricsSlice() ScopeMetricsSlice { +func GenerateTestScopeMetricsSlice() MutableScopeMetricsSlice { orig := []*otlpmetrics.ScopeMetrics{} - tv := NewScopeMetricsSlice(&orig) + tv := NewMutableScopeMetricsSlice(&orig) FillTestScopeMetricsSlice(tv) return tv } -func FillTestScopeMetricsSlice(tv ScopeMetricsSlice) { +func FillTestScopeMetricsSlice(tv MutableScopeMetricsSlice) { *tv.orig = make([]*otlpmetrics.ScopeMetrics, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.ScopeMetrics{} - FillTestScopeMetrics(NewScopeMetrics((*tv.orig)[i])) + FillTestScopeMetrics(NewMutableScopeMetrics((*tv.orig)[i])) } } -func GenerateTestScopeMetrics() ScopeMetrics { +func GenerateTestScopeMetrics() MutableScopeMetrics { orig := otlpmetrics.ScopeMetrics{} - tv := NewScopeMetrics(&orig) + tv := NewMutableScopeMetrics(&orig) FillTestScopeMetrics(tv) return tv } -func FillTestScopeMetrics(tv ScopeMetrics) { - FillTestInstrumentationScope(NewInstrumentationScope(&tv.orig.Scope)) +func FillTestScopeMetrics(tv MutableScopeMetrics) { + FillTestInstrumentationScope(NewMutableInstrumentationScope(&tv.orig.Scope)) tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestMetricSlice(NewMetricSlice(&tv.orig.Metrics)) + FillTestMetricSlice(NewMutableMetricSlice(&tv.orig.Metrics)) } -func GenerateTestMetricSlice() MetricSlice { +func GenerateTestMetricSlice() MutableMetricSlice { orig := []*otlpmetrics.Metric{} - tv := NewMetricSlice(&orig) + tv := NewMutableMetricSlice(&orig) FillTestMetricSlice(tv) return tv } -func FillTestMetricSlice(tv MetricSlice) { +func FillTestMetricSlice(tv MutableMetricSlice) { *tv.orig = make([]*otlpmetrics.Metric, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.Metric{} - FillTestMetric(NewMetric((*tv.orig)[i])) + FillTestMetric(NewMutableMetric((*tv.orig)[i])) } } -func GenerateTestMetric() Metric { +func GenerateTestMetric() MutableMetric { orig := otlpmetrics.Metric{} - tv := NewMetric(&orig) + tv := NewMutableMetric(&orig) FillTestMetric(tv) return tv } -func FillTestMetric(tv Metric) { +func FillTestMetric(tv MutableMetric) { 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())) + FillTestSum(NewMutableSum(tv.orig.GetSum())) } -func GenerateTestGauge() Gauge { +func GenerateTestGauge() MutableGauge { orig := otlpmetrics.Gauge{} - tv := NewGauge(&orig) + tv := NewMutableGauge(&orig) FillTestGauge(tv) return tv } -func FillTestGauge(tv Gauge) { - FillTestNumberDataPointSlice(NewNumberDataPointSlice(&tv.orig.DataPoints)) +func FillTestGauge(tv MutableGauge) { + FillTestNumberDataPointSlice(NewMutableNumberDataPointSlice(&tv.orig.DataPoints)) } -func GenerateTestSum() Sum { +func GenerateTestSum() MutableSum { orig := otlpmetrics.Sum{} - tv := NewSum(&orig) + tv := NewMutableSum(&orig) FillTestSum(tv) return tv } -func FillTestSum(tv Sum) { +func FillTestSum(tv MutableSum) { tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) tv.orig.IsMonotonic = true - FillTestNumberDataPointSlice(NewNumberDataPointSlice(&tv.orig.DataPoints)) + FillTestNumberDataPointSlice(NewMutableNumberDataPointSlice(&tv.orig.DataPoints)) } -func GenerateTestHistogram() Histogram { +func GenerateTestHistogram() MutableHistogram { orig := otlpmetrics.Histogram{} - tv := NewHistogram(&orig) + tv := NewMutableHistogram(&orig) FillTestHistogram(tv) return tv } -func FillTestHistogram(tv Histogram) { +func FillTestHistogram(tv MutableHistogram) { tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) - FillTestHistogramDataPointSlice(NewHistogramDataPointSlice(&tv.orig.DataPoints)) + FillTestHistogramDataPointSlice(NewMutableHistogramDataPointSlice(&tv.orig.DataPoints)) } -func GenerateTestExponentialHistogram() ExponentialHistogram { +func GenerateTestExponentialHistogram() MutableExponentialHistogram { orig := otlpmetrics.ExponentialHistogram{} - tv := NewExponentialHistogram(&orig) + tv := NewMutableExponentialHistogram(&orig) FillTestExponentialHistogram(tv) return tv } -func FillTestExponentialHistogram(tv ExponentialHistogram) { +func FillTestExponentialHistogram(tv MutableExponentialHistogram) { tv.orig.AggregationTemporality = otlpmetrics.AggregationTemporality(1) - FillTestExponentialHistogramDataPointSlice(NewExponentialHistogramDataPointSlice(&tv.orig.DataPoints)) + FillTestExponentialHistogramDataPointSlice(NewMutableExponentialHistogramDataPointSlice(&tv.orig.DataPoints)) } -func GenerateTestSummary() Summary { +func GenerateTestSummary() MutableSummary { orig := otlpmetrics.Summary{} - tv := NewSummary(&orig) + tv := NewMutableSummary(&orig) FillTestSummary(tv) return tv } -func FillTestSummary(tv Summary) { - FillTestSummaryDataPointSlice(NewSummaryDataPointSlice(&tv.orig.DataPoints)) +func FillTestSummary(tv MutableSummary) { + FillTestSummaryDataPointSlice(NewMutableSummaryDataPointSlice(&tv.orig.DataPoints)) } -func GenerateTestNumberDataPointSlice() NumberDataPointSlice { +func GenerateTestNumberDataPointSlice() MutableNumberDataPointSlice { orig := []*otlpmetrics.NumberDataPoint{} - tv := NewNumberDataPointSlice(&orig) + tv := NewMutableNumberDataPointSlice(&orig) FillTestNumberDataPointSlice(tv) return tv } -func FillTestNumberDataPointSlice(tv NumberDataPointSlice) { +func FillTestNumberDataPointSlice(tv MutableNumberDataPointSlice) { *tv.orig = make([]*otlpmetrics.NumberDataPoint, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.NumberDataPoint{} - FillTestNumberDataPoint(NewNumberDataPoint((*tv.orig)[i])) + FillTestNumberDataPoint(NewMutableNumberDataPoint((*tv.orig)[i])) } } -func GenerateTestNumberDataPoint() NumberDataPoint { +func GenerateTestNumberDataPoint() MutableNumberDataPoint { orig := otlpmetrics.NumberDataPoint{} - tv := NewNumberDataPoint(&orig) + tv := NewMutableNumberDataPoint(&orig) FillTestNumberDataPoint(tv) return tv } -func FillTestNumberDataPoint(tv NumberDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) +func FillTestNumberDataPoint(tv MutableNumberDataPoint) { + FillTestMap(NewMutableMap(&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)) + FillTestExemplarSlice(NewMutableExemplarSlice(&tv.orig.Exemplars)) tv.orig.Flags = 1 } -func GenerateTestHistogramDataPointSlice() HistogramDataPointSlice { +func GenerateTestHistogramDataPointSlice() MutableHistogramDataPointSlice { orig := []*otlpmetrics.HistogramDataPoint{} - tv := NewHistogramDataPointSlice(&orig) + tv := NewMutableHistogramDataPointSlice(&orig) FillTestHistogramDataPointSlice(tv) return tv } -func FillTestHistogramDataPointSlice(tv HistogramDataPointSlice) { +func FillTestHistogramDataPointSlice(tv MutableHistogramDataPointSlice) { *tv.orig = make([]*otlpmetrics.HistogramDataPoint, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.HistogramDataPoint{} - FillTestHistogramDataPoint(NewHistogramDataPoint((*tv.orig)[i])) + FillTestHistogramDataPoint(NewMutableHistogramDataPoint((*tv.orig)[i])) } } -func GenerateTestHistogramDataPoint() HistogramDataPoint { +func GenerateTestHistogramDataPoint() MutableHistogramDataPoint { orig := otlpmetrics.HistogramDataPoint{} - tv := NewHistogramDataPoint(&orig) + tv := NewMutableHistogramDataPoint(&orig) FillTestHistogramDataPoint(tv) return tv } -func FillTestHistogramDataPoint(tv HistogramDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) +func FillTestHistogramDataPoint(tv MutableHistogramDataPoint) { + FillTestMap(NewMutableMap(&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)) + FillTestExemplarSlice(NewMutableExemplarSlice(&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 { +func GenerateTestExponentialHistogramDataPointSlice() MutableExponentialHistogramDataPointSlice { orig := []*otlpmetrics.ExponentialHistogramDataPoint{} - tv := NewExponentialHistogramDataPointSlice(&orig) + tv := NewMutableExponentialHistogramDataPointSlice(&orig) FillTestExponentialHistogramDataPointSlice(tv) return tv } -func FillTestExponentialHistogramDataPointSlice(tv ExponentialHistogramDataPointSlice) { +func FillTestExponentialHistogramDataPointSlice(tv MutableExponentialHistogramDataPointSlice) { *tv.orig = make([]*otlpmetrics.ExponentialHistogramDataPoint, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.ExponentialHistogramDataPoint{} - FillTestExponentialHistogramDataPoint(NewExponentialHistogramDataPoint((*tv.orig)[i])) + FillTestExponentialHistogramDataPoint(NewMutableExponentialHistogramDataPoint((*tv.orig)[i])) } } -func GenerateTestExponentialHistogramDataPoint() ExponentialHistogramDataPoint { +func GenerateTestExponentialHistogramDataPoint() MutableExponentialHistogramDataPoint { orig := otlpmetrics.ExponentialHistogramDataPoint{} - tv := NewExponentialHistogramDataPoint(&orig) + tv := NewMutableExponentialHistogramDataPoint(&orig) FillTestExponentialHistogramDataPoint(tv) return tv } -func FillTestExponentialHistogramDataPoint(tv ExponentialHistogramDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) +func FillTestExponentialHistogramDataPoint(tv MutableExponentialHistogramDataPoint) { + FillTestMap(NewMutableMap(&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)) + FillTestExponentialHistogramDataPointBuckets(NewMutableExponentialHistogramDataPointBuckets(&tv.orig.Positive)) + FillTestExponentialHistogramDataPointBuckets(NewMutableExponentialHistogramDataPointBuckets(&tv.orig.Negative)) + FillTestExemplarSlice(NewMutableExemplarSlice(&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 { +func GenerateTestExponentialHistogramDataPointBuckets() MutableExponentialHistogramDataPointBuckets { orig := otlpmetrics.ExponentialHistogramDataPoint_Buckets{} - tv := NewExponentialHistogramDataPointBuckets(&orig) + tv := NewMutableExponentialHistogramDataPointBuckets(&orig) FillTestExponentialHistogramDataPointBuckets(tv) return tv } -func FillTestExponentialHistogramDataPointBuckets(tv ExponentialHistogramDataPointBuckets) { +func FillTestExponentialHistogramDataPointBuckets(tv MutableExponentialHistogramDataPointBuckets) { tv.orig.Offset = int32(909) tv.orig.BucketCounts = []uint64{1, 2, 3} } -func GenerateTestSummaryDataPointSlice() SummaryDataPointSlice { +func GenerateTestSummaryDataPointSlice() MutableSummaryDataPointSlice { orig := []*otlpmetrics.SummaryDataPoint{} - tv := NewSummaryDataPointSlice(&orig) + tv := NewMutableSummaryDataPointSlice(&orig) FillTestSummaryDataPointSlice(tv) return tv } -func FillTestSummaryDataPointSlice(tv SummaryDataPointSlice) { +func FillTestSummaryDataPointSlice(tv MutableSummaryDataPointSlice) { *tv.orig = make([]*otlpmetrics.SummaryDataPoint, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.SummaryDataPoint{} - FillTestSummaryDataPoint(NewSummaryDataPoint((*tv.orig)[i])) + FillTestSummaryDataPoint(NewMutableSummaryDataPoint((*tv.orig)[i])) } } -func GenerateTestSummaryDataPoint() SummaryDataPoint { +func GenerateTestSummaryDataPoint() MutableSummaryDataPoint { orig := otlpmetrics.SummaryDataPoint{} - tv := NewSummaryDataPoint(&orig) + tv := NewMutableSummaryDataPoint(&orig) FillTestSummaryDataPoint(tv) return tv } -func FillTestSummaryDataPoint(tv SummaryDataPoint) { - FillTestMap(NewMap(&tv.orig.Attributes)) +func FillTestSummaryDataPoint(tv MutableSummaryDataPoint) { + FillTestMap(NewMutableMap(&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)) + FillTestSummaryDataPointValueAtQuantileSlice(NewMutableSummaryDataPointValueAtQuantileSlice(&tv.orig.QuantileValues)) tv.orig.Flags = 1 } -func GenerateTestSummaryDataPointValueAtQuantileSlice() SummaryDataPointValueAtQuantileSlice { +func GenerateTestSummaryDataPointValueAtQuantileSlice() MutableSummaryDataPointValueAtQuantileSlice { orig := []*otlpmetrics.SummaryDataPoint_ValueAtQuantile{} - tv := NewSummaryDataPointValueAtQuantileSlice(&orig) + tv := NewMutableSummaryDataPointValueAtQuantileSlice(&orig) FillTestSummaryDataPointValueAtQuantileSlice(tv) return tv } -func FillTestSummaryDataPointValueAtQuantileSlice(tv SummaryDataPointValueAtQuantileSlice) { +func FillTestSummaryDataPointValueAtQuantileSlice(tv MutableSummaryDataPointValueAtQuantileSlice) { *tv.orig = make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlpmetrics.SummaryDataPoint_ValueAtQuantile{} - FillTestSummaryDataPointValueAtQuantile(NewSummaryDataPointValueAtQuantile((*tv.orig)[i])) + FillTestSummaryDataPointValueAtQuantile(NewMutableSummaryDataPointValueAtQuantile((*tv.orig)[i])) } } -func GenerateTestSummaryDataPointValueAtQuantile() SummaryDataPointValueAtQuantile { +func GenerateTestSummaryDataPointValueAtQuantile() MutableSummaryDataPointValueAtQuantile { orig := otlpmetrics.SummaryDataPoint_ValueAtQuantile{} - tv := NewSummaryDataPointValueAtQuantile(&orig) + tv := NewMutableSummaryDataPointValueAtQuantile(&orig) FillTestSummaryDataPointValueAtQuantile(tv) return tv } -func FillTestSummaryDataPointValueAtQuantile(tv SummaryDataPointValueAtQuantile) { +func FillTestSummaryDataPointValueAtQuantile(tv MutableSummaryDataPointValueAtQuantile) { tv.orig.Quantile = float64(17.13) tv.orig.Value = float64(17.13) } -func GenerateTestExemplarSlice() ExemplarSlice { +func GenerateTestExemplarSlice() MutableExemplarSlice { orig := []otlpmetrics.Exemplar{} - tv := NewExemplarSlice(&orig) + tv := NewMutableExemplarSlice(&orig) FillTestExemplarSlice(tv) return tv } -func FillTestExemplarSlice(tv ExemplarSlice) { +func FillTestExemplarSlice(tv MutableExemplarSlice) { *tv.orig = make([]otlpmetrics.Exemplar, 7) for i := 0; i < 7; i++ { - FillTestExemplar(NewExemplar(&(*tv.orig)[i])) + FillTestExemplar(NewMutableExemplar(&(*tv.orig)[i])) } } -func GenerateTestExemplar() Exemplar { +func GenerateTestExemplar() MutableExemplar { orig := otlpmetrics.Exemplar{} - tv := NewExemplar(&orig) + tv := NewMutableExemplar(&orig) FillTestExemplar(tv) return tv } -func FillTestExemplar(tv Exemplar) { +func FillTestExemplar(tv MutableExemplar) { tv.orig.TimeUnixNano = 1234567890 tv.orig.Value = &otlpmetrics.Exemplar_AsInt{AsInt: int64(17)} - FillTestMap(NewMap(&tv.orig.FilteredAttributes)) + FillTestMap(NewMutableMap(&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 index 7256ee8d6ee..2b9687a25ee 100644 --- a/pdata/internal/generated_wrapper_metrics_otlp.go +++ b/pdata/internal/generated_wrapper_metrics_otlp.go @@ -25,22 +25,34 @@ type MetricsExportPartialSuccess struct { orig *otlpcollectormetrics.ExportMetricsPartialSuccess } +type MutableMetricsExportPartialSuccess struct { + orig *otlpcollectormetrics.ExportMetricsPartialSuccess +} + func GetOrigMetricsExportPartialSuccess(ms MetricsExportPartialSuccess) *otlpcollectormetrics.ExportMetricsPartialSuccess { return ms.orig } +func GetMutableOrigMetricsExportPartialSuccess(ms MutableMetricsExportPartialSuccess) *otlpcollectormetrics.ExportMetricsPartialSuccess { + return ms.orig +} + func NewMetricsExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) MetricsExportPartialSuccess { return MetricsExportPartialSuccess{orig: orig} } -func GenerateTestMetricsExportPartialSuccess() MetricsExportPartialSuccess { +func NewMutableMetricsExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) MutableMetricsExportPartialSuccess { + return MutableMetricsExportPartialSuccess{orig: orig} +} + +func GenerateTestMetricsExportPartialSuccess() MutableMetricsExportPartialSuccess { orig := otlpcollectormetrics.ExportMetricsPartialSuccess{} - tv := NewMetricsExportPartialSuccess(&orig) + tv := NewMutableMetricsExportPartialSuccess(&orig) FillTestMetricsExportPartialSuccess(tv) return tv } -func FillTestMetricsExportPartialSuccess(tv MetricsExportPartialSuccess) { +func FillTestMetricsExportPartialSuccess(tv MutableMetricsExportPartialSuccess) { tv.orig.RejectedDataPoints = int64(13) tv.orig.ErrorMessage = "error message" } diff --git a/pdata/internal/generated_wrapper_primitive_slice.go b/pdata/internal/generated_wrapper_primitive_slice.go index 7274a94c764..7fa57fa7674 100644 --- a/pdata/internal/generated_wrapper_primitive_slice.go +++ b/pdata/internal/generated_wrapper_primitive_slice.go @@ -21,34 +21,70 @@ type ByteSlice struct { orig *[]byte } +type MutableByteSlice struct { + mo *[]byte +} + func GetOrigByteSlice(ms ByteSlice) *[]byte { return ms.orig } +func GetMutableOrigByteSlice(ms MutableByteSlice) *[]byte { + return ms.mo +} + func NewByteSlice(orig *[]byte) ByteSlice { return ByteSlice{orig: orig} } +func NewMutableByteSlice(orig *[]byte) MutableByteSlice { + return MutableByteSlice{mo: orig} +} + type Float64Slice struct { orig *[]float64 } +type MutableFloat64Slice struct { + mo *[]float64 +} + func GetOrigFloat64Slice(ms Float64Slice) *[]float64 { return ms.orig } +func GetMutableOrigFloat64Slice(ms MutableFloat64Slice) *[]float64 { + return ms.mo +} + func NewFloat64Slice(orig *[]float64) Float64Slice { return Float64Slice{orig: orig} } +func NewMutableFloat64Slice(orig *[]float64) MutableFloat64Slice { + return MutableFloat64Slice{mo: orig} +} + type UInt64Slice struct { orig *[]uint64 } +type MutableUInt64Slice struct { + mo *[]uint64 +} + func GetOrigUInt64Slice(ms UInt64Slice) *[]uint64 { return ms.orig } +func GetMutableOrigUInt64Slice(ms MutableUInt64Slice) *[]uint64 { + return ms.mo +} + func NewUInt64Slice(orig *[]uint64) UInt64Slice { return UInt64Slice{orig: orig} } + +func NewMutableUInt64Slice(orig *[]uint64) MutableUInt64Slice { + return MutableUInt64Slice{mo: orig} +} diff --git a/pdata/internal/generated_wrapper_resource.go b/pdata/internal/generated_wrapper_resource.go index 96119dc6a60..49b49940ce0 100644 --- a/pdata/internal/generated_wrapper_resource.go +++ b/pdata/internal/generated_wrapper_resource.go @@ -25,22 +25,34 @@ type Resource struct { orig *otlpresource.Resource } +type MutableResource struct { + orig *otlpresource.Resource +} + func GetOrigResource(ms Resource) *otlpresource.Resource { return ms.orig } +func GetMutableOrigResource(ms MutableResource) *otlpresource.Resource { + return ms.orig +} + func NewResource(orig *otlpresource.Resource) Resource { return Resource{orig: orig} } -func GenerateTestResource() Resource { +func NewMutableResource(orig *otlpresource.Resource) MutableResource { + return MutableResource{orig: orig} +} + +func GenerateTestResource() MutableResource { orig := otlpresource.Resource{} - tv := NewResource(&orig) + tv := NewMutableResource(&orig) FillTestResource(tv) return tv } -func FillTestResource(tv Resource) { - FillTestMap(NewMap(&tv.orig.Attributes)) +func FillTestResource(tv MutableResource) { + FillTestMap(NewMutableMap(&tv.orig.Attributes)) tv.orig.DroppedAttributesCount = uint32(17) } diff --git a/pdata/internal/generated_wrapper_traces.go b/pdata/internal/generated_wrapper_traces.go index 38d7e69d117..83731a55594 100644 --- a/pdata/internal/generated_wrapper_traces.go +++ b/pdata/internal/generated_wrapper_traces.go @@ -26,297 +26,429 @@ type ResourceSpansSlice struct { orig *[]*otlptrace.ResourceSpans } +type MutableResourceSpansSlice struct { + orig *[]*otlptrace.ResourceSpans +} + func GetOrigResourceSpansSlice(ms ResourceSpansSlice) *[]*otlptrace.ResourceSpans { return ms.orig } +func GetMutableOrigResourceSpansSlice(ms MutableResourceSpansSlice) *[]*otlptrace.ResourceSpans { + return ms.orig +} + func NewResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) ResourceSpansSlice { return ResourceSpansSlice{orig: orig} } +func NewMutableResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) MutableResourceSpansSlice { + return MutableResourceSpansSlice{orig: orig} +} + type ResourceSpans struct { orig *otlptrace.ResourceSpans } +type MutableResourceSpans struct { + orig *otlptrace.ResourceSpans +} + func GetOrigResourceSpans(ms ResourceSpans) *otlptrace.ResourceSpans { return ms.orig } +func GetMutableOrigResourceSpans(ms MutableResourceSpans) *otlptrace.ResourceSpans { + return ms.orig +} + func NewResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans { return ResourceSpans{orig: orig} } +func NewMutableResourceSpans(orig *otlptrace.ResourceSpans) MutableResourceSpans { + return MutableResourceSpans{orig: orig} +} + type ScopeSpansSlice struct { orig *[]*otlptrace.ScopeSpans } +type MutableScopeSpansSlice struct { + orig *[]*otlptrace.ScopeSpans +} + func GetOrigScopeSpansSlice(ms ScopeSpansSlice) *[]*otlptrace.ScopeSpans { return ms.orig } +func GetMutableOrigScopeSpansSlice(ms MutableScopeSpansSlice) *[]*otlptrace.ScopeSpans { + return ms.orig +} + func NewScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) ScopeSpansSlice { return ScopeSpansSlice{orig: orig} } +func NewMutableScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) MutableScopeSpansSlice { + return MutableScopeSpansSlice{orig: orig} +} + type ScopeSpans struct { orig *otlptrace.ScopeSpans } +type MutableScopeSpans struct { + orig *otlptrace.ScopeSpans +} + func GetOrigScopeSpans(ms ScopeSpans) *otlptrace.ScopeSpans { return ms.orig } +func GetMutableOrigScopeSpans(ms MutableScopeSpans) *otlptrace.ScopeSpans { + return ms.orig +} + func NewScopeSpans(orig *otlptrace.ScopeSpans) ScopeSpans { return ScopeSpans{orig: orig} } +func NewMutableScopeSpans(orig *otlptrace.ScopeSpans) MutableScopeSpans { + return MutableScopeSpans{orig: orig} +} + type SpanSlice struct { orig *[]*otlptrace.Span } +type MutableSpanSlice struct { + orig *[]*otlptrace.Span +} + func GetOrigSpanSlice(ms SpanSlice) *[]*otlptrace.Span { return ms.orig } +func GetMutableOrigSpanSlice(ms MutableSpanSlice) *[]*otlptrace.Span { + return ms.orig +} + func NewSpanSlice(orig *[]*otlptrace.Span) SpanSlice { return SpanSlice{orig: orig} } +func NewMutableSpanSlice(orig *[]*otlptrace.Span) MutableSpanSlice { + return MutableSpanSlice{orig: orig} +} + type Span struct { orig *otlptrace.Span } +type MutableSpan struct { + orig *otlptrace.Span +} + func GetOrigSpan(ms Span) *otlptrace.Span { return ms.orig } +func GetMutableOrigSpan(ms MutableSpan) *otlptrace.Span { + return ms.orig +} + func NewSpan(orig *otlptrace.Span) Span { return Span{orig: orig} } +func NewMutableSpan(orig *otlptrace.Span) MutableSpan { + return MutableSpan{orig: orig} +} + type SpanEventSlice struct { orig *[]*otlptrace.Span_Event } +type MutableSpanEventSlice struct { + orig *[]*otlptrace.Span_Event +} + func GetOrigSpanEventSlice(ms SpanEventSlice) *[]*otlptrace.Span_Event { return ms.orig } +func GetMutableOrigSpanEventSlice(ms MutableSpanEventSlice) *[]*otlptrace.Span_Event { + return ms.orig +} + func NewSpanEventSlice(orig *[]*otlptrace.Span_Event) SpanEventSlice { return SpanEventSlice{orig: orig} } +func NewMutableSpanEventSlice(orig *[]*otlptrace.Span_Event) MutableSpanEventSlice { + return MutableSpanEventSlice{orig: orig} +} + type SpanEvent struct { orig *otlptrace.Span_Event } +type MutableSpanEvent struct { + orig *otlptrace.Span_Event +} + func GetOrigSpanEvent(ms SpanEvent) *otlptrace.Span_Event { return ms.orig } +func GetMutableOrigSpanEvent(ms MutableSpanEvent) *otlptrace.Span_Event { + return ms.orig +} + func NewSpanEvent(orig *otlptrace.Span_Event) SpanEvent { return SpanEvent{orig: orig} } +func NewMutableSpanEvent(orig *otlptrace.Span_Event) MutableSpanEvent { + return MutableSpanEvent{orig: orig} +} + type SpanLinkSlice struct { orig *[]*otlptrace.Span_Link } +type MutableSpanLinkSlice struct { + orig *[]*otlptrace.Span_Link +} + func GetOrigSpanLinkSlice(ms SpanLinkSlice) *[]*otlptrace.Span_Link { return ms.orig } +func GetMutableOrigSpanLinkSlice(ms MutableSpanLinkSlice) *[]*otlptrace.Span_Link { + return ms.orig +} + func NewSpanLinkSlice(orig *[]*otlptrace.Span_Link) SpanLinkSlice { return SpanLinkSlice{orig: orig} } +func NewMutableSpanLinkSlice(orig *[]*otlptrace.Span_Link) MutableSpanLinkSlice { + return MutableSpanLinkSlice{orig: orig} +} + type SpanLink struct { orig *otlptrace.Span_Link } +type MutableSpanLink struct { + orig *otlptrace.Span_Link +} + func GetOrigSpanLink(ms SpanLink) *otlptrace.Span_Link { return ms.orig } +func GetMutableOrigSpanLink(ms MutableSpanLink) *otlptrace.Span_Link { + return ms.orig +} + func NewSpanLink(orig *otlptrace.Span_Link) SpanLink { return SpanLink{orig: orig} } +func NewMutableSpanLink(orig *otlptrace.Span_Link) MutableSpanLink { + return MutableSpanLink{orig: orig} +} + type Status struct { orig *otlptrace.Status } +type MutableStatus struct { + orig *otlptrace.Status +} + func GetOrigStatus(ms Status) *otlptrace.Status { return ms.orig } +func GetMutableOrigStatus(ms MutableStatus) *otlptrace.Status { + return ms.orig +} + func NewStatus(orig *otlptrace.Status) Status { return Status{orig: orig} } -func GenerateTestResourceSpansSlice() ResourceSpansSlice { +func NewMutableStatus(orig *otlptrace.Status) MutableStatus { + return MutableStatus{orig: orig} +} + +func GenerateTestResourceSpansSlice() MutableResourceSpansSlice { orig := []*otlptrace.ResourceSpans{} - tv := NewResourceSpansSlice(&orig) + tv := NewMutableResourceSpansSlice(&orig) FillTestResourceSpansSlice(tv) return tv } -func FillTestResourceSpansSlice(tv ResourceSpansSlice) { +func FillTestResourceSpansSlice(tv MutableResourceSpansSlice) { *tv.orig = make([]*otlptrace.ResourceSpans, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlptrace.ResourceSpans{} - FillTestResourceSpans(NewResourceSpans((*tv.orig)[i])) + FillTestResourceSpans(NewMutableResourceSpans((*tv.orig)[i])) } } -func GenerateTestResourceSpans() ResourceSpans { +func GenerateTestResourceSpans() MutableResourceSpans { orig := otlptrace.ResourceSpans{} - tv := NewResourceSpans(&orig) + tv := NewMutableResourceSpans(&orig) FillTestResourceSpans(tv) return tv } -func FillTestResourceSpans(tv ResourceSpans) { - FillTestResource(NewResource(&tv.orig.Resource)) +func FillTestResourceSpans(tv MutableResourceSpans) { + FillTestResource(NewMutableResource(&tv.orig.Resource)) tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestScopeSpansSlice(NewScopeSpansSlice(&tv.orig.ScopeSpans)) + FillTestScopeSpansSlice(NewMutableScopeSpansSlice(&tv.orig.ScopeSpans)) } -func GenerateTestScopeSpansSlice() ScopeSpansSlice { +func GenerateTestScopeSpansSlice() MutableScopeSpansSlice { orig := []*otlptrace.ScopeSpans{} - tv := NewScopeSpansSlice(&orig) + tv := NewMutableScopeSpansSlice(&orig) FillTestScopeSpansSlice(tv) return tv } -func FillTestScopeSpansSlice(tv ScopeSpansSlice) { +func FillTestScopeSpansSlice(tv MutableScopeSpansSlice) { *tv.orig = make([]*otlptrace.ScopeSpans, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlptrace.ScopeSpans{} - FillTestScopeSpans(NewScopeSpans((*tv.orig)[i])) + FillTestScopeSpans(NewMutableScopeSpans((*tv.orig)[i])) } } -func GenerateTestScopeSpans() ScopeSpans { +func GenerateTestScopeSpans() MutableScopeSpans { orig := otlptrace.ScopeSpans{} - tv := NewScopeSpans(&orig) + tv := NewMutableScopeSpans(&orig) FillTestScopeSpans(tv) return tv } -func FillTestScopeSpans(tv ScopeSpans) { - FillTestInstrumentationScope(NewInstrumentationScope(&tv.orig.Scope)) +func FillTestScopeSpans(tv MutableScopeSpans) { + FillTestInstrumentationScope(NewMutableInstrumentationScope(&tv.orig.Scope)) tv.orig.SchemaUrl = "https://opentelemetry.io/schemas/1.5.0" - FillTestSpanSlice(NewSpanSlice(&tv.orig.Spans)) + FillTestSpanSlice(NewMutableSpanSlice(&tv.orig.Spans)) } -func GenerateTestSpanSlice() SpanSlice { +func GenerateTestSpanSlice() MutableSpanSlice { orig := []*otlptrace.Span{} - tv := NewSpanSlice(&orig) + tv := NewMutableSpanSlice(&orig) FillTestSpanSlice(tv) return tv } -func FillTestSpanSlice(tv SpanSlice) { +func FillTestSpanSlice(tv MutableSpanSlice) { *tv.orig = make([]*otlptrace.Span, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlptrace.Span{} - FillTestSpan(NewSpan((*tv.orig)[i])) + FillTestSpan(NewMutableSpan((*tv.orig)[i])) } } -func GenerateTestSpan() Span { +func GenerateTestSpan() MutableSpan { orig := otlptrace.Span{} - tv := NewSpan(&orig) + tv := NewMutableSpan(&orig) FillTestSpan(tv) return tv } -func FillTestSpan(tv Span) { +func FillTestSpan(tv MutableSpan) { 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)) + FillTestTraceState(NewMutableTraceState(&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)) + FillTestMap(NewMutableMap(&tv.orig.Attributes)) tv.orig.DroppedAttributesCount = uint32(17) - FillTestSpanEventSlice(NewSpanEventSlice(&tv.orig.Events)) + FillTestSpanEventSlice(NewMutableSpanEventSlice(&tv.orig.Events)) tv.orig.DroppedEventsCount = uint32(17) - FillTestSpanLinkSlice(NewSpanLinkSlice(&tv.orig.Links)) + FillTestSpanLinkSlice(NewMutableSpanLinkSlice(&tv.orig.Links)) tv.orig.DroppedLinksCount = uint32(17) - FillTestStatus(NewStatus(&tv.orig.Status)) + FillTestStatus(NewMutableStatus(&tv.orig.Status)) } -func GenerateTestSpanEventSlice() SpanEventSlice { +func GenerateTestSpanEventSlice() MutableSpanEventSlice { orig := []*otlptrace.Span_Event{} - tv := NewSpanEventSlice(&orig) + tv := NewMutableSpanEventSlice(&orig) FillTestSpanEventSlice(tv) return tv } -func FillTestSpanEventSlice(tv SpanEventSlice) { +func FillTestSpanEventSlice(tv MutableSpanEventSlice) { *tv.orig = make([]*otlptrace.Span_Event, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlptrace.Span_Event{} - FillTestSpanEvent(NewSpanEvent((*tv.orig)[i])) + FillTestSpanEvent(NewMutableSpanEvent((*tv.orig)[i])) } } -func GenerateTestSpanEvent() SpanEvent { +func GenerateTestSpanEvent() MutableSpanEvent { orig := otlptrace.Span_Event{} - tv := NewSpanEvent(&orig) + tv := NewMutableSpanEvent(&orig) FillTestSpanEvent(tv) return tv } -func FillTestSpanEvent(tv SpanEvent) { +func FillTestSpanEvent(tv MutableSpanEvent) { tv.orig.TimeUnixNano = 1234567890 tv.orig.Name = "test_name" - FillTestMap(NewMap(&tv.orig.Attributes)) + FillTestMap(NewMutableMap(&tv.orig.Attributes)) tv.orig.DroppedAttributesCount = uint32(17) } -func GenerateTestSpanLinkSlice() SpanLinkSlice { +func GenerateTestSpanLinkSlice() MutableSpanLinkSlice { orig := []*otlptrace.Span_Link{} - tv := NewSpanLinkSlice(&orig) + tv := NewMutableSpanLinkSlice(&orig) FillTestSpanLinkSlice(tv) return tv } -func FillTestSpanLinkSlice(tv SpanLinkSlice) { +func FillTestSpanLinkSlice(tv MutableSpanLinkSlice) { *tv.orig = make([]*otlptrace.Span_Link, 7) for i := 0; i < 7; i++ { (*tv.orig)[i] = &otlptrace.Span_Link{} - FillTestSpanLink(NewSpanLink((*tv.orig)[i])) + FillTestSpanLink(NewMutableSpanLink((*tv.orig)[i])) } } -func GenerateTestSpanLink() SpanLink { +func GenerateTestSpanLink() MutableSpanLink { orig := otlptrace.Span_Link{} - tv := NewSpanLink(&orig) + tv := NewMutableSpanLink(&orig) FillTestSpanLink(tv) return tv } -func FillTestSpanLink(tv SpanLink) { +func FillTestSpanLink(tv MutableSpanLink) { 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)) + FillTestTraceState(NewMutableTraceState(&tv.orig.TraceState)) + FillTestMap(NewMutableMap(&tv.orig.Attributes)) tv.orig.DroppedAttributesCount = uint32(17) } -func GenerateTestStatus() Status { +func GenerateTestStatus() MutableStatus { orig := otlptrace.Status{} - tv := NewStatus(&orig) + tv := NewMutableStatus(&orig) FillTestStatus(tv) return tv } -func FillTestStatus(tv Status) { +func FillTestStatus(tv MutableStatus) { 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 index 1949149976a..14e38dfdec8 100644 --- a/pdata/internal/generated_wrapper_traces_otlp.go +++ b/pdata/internal/generated_wrapper_traces_otlp.go @@ -25,22 +25,34 @@ type TracesExportPartialSuccess struct { orig *otlpcollectortrace.ExportTracePartialSuccess } +type MutableTracesExportPartialSuccess struct { + orig *otlpcollectortrace.ExportTracePartialSuccess +} + func GetOrigTracesExportPartialSuccess(ms TracesExportPartialSuccess) *otlpcollectortrace.ExportTracePartialSuccess { return ms.orig } +func GetMutableOrigTracesExportPartialSuccess(ms MutableTracesExportPartialSuccess) *otlpcollectortrace.ExportTracePartialSuccess { + return ms.orig +} + func NewTracesExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) TracesExportPartialSuccess { return TracesExportPartialSuccess{orig: orig} } -func GenerateTestTracesExportPartialSuccess() TracesExportPartialSuccess { +func NewMutableTracesExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) MutableTracesExportPartialSuccess { + return MutableTracesExportPartialSuccess{orig: orig} +} + +func GenerateTestTracesExportPartialSuccess() MutableTracesExportPartialSuccess { orig := otlpcollectortrace.ExportTracePartialSuccess{} - tv := NewTracesExportPartialSuccess(&orig) + tv := NewMutableTracesExportPartialSuccess(&orig) FillTestTracesExportPartialSuccess(tv) return tv } -func FillTestTracesExportPartialSuccess(tv TracesExportPartialSuccess) { +func FillTestTracesExportPartialSuccess(tv MutableTracesExportPartialSuccess) { 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..3668ec38ab4 100644 --- a/pdata/internal/wrapper_common.go +++ b/pdata/internal/wrapper_common.go @@ -22,21 +22,33 @@ type Value struct { orig *otlpcommon.AnyValue } +type MutableValue struct { + orig *otlpcommon.AnyValue +} + func GetOrigValue(ms Value) *otlpcommon.AnyValue { return ms.orig } +func GetMutableOrigValue(ms MutableValue) *otlpcommon.AnyValue { + return ms.orig +} + func NewValue(orig *otlpcommon.AnyValue) Value { return Value{orig: orig} } -func FillTestValue(dest Value) { +func NewMutableValue(orig *otlpcommon.AnyValue) MutableValue { + return MutableValue{orig: orig} +} + +func FillTestValue(dest MutableValue) { dest.orig.Value = &otlpcommon.AnyValue_StringValue{StringValue: "v"} } -func GenerateTestValue() Value { +func GenerateTestValue() MutableValue { var orig otlpcommon.AnyValue - ms := NewValue(&orig) + ms := NewMutableValue(&orig) FillTestValue(ms) return ms } @@ -45,24 +57,36 @@ type Map struct { orig *[]otlpcommon.KeyValue } +type MutableMap struct { + mo *[]otlpcommon.KeyValue +} + func GetOrigMap(ms Map) *[]otlpcommon.KeyValue { return ms.orig } +func GetMutableOrigMap(ms MutableMap) *[]otlpcommon.KeyValue { + return ms.mo +} + func NewMap(orig *[]otlpcommon.KeyValue) Map { return Map{orig: orig} } -func GenerateTestMap() Map { +func NewMutableMap(orig *[]otlpcommon.KeyValue) MutableMap { + return MutableMap{mo: orig} +} + +func GenerateTestMap() MutableMap { var orig []otlpcommon.KeyValue - ms := NewMap(&orig) + ms := NewMutableMap(&orig) FillTestMap(ms) return ms } -func FillTestMap(dest Map) { - *dest.orig = nil - *dest.orig = append(*dest.orig, otlpcommon.KeyValue{Key: "k", Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "v"}}}) +func FillTestMap(dest MutableMap) { + *dest.mo = nil + *dest.mo = append(*dest.mo, otlpcommon.KeyValue{Key: "k", Value: otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: "v"}}}) } type TraceState struct { diff --git a/pdata/pcommon/common.go b/pdata/pcommon/common.go index 01b67770799..d61de8cd17f 100644 --- a/pdata/pcommon/common.go +++ b/pdata/pcommon/common.go @@ -87,55 +87,65 @@ func (avt ValueType) String() string { // be called only on instances that are created via NewValue+ functions. type Value internal.Value +type MutableValue internal.MutableValue + // NewValueEmpty creates a new Value with an empty value. -func NewValueEmpty() Value { - return newValue(&otlpcommon.AnyValue{}) +func NewValueEmpty() MutableValue { + return newMutableValue(&otlpcommon.AnyValue{}) } // NewValueStr creates a new Value with the given string value. -func NewValueStr(v string) Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: v}}) +func NewValueStr(v string) MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_StringValue{StringValue: v}}) } // NewValueInt creates a new Value with the given int64 value. -func NewValueInt(v int64) Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: v}}) +func NewValueInt(v int64) MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_IntValue{IntValue: v}}) } // NewValueDouble creates a new Value with the given float64 value. -func NewValueDouble(v float64) Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: v}}) +func NewValueDouble(v float64) MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_DoubleValue{DoubleValue: v}}) } // NewValueBool creates a new Value with the given bool value. -func NewValueBool(v bool) Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: v}}) +func NewValueBool(v bool) MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BoolValue{BoolValue: v}}) } // NewValueMap creates a new Value of map type. -func NewValueMap() Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}}) +func NewValueMap() MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}}}) } // NewValueSlice creates a new Value of array type. -func NewValueSlice() Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}}) +func NewValueSlice() MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}}}) } // NewValueBytes creates a new empty Value of byte type. -func NewValueBytes() Value { - return newValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BytesValue{BytesValue: nil}}) +func NewValueBytes() MutableValue { + return newMutableValue(&otlpcommon.AnyValue{Value: &otlpcommon.AnyValue_BytesValue{BytesValue: nil}}) } func newValue(orig *otlpcommon.AnyValue) Value { return Value(internal.NewValue(orig)) } +func newMutableValue(orig *otlpcommon.AnyValue) MutableValue { + return MutableValue(internal.NewMutableValue(orig)) +} + func (v Value) getOrig() *otlpcommon.AnyValue { return internal.GetOrigValue(internal.Value(v)) } -func (v Value) FromRaw(iv any) error { +func (v MutableValue) getOrig() *otlpcommon.AnyValue { + return internal.GetMutableOrigValue(internal.MutableValue(v)) +} + +func (v MutableValue) FromRaw(iv any) error { switch tv := iv.(type) { case nil: v.getOrig().Value = nil @@ -243,6 +253,14 @@ func (v Value) Map() Map { return newMap(&kvlist.Values) } +func (v MutableValue) Map() MutableMap { + kvlist := v.getOrig().GetKvlistValue() + if kvlist == nil { + return MutableMap{} + } + return newMutableMap(&kvlist.Values) +} + // Slice returns the slice value associated with this Value. // If the Type() is not ValueTypeSlice then returns an invalid slice. Note that using // such slice can cause panic. @@ -274,34 +292,34 @@ func (v Value) Bytes() ByteSlice { // The shorter name is used instead of SetString to avoid implementing // fmt.Stringer interface by the corresponding getter method. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetStr(sv string) { +func (v MutableValue) SetStr(sv string) { v.getOrig().Value = &otlpcommon.AnyValue_StringValue{StringValue: sv} } // SetInt replaces the int64 value associated with this Value, // it also changes the type to be ValueTypeInt. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetInt(iv int64) { +func (v MutableValue) SetInt(iv int64) { v.getOrig().Value = &otlpcommon.AnyValue_IntValue{IntValue: iv} } // SetDouble replaces the float64 value associated with this Value, // it also changes the type to be ValueTypeDouble. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetDouble(dv float64) { +func (v MutableValue) SetDouble(dv float64) { v.getOrig().Value = &otlpcommon.AnyValue_DoubleValue{DoubleValue: dv} } // SetBool replaces the bool value associated with this Value, // it also changes the type to be ValueTypeBool. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetBool(bv bool) { +func (v MutableValue) SetBool(bv bool) { v.getOrig().Value = &otlpcommon.AnyValue_BoolValue{BoolValue: bv} } // SetEmptyBytes sets value to an empty byte slice and returns it. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetEmptyBytes() ByteSlice { +func (v MutableValue) SetEmptyBytes() ByteSlice { bv := otlpcommon.AnyValue_BytesValue{BytesValue: nil} v.getOrig().Value = &bv return ByteSlice(internal.NewByteSlice(&bv.BytesValue)) @@ -309,22 +327,22 @@ func (v Value) SetEmptyBytes() ByteSlice { // SetEmptyMap sets value to an empty map and returns it. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetEmptyMap() Map { +func (v MutableValue) SetEmptyMap() MutableMap { kv := &otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{}} v.getOrig().Value = kv - return newMap(&kv.KvlistValue.Values) + return newMutableMap(&kv.KvlistValue.Values) } // SetEmptySlice sets value to an empty slice and returns it. // Calling this function on zero-initialized Value will cause a panic. -func (v Value) SetEmptySlice() Slice { +func (v MutableValue) SetEmptySlice() MutableSlice { av := &otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{}} v.getOrig().Value = av - return newSlice(&av.ArrayValue.Values) + return newMutableSlice(&av.ArrayValue.Values) } // CopyTo copies the Value instance overriding the destination. -func (v Value) CopyTo(dest Value) { +func (v Value) CopyTo(dest MutableValue) { destOrig := dest.getOrig() switch ov := v.getOrig().Value.(type) { case *otlpcommon.AnyValue_KvlistValue: @@ -338,7 +356,7 @@ func (v Value) CopyTo(dest Value) { return } // Deep copy to dest. - newMap(&ov.KvlistValue.Values).CopyTo(newMap(&kv.KvlistValue.Values)) + newMap(&ov.KvlistValue.Values).CopyTo(newMutableMap(&kv.KvlistValue.Values)) case *otlpcommon.AnyValue_ArrayValue: av, ok := destOrig.Value.(*otlpcommon.AnyValue_ArrayValue) if !ok { @@ -350,7 +368,7 @@ func (v Value) CopyTo(dest Value) { return } // Deep copy to dest. - newSlice(&ov.ArrayValue.Values).CopyTo(newSlice(&av.ArrayValue.Values)) + newSlice(&ov.ArrayValue.Values).CopyTo(newMutableSlice(&av.ArrayValue.Values)) case *otlpcommon.AnyValue_BytesValue: bv, ok := destOrig.Value.(*otlpcommon.AnyValue_BytesValue) if !ok { @@ -519,28 +537,28 @@ func (v Value) AsRaw() any { func newKeyValueString(k string, v string) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := newValue(&orig.Value) + akv := newMutableValue(&orig.Value) akv.SetStr(v) return orig } func newKeyValueInt(k string, v int64) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := newValue(&orig.Value) + akv := newMutableValue(&orig.Value) akv.SetInt(v) return orig } func newKeyValueDouble(k string, v float64) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := newValue(&orig.Value) + akv := newMutableValue(&orig.Value) akv.SetDouble(v) return orig } func newKeyValueBool(k string, v bool) otlpcommon.KeyValue { orig := otlpcommon.KeyValue{Key: k} - akv := newValue(&orig.Value) + akv := newMutableValue(&orig.Value) akv.SetBool(v) return orig } @@ -548,28 +566,43 @@ func newKeyValueBool(k string, v bool) otlpcommon.KeyValue { // Map stores a map of string keys to elements of Value type. type Map internal.Map +// MutableMap stores a map of string keys to elements of Value type. +type MutableMap internal.MutableMap + +func (m MutableMap) immutable() Map { + return newMap(m.getOrig()) +} + // NewMap creates a Map with 0 elements. -func NewMap() Map { +func NewMap() MutableMap { orig := []otlpcommon.KeyValue(nil) - return Map(internal.NewMap(&orig)) + return MutableMap(internal.NewMutableMap(&orig)) } func (m Map) getOrig() *[]otlpcommon.KeyValue { return internal.GetOrigMap(internal.Map(m)) } +func (m MutableMap) getOrig() *[]otlpcommon.KeyValue { + return internal.GetMutableOrigMap(internal.MutableMap(m)) +} + func newMap(orig *[]otlpcommon.KeyValue) Map { return Map(internal.NewMap(orig)) } +func newMutableMap(orig *[]otlpcommon.KeyValue) MutableMap { + return MutableMap(internal.NewMutableMap(orig)) +} + // Clear erases any existing entries in this Map instance. -func (m Map) Clear() { +func (m MutableMap) Clear() { *m.getOrig() = nil } // EnsureCapacity increases the capacity of this Map instance, if necessary, // to ensure that it can hold at least the number of elements specified by the capacity argument. -func (m Map) EnsureCapacity(capacity int) { +func (m MutableMap) EnsureCapacity(capacity int) { if capacity <= cap(*m.getOrig()) { return } @@ -595,9 +628,14 @@ func (m Map) Get(key string) (Value, bool) { return newValue(nil), false } +func (m MutableMap) Get(key string) (MutableValue, bool) { + v, ok := m.immutable().Get(key) + return newMutableValue(v.getOrig()), ok +} + // Remove removes the entry associated with the key and returns true if the key // was present in the map, otherwise returns false. -func (m Map) Remove(key string) bool { +func (m MutableMap) Remove(key string) bool { for i := range *m.getOrig() { akv := &(*m.getOrig())[i] if akv.Key == key { @@ -610,11 +648,11 @@ func (m Map) Remove(key string) bool { } // RemoveIf removes the entries for which the function in question returns true -func (m Map) RemoveIf(f func(string, Value) bool) { +func (m MutableMap) RemoveIf(f func(string, MutableValue) bool) { newLen := 0 for i := 0; i < len(*m.getOrig()); i++ { akv := &(*m.getOrig())[i] - if f(akv.Key, newValue(&akv.Value)) { + if f(akv.Key, newMutableValue(&akv.Value)) { continue } if newLen == i { @@ -630,19 +668,19 @@ func (m Map) RemoveIf(f func(string, Value) bool) { // PutEmpty inserts or updates an empty value to the map under given key // and return the updated/inserted value. -func (m Map) PutEmpty(k string) Value { +func (m MutableMap) PutEmpty(k string) MutableValue { if av, existing := m.Get(k); existing { av.getOrig().Value = nil - return newValue(av.getOrig()) + return newMutableValue(av.getOrig()) } *m.getOrig() = append(*m.getOrig(), otlpcommon.KeyValue{Key: k}) - return newValue(&(*m.getOrig())[len(*m.getOrig())-1].Value) + return newMutableValue(&(*m.getOrig())[len(*m.getOrig())-1].Value) } // PutStr performs the Insert or Update action. The Value is // inserted to the map that did not originally have the key. The key/value is // updated to the map where the key already existed. -func (m Map) PutStr(k string, v string) { +func (m MutableMap) PutStr(k string, v string) { if av, existing := m.Get(k); existing { av.SetStr(v) } else { @@ -653,7 +691,7 @@ func (m Map) PutStr(k string, v string) { // PutInt performs the Insert or Update action. The int Value is // inserted to the map that did not originally have the key. The key/value is // updated to the map where the key already existed. -func (m Map) PutInt(k string, v int64) { +func (m MutableMap) PutInt(k string, v int64) { if av, existing := m.Get(k); existing { av.SetInt(v) } else { @@ -664,7 +702,7 @@ func (m Map) PutInt(k string, v int64) { // PutDouble performs the Insert or Update action. The double Value is // inserted to the map that did not originally have the key. The key/value is // updated to the map where the key already existed. -func (m Map) PutDouble(k string, v float64) { +func (m MutableMap) PutDouble(k string, v float64) { if av, existing := m.Get(k); existing { av.SetDouble(v) } else { @@ -675,7 +713,7 @@ func (m Map) PutDouble(k string, v float64) { // PutBool performs the Insert or Update action. The bool Value is // inserted to the map that did not originally have the key. The key/value is // updated to the map where the key already existed. -func (m Map) PutBool(k string, v bool) { +func (m MutableMap) PutBool(k string, v bool) { if av, existing := m.Get(k); existing { av.SetBool(v) } else { @@ -684,7 +722,7 @@ func (m Map) PutBool(k string, v bool) { } // PutEmptyBytes inserts or updates an empty byte slice under given key and returns it. -func (m Map) PutEmptyBytes(k string) ByteSlice { +func (m MutableMap) PutEmptyBytes(k string) ByteSlice { bv := otlpcommon.AnyValue_BytesValue{} if av, existing := m.Get(k); existing { av.getOrig().Value = &bv @@ -695,7 +733,7 @@ func (m Map) PutEmptyBytes(k string) ByteSlice { } // PutEmptyMap inserts or updates an empty map under given key and returns it. -func (m Map) PutEmptyMap(k string) Map { +func (m MutableMap) PutEmptyMap(k string) Map { kvl := otlpcommon.AnyValue_KvlistValue{KvlistValue: &otlpcommon.KeyValueList{Values: []otlpcommon.KeyValue(nil)}} if av, existing := m.Get(k); existing { av.getOrig().Value = &kvl @@ -706,7 +744,7 @@ func (m Map) PutEmptyMap(k string) Map { } // PutEmptySlice inserts or updates an empty slice under given key and returns it. -func (m Map) PutEmptySlice(k string) Slice { +func (m MutableMap) PutEmptySlice(k string) Slice { vl := otlpcommon.AnyValue_ArrayValue{ArrayValue: &otlpcommon.ArrayValue{Values: []otlpcommon.AnyValue(nil)}} if av, existing := m.Get(k); existing { av.getOrig().Value = &vl @@ -720,7 +758,7 @@ func (m Map) PutEmptySlice(k string) Slice { // // IMPORTANT: Sort mutates the data, if you call this function in a consumer, // the consumer must be configured that it mutates data. -func (m Map) Sort() { +func (m MutableMap) Sort() { // Intention is to move the nil values at the end. sort.SliceStable(*m.getOrig(), func(i, j int) bool { return (*m.getOrig())[i].Key < (*m.getOrig())[j].Key @@ -735,6 +773,10 @@ func (m Map) Len() int { return len(*m.getOrig()) } +func (m MutableMap) Len() int { + return m.immutable().Len() +} + // Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration. // // Example: @@ -751,8 +793,14 @@ func (m Map) Range(f func(k string, v Value) bool) { } } +func (m MutableMap) Range(f func(k string, mv MutableValue) bool) { + m.immutable().Range(func(k string, v Value) bool { + return f(k, newMutableValue(v.getOrig())) + }) +} + // CopyTo copies all elements from the current map overriding the destination. -func (m Map) CopyTo(dest Map) { +func (m Map) CopyTo(dest MutableMap) { newLen := len(*m.getOrig()) oldCap := cap(*dest.getOrig()) if newLen <= oldCap { @@ -762,7 +810,7 @@ func (m Map) CopyTo(dest Map) { akv := &(*m.getOrig())[i] destAkv := &(*dest.getOrig())[i] destAkv.Key = akv.Key - newValue(&akv.Value).CopyTo(newValue(&destAkv.Value)) + newValue(&akv.Value).CopyTo(newMutableValue(&destAkv.Value)) } return } @@ -772,11 +820,16 @@ func (m Map) CopyTo(dest Map) { for i := range *m.getOrig() { akv := &(*m.getOrig())[i] origs[i].Key = akv.Key - newValue(&akv.Value).CopyTo(newValue(&origs[i].Value)) + newValue(&akv.Value).CopyTo(newMutableValue(&origs[i].Value)) } *dest.getOrig() = origs } +// CopyTo copies all elements from the current map overriding the destination. +func (m MutableMap) CopyTo(dest MutableMap) { + m.immutable().CopyTo(dest) +} + // AsRaw converts an OTLP Map to a standard go map func (m Map) AsRaw() map[string]any { rawMap := make(map[string]any) @@ -787,7 +840,12 @@ func (m Map) AsRaw() map[string]any { return rawMap } -func (m Map) FromRaw(rawMap map[string]any) error { +// AsRaw converts an OTLP Map to a standard go map +func (m MutableMap) AsRaw() map[string]any { + return m.immutable().AsRaw() +} + +func (m MutableMap) FromRaw(rawMap map[string]any) error { if len(rawMap) == 0 { *m.getOrig() = nil return nil @@ -798,7 +856,7 @@ func (m Map) FromRaw(rawMap map[string]any) error { ix := 0 for k, iv := range rawMap { origs[ix].Key = k - errs = multierr.Append(errs, newValue(&origs[ix].Value).FromRaw(iv)) + errs = multierr.Append(errs, newMutableValue(&origs[ix].Value).FromRaw(iv)) ix++ } *m.getOrig() = origs @@ -814,8 +872,12 @@ func (es Slice) AsRaw() []any { return rawSlice } +func (es MutableSlice) AsRaw() []any { + return es.immutable().AsRaw() +} + // FromRaw copies []any into the Slice. -func (es Slice) FromRaw(rawSlice []any) error { +func (es MutableSlice) FromRaw(rawSlice []any) error { if len(rawSlice) == 0 { *es.getOrig() = nil return nil @@ -823,7 +885,7 @@ func (es Slice) FromRaw(rawSlice []any) error { var errs error origs := make([]otlpcommon.AnyValue, len(rawSlice)) for ix, iv := range rawSlice { - errs = multierr.Append(errs, newValue(&origs[ix]).FromRaw(iv)) + errs = multierr.Append(errs, newMutableValue(&origs[ix]).FromRaw(iv)) } *es.getOrig() = origs return errs diff --git a/pdata/pcommon/generated_common.go b/pdata/pcommon/generated_common.go index e53019a3725..14a13a0eb93 100644 --- a/pdata/pcommon/generated_common.go +++ b/pdata/pcommon/generated_common.go @@ -32,25 +32,35 @@ import ( type InstrumentationScope internal.InstrumentationScope +type MutableInstrumentationScope internal.MutableInstrumentationScope + func newInstrumentationScope(orig *otlpcommon.InstrumentationScope) InstrumentationScope { return InstrumentationScope(internal.NewInstrumentationScope(orig)) } +func newMutableInstrumentationScope(orig *otlpcommon.InstrumentationScope) MutableInstrumentationScope { + return MutableInstrumentationScope(internal.NewInstrumentationScope(orig)) +} + func (ms InstrumentationScope) getOrig() *otlpcommon.InstrumentationScope { return internal.GetOrigInstrumentationScope(internal.InstrumentationScope(ms)) } +func (ms MutableInstrumentationScope) getOrig() *otlpcommon.InstrumentationScope { + return internal.GetMutableOrigInstrumentationScope(internal.MutableInstrumentationScope(ms)) +} + // NewInstrumentationScope creates a new empty InstrumentationScope. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewInstrumentationScope() InstrumentationScope { - return newInstrumentationScope(&otlpcommon.InstrumentationScope{}) +func NewInstrumentationScope() MutableInstrumentationScope { + return newMutableInstrumentationScope(&otlpcommon.InstrumentationScope{}) } // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value -func (ms InstrumentationScope) MoveTo(dest InstrumentationScope) { +func (ms MutableInstrumentationScope) MoveTo(dest MutableInstrumentationScope) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpcommon.InstrumentationScope{} } @@ -60,8 +70,13 @@ func (ms InstrumentationScope) Name() string { return ms.getOrig().Name } +// MutableName returns the name associated with this InstrumentationScope. +func (ms MutableInstrumentationScope) Name() string { + return ms.getOrig().Name +} + // SetName replaces the name associated with this InstrumentationScope. -func (ms InstrumentationScope) SetName(v string) { +func (ms MutableInstrumentationScope) SetName(v string) { ms.getOrig().Name = v } @@ -70,8 +85,13 @@ func (ms InstrumentationScope) Version() string { return ms.getOrig().Version } +// MutableVersion returns the version associated with this InstrumentationScope. +func (ms MutableInstrumentationScope) Version() string { + return ms.getOrig().Version +} + // SetVersion replaces the version associated with this InstrumentationScope. -func (ms InstrumentationScope) SetVersion(v string) { +func (ms MutableInstrumentationScope) SetVersion(v string) { ms.getOrig().Version = v } @@ -80,24 +100,39 @@ func (ms InstrumentationScope) Attributes() Map { return Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this InstrumentationScope. +func (ms MutableInstrumentationScope) Attributes() MutableMap { + return MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // DroppedAttributesCount returns the droppedattributescount associated with this InstrumentationScope. func (ms InstrumentationScope) DroppedAttributesCount() uint32 { return ms.getOrig().DroppedAttributesCount } +// MutableDroppedAttributesCount returns the droppedattributescount associated with this InstrumentationScope. +func (ms MutableInstrumentationScope) DroppedAttributesCount() uint32 { + return ms.getOrig().DroppedAttributesCount +} + // SetDroppedAttributesCount replaces the droppedattributescount associated with this InstrumentationScope. -func (ms InstrumentationScope) SetDroppedAttributesCount(v uint32) { +func (ms MutableInstrumentationScope) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms InstrumentationScope) CopyTo(dest InstrumentationScope) { +func (ms InstrumentationScope) CopyTo(dest MutableInstrumentationScope) { dest.SetName(ms.Name()) dest.SetVersion(ms.Version()) ms.Attributes().CopyTo(dest.Attributes()) dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableInstrumentationScope) CopyTo(dest MutableInstrumentationScope) { + newInstrumentationScope(ms.getOrig()).CopyTo(dest) +} + // Slice logically represents a slice of Value. // // This is a reference type. If passed by value and callee modifies it, the @@ -107,19 +142,33 @@ func (ms InstrumentationScope) CopyTo(dest InstrumentationScope) { // Important: zero-initialized instance is not valid for use. type Slice internal.Slice +type MutableSlice internal.MutableSlice + func newSlice(orig *[]otlpcommon.AnyValue) Slice { return Slice(internal.NewSlice(orig)) } +func newMutableSlice(orig *[]otlpcommon.AnyValue) MutableSlice { + return MutableSlice(internal.NewSlice(orig)) +} + func (ms Slice) getOrig() *[]otlpcommon.AnyValue { return internal.GetOrigSlice(internal.Slice(ms)) } +func (ms MutableSlice) getOrig() *[]otlpcommon.AnyValue { + return internal.GetMutableOrigSlice(internal.MutableSlice(ms)) +} + +func (ms MutableSlice) immutable() Slice { + return newSlice(ms.getOrig()) +} + // NewSlice creates a Slice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewSlice() Slice { +func NewSlice() MutableSlice { orig := []otlpcommon.AnyValue(nil) - return Slice(internal.NewSlice(&orig)) + return MutableSlice(internal.NewSlice(&orig)) } // Len returns the number of elements in the slice. @@ -129,6 +178,10 @@ func (es Slice) Len() int { return len(*es.getOrig()) } +func (es MutableSlice) Len() int { + return newMutableSlice(es.getOrig()).Len() +} + // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: @@ -141,8 +194,12 @@ func (es Slice) At(ix int) Value { return newValue(&(*es.getOrig())[ix]) } +func (es MutableSlice) At(ix int) MutableValue { + return newMutableValue(&(*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es Slice) CopyTo(dest Slice) { +func (es Slice) CopyTo(dest MutableSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { @@ -152,10 +209,15 @@ func (es Slice) CopyTo(dest Slice) { } for i := range *es.getOrig() { - newValue(&(*es.getOrig())[i]).CopyTo(newValue(&(*dest.getOrig())[i])) + newValue(&(*es.getOrig())[i]).CopyTo(newMutableValue(&(*dest.getOrig())[i])) } } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableSlice) CopyTo(dest MutableSlice) { + newSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -168,7 +230,7 @@ func (es Slice) CopyTo(dest Slice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es Slice) EnsureCapacity(newCap int) { +func (es MutableSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -181,14 +243,14 @@ func (es Slice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty Value. // It returns the newly added Value. -func (es Slice) AppendEmpty() Value { +func (es MutableSlice) AppendEmpty() MutableValue { *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) { +func (es MutableSlice) MoveAndAppendTo(dest MutableSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -200,7 +262,7 @@ func (es Slice) MoveAndAppendTo(dest Slice) { // 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) { +func (es MutableSlice) RemoveIf(f func(MutableValue) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { diff --git a/pdata/pcommon/generated_common_test.go b/pdata/pcommon/generated_common_test.go index ab221ac43e3..41c23403635 100644 --- a/pdata/pcommon/generated_common_test.go +++ b/pdata/pcommon/generated_common_test.go @@ -27,11 +27,11 @@ import ( ) func TestInstrumentationScope_MoveTo(t *testing.T) { - ms := InstrumentationScope(internal.GenerateTestInstrumentationScope()) + ms := MutableInstrumentationScope{internal.GenerateTestInstrumentationScope()} dest := NewInstrumentationScope() ms.MoveTo(dest) assert.Equal(t, NewInstrumentationScope(), ms) - assert.Equal(t, InstrumentationScope(internal.GenerateTestInstrumentationScope()), dest) + assert.Equal(t, MutableInstrumentationScope(internal.GenerateTestInstrumentationScope()), dest) } func TestInstrumentationScope_CopyTo(t *testing.T) { @@ -39,7 +39,7 @@ func TestInstrumentationScope_CopyTo(t *testing.T) { orig := NewInstrumentationScope() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = InstrumentationScope(internal.GenerateTestInstrumentationScope()) + orig = MutableInstrumentationScope(internal.GenerateTestInstrumentationScope()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -85,7 +85,7 @@ func TestSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestValue(internal.Value(el)) + internal.FillTestValue(internal.MutableValue(el)) assert.Equal(t, testVal, el) } } diff --git a/pdata/pcommon/generated_primitive_slice.go b/pdata/pcommon/generated_primitive_slice.go index 8289a7e3c20..9ecd43e0f90 100644 --- a/pdata/pcommon/generated_primitive_slice.go +++ b/pdata/pcommon/generated_primitive_slice.go @@ -26,14 +26,24 @@ import "go.opentelemetry.io/collector/pdata/internal" // Important: zero-initialized instance is not valid for use. type ByteSlice internal.ByteSlice +type MutableByteSlice internal.MutableByteSlice + func (ms ByteSlice) getOrig() *[]byte { return internal.GetOrigByteSlice(internal.ByteSlice(ms)) } +func (ms MutableByteSlice) getOrig() *[]byte { + return internal.GetMutableOrigByteSlice(internal.MutableByteSlice(ms)) +} + +func (ms MutableByteSlice) immutable() ByteSlice { + return ByteSlice(internal.NewByteSlice(ms.getOrig())) +} + // NewByteSlice creates a new empty ByteSlice. -func NewByteSlice() ByteSlice { +func NewByteSlice() MutableByteSlice { orig := []byte(nil) - return ByteSlice(internal.NewByteSlice(&orig)) + return MutableByteSlice(internal.NewMutableByteSlice(&orig)) } // AsRaw returns a copy of the []byte slice. @@ -41,8 +51,12 @@ func (ms ByteSlice) AsRaw() []byte { return copyByteSlice(nil, *ms.getOrig()) } +func (ms MutableByteSlice) AsRaw() []byte { + return ms.immutable().AsRaw() +} + // FromRaw copies raw []byte into the slice ByteSlice. -func (ms ByteSlice) FromRaw(val []byte) { +func (ms MutableByteSlice) FromRaw(val []byte) { *ms.getOrig() = copyByteSlice(*ms.getOrig(), val) } @@ -52,15 +66,23 @@ func (ms ByteSlice) Len() int { return len(*ms.getOrig()) } +func (ms MutableByteSlice) Len() int { + return ms.immutable().Len() +} + // At returns an item from particular index. // Equivalent of byteSlice[i]. func (ms ByteSlice) At(i int) byte { return (*ms.getOrig())[i] } +func (ms MutableByteSlice) At(i int) byte { + return ms.immutable().At(i) +} + // SetAt sets byte item at particular index. // Equivalent of byteSlice[i] = val -func (ms ByteSlice) SetAt(i int, val byte) { +func (ms MutableByteSlice) SetAt(i int, val byte) { (*ms.getOrig())[i] = val } @@ -70,7 +92,7 @@ func (ms ByteSlice) SetAt(i int, val byte) { // buf := make([]byte, len(byteSlice), newCap) // copy(buf, byteSlice) // byteSlice = buf -func (ms ByteSlice) EnsureCapacity(newCap int) { +func (ms MutableByteSlice) EnsureCapacity(newCap int) { oldCap := cap(*ms.getOrig()) if newCap <= oldCap { return @@ -83,22 +105,26 @@ func (ms ByteSlice) EnsureCapacity(newCap int) { // Append appends extra elements to ByteSlice. // Equivalent of byteSlice = append(byteSlice, elms...) -func (ms ByteSlice) Append(elms ...byte) { +func (ms MutableByteSlice) Append(elms ...byte) { *ms.getOrig() = append(*ms.getOrig(), elms...) } // MoveTo moves all elements from the current slice overriding the destination and // resetting the current instance to its zero value. -func (ms ByteSlice) MoveTo(dest ByteSlice) { +func (ms MutableByteSlice) MoveTo(dest MutableByteSlice) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = nil } // CopyTo copies all elements from the current slice overriding the destination. -func (ms ByteSlice) CopyTo(dest ByteSlice) { +func (ms ByteSlice) CopyTo(dest MutableByteSlice) { *dest.getOrig() = copyByteSlice(*dest.getOrig(), *ms.getOrig()) } +func (ms MutableByteSlice) CopyTo(dest MutableByteSlice) { + ms.immutable().CopyTo(dest) +} + func copyByteSlice(dst, src []byte) []byte { dst = dst[:0] return append(dst, src...) @@ -111,14 +137,24 @@ func copyByteSlice(dst, src []byte) []byte { // Important: zero-initialized instance is not valid for use. type Float64Slice internal.Float64Slice +type MutableFloat64Slice internal.MutableFloat64Slice + func (ms Float64Slice) getOrig() *[]float64 { return internal.GetOrigFloat64Slice(internal.Float64Slice(ms)) } +func (ms MutableFloat64Slice) getOrig() *[]float64 { + return internal.GetMutableOrigFloat64Slice(internal.MutableFloat64Slice(ms)) +} + +func (ms MutableFloat64Slice) immutable() Float64Slice { + return Float64Slice(internal.NewFloat64Slice(ms.getOrig())) +} + // NewFloat64Slice creates a new empty Float64Slice. -func NewFloat64Slice() Float64Slice { +func NewFloat64Slice() MutableFloat64Slice { orig := []float64(nil) - return Float64Slice(internal.NewFloat64Slice(&orig)) + return MutableFloat64Slice(internal.NewMutableFloat64Slice(&orig)) } // AsRaw returns a copy of the []float64 slice. @@ -126,8 +162,12 @@ func (ms Float64Slice) AsRaw() []float64 { return copyFloat64Slice(nil, *ms.getOrig()) } +func (ms MutableFloat64Slice) AsRaw() []float64 { + return ms.immutable().AsRaw() +} + // FromRaw copies raw []float64 into the slice Float64Slice. -func (ms Float64Slice) FromRaw(val []float64) { +func (ms MutableFloat64Slice) FromRaw(val []float64) { *ms.getOrig() = copyFloat64Slice(*ms.getOrig(), val) } @@ -137,15 +177,23 @@ func (ms Float64Slice) Len() int { return len(*ms.getOrig()) } +func (ms MutableFloat64Slice) Len() int { + return ms.immutable().Len() +} + // At returns an item from particular index. // Equivalent of float64Slice[i]. func (ms Float64Slice) At(i int) float64 { return (*ms.getOrig())[i] } +func (ms MutableFloat64Slice) At(i int) float64 { + return ms.immutable().At(i) +} + // SetAt sets float64 item at particular index. // Equivalent of float64Slice[i] = val -func (ms Float64Slice) SetAt(i int, val float64) { +func (ms MutableFloat64Slice) SetAt(i int, val float64) { (*ms.getOrig())[i] = val } @@ -155,7 +203,7 @@ func (ms Float64Slice) SetAt(i int, val float64) { // buf := make([]float64, len(float64Slice), newCap) // copy(buf, float64Slice) // float64Slice = buf -func (ms Float64Slice) EnsureCapacity(newCap int) { +func (ms MutableFloat64Slice) EnsureCapacity(newCap int) { oldCap := cap(*ms.getOrig()) if newCap <= oldCap { return @@ -168,22 +216,26 @@ func (ms Float64Slice) EnsureCapacity(newCap int) { // Append appends extra elements to Float64Slice. // Equivalent of float64Slice = append(float64Slice, elms...) -func (ms Float64Slice) Append(elms ...float64) { +func (ms MutableFloat64Slice) Append(elms ...float64) { *ms.getOrig() = append(*ms.getOrig(), elms...) } // MoveTo moves all elements from the current slice overriding the destination and // resetting the current instance to its zero value. -func (ms Float64Slice) MoveTo(dest Float64Slice) { +func (ms MutableFloat64Slice) MoveTo(dest MutableFloat64Slice) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = nil } // CopyTo copies all elements from the current slice overriding the destination. -func (ms Float64Slice) CopyTo(dest Float64Slice) { +func (ms Float64Slice) CopyTo(dest MutableFloat64Slice) { *dest.getOrig() = copyFloat64Slice(*dest.getOrig(), *ms.getOrig()) } +func (ms MutableFloat64Slice) CopyTo(dest MutableFloat64Slice) { + ms.immutable().CopyTo(dest) +} + func copyFloat64Slice(dst, src []float64) []float64 { dst = dst[:0] return append(dst, src...) @@ -196,14 +248,24 @@ func copyFloat64Slice(dst, src []float64) []float64 { // Important: zero-initialized instance is not valid for use. type UInt64Slice internal.UInt64Slice +type MutableUInt64Slice internal.MutableUInt64Slice + func (ms UInt64Slice) getOrig() *[]uint64 { return internal.GetOrigUInt64Slice(internal.UInt64Slice(ms)) } +func (ms MutableUInt64Slice) getOrig() *[]uint64 { + return internal.GetMutableOrigUInt64Slice(internal.MutableUInt64Slice(ms)) +} + +func (ms MutableUInt64Slice) immutable() UInt64Slice { + return UInt64Slice(internal.NewUInt64Slice(ms.getOrig())) +} + // NewUInt64Slice creates a new empty UInt64Slice. -func NewUInt64Slice() UInt64Slice { +func NewUInt64Slice() MutableUInt64Slice { orig := []uint64(nil) - return UInt64Slice(internal.NewUInt64Slice(&orig)) + return MutableUInt64Slice(internal.NewMutableUInt64Slice(&orig)) } // AsRaw returns a copy of the []uint64 slice. @@ -211,8 +273,12 @@ func (ms UInt64Slice) AsRaw() []uint64 { return copyUInt64Slice(nil, *ms.getOrig()) } +func (ms MutableUInt64Slice) AsRaw() []uint64 { + return ms.immutable().AsRaw() +} + // FromRaw copies raw []uint64 into the slice UInt64Slice. -func (ms UInt64Slice) FromRaw(val []uint64) { +func (ms MutableUInt64Slice) FromRaw(val []uint64) { *ms.getOrig() = copyUInt64Slice(*ms.getOrig(), val) } @@ -222,15 +288,23 @@ func (ms UInt64Slice) Len() int { return len(*ms.getOrig()) } +func (ms MutableUInt64Slice) Len() int { + return ms.immutable().Len() +} + // At returns an item from particular index. // Equivalent of uInt64Slice[i]. func (ms UInt64Slice) At(i int) uint64 { return (*ms.getOrig())[i] } +func (ms MutableUInt64Slice) At(i int) uint64 { + return ms.immutable().At(i) +} + // SetAt sets uint64 item at particular index. // Equivalent of uInt64Slice[i] = val -func (ms UInt64Slice) SetAt(i int, val uint64) { +func (ms MutableUInt64Slice) SetAt(i int, val uint64) { (*ms.getOrig())[i] = val } @@ -240,7 +314,7 @@ func (ms UInt64Slice) SetAt(i int, val uint64) { // buf := make([]uint64, len(uInt64Slice), newCap) // copy(buf, uInt64Slice) // uInt64Slice = buf -func (ms UInt64Slice) EnsureCapacity(newCap int) { +func (ms MutableUInt64Slice) EnsureCapacity(newCap int) { oldCap := cap(*ms.getOrig()) if newCap <= oldCap { return @@ -253,22 +327,26 @@ func (ms UInt64Slice) EnsureCapacity(newCap int) { // Append appends extra elements to UInt64Slice. // Equivalent of uInt64Slice = append(uInt64Slice, elms...) -func (ms UInt64Slice) Append(elms ...uint64) { +func (ms MutableUInt64Slice) Append(elms ...uint64) { *ms.getOrig() = append(*ms.getOrig(), elms...) } // MoveTo moves all elements from the current slice overriding the destination and // resetting the current instance to its zero value. -func (ms UInt64Slice) MoveTo(dest UInt64Slice) { +func (ms MutableUInt64Slice) MoveTo(dest MutableUInt64Slice) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = nil } // CopyTo copies all elements from the current slice overriding the destination. -func (ms UInt64Slice) CopyTo(dest UInt64Slice) { +func (ms UInt64Slice) CopyTo(dest MutableUInt64Slice) { *dest.getOrig() = copyUInt64Slice(*dest.getOrig(), *ms.getOrig()) } +func (ms MutableUInt64Slice) CopyTo(dest MutableUInt64Slice) { + ms.immutable().CopyTo(dest) +} + func copyUInt64Slice(dst, src []uint64) []uint64 { dst = dst[:0] return append(dst, src...) diff --git a/pdata/pcommon/generated_resource.go b/pdata/pcommon/generated_resource.go index f98f10f53f6..157fabac6e1 100644 --- a/pdata/pcommon/generated_resource.go +++ b/pdata/pcommon/generated_resource.go @@ -32,25 +32,35 @@ import ( type Resource internal.Resource +type MutableResource internal.MutableResource + func newResource(orig *otlpresource.Resource) Resource { return Resource(internal.NewResource(orig)) } +func newMutableResource(orig *otlpresource.Resource) MutableResource { + return MutableResource(internal.NewResource(orig)) +} + func (ms Resource) getOrig() *otlpresource.Resource { return internal.GetOrigResource(internal.Resource(ms)) } +func (ms MutableResource) getOrig() *otlpresource.Resource { + return internal.GetMutableOrigResource(internal.MutableResource(ms)) +} + // NewResource creates a new empty Resource. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewResource() Resource { - return newResource(&otlpresource.Resource{}) +func NewResource() MutableResource { + return newMutableResource(&otlpresource.Resource{}) } // MoveTo moves all properties from the current struct overriding the destination and // resetting the current instance to its zero value -func (ms Resource) MoveTo(dest Resource) { +func (ms MutableResource) MoveTo(dest MutableResource) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpresource.Resource{} } @@ -60,18 +70,33 @@ func (ms Resource) Attributes() Map { return Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this Resource. +func (ms MutableResource) Attributes() MutableMap { + return MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // DroppedAttributesCount returns the droppedattributescount associated with this Resource. func (ms Resource) DroppedAttributesCount() uint32 { return ms.getOrig().DroppedAttributesCount } +// MutableDroppedAttributesCount returns the droppedattributescount associated with this Resource. +func (ms MutableResource) DroppedAttributesCount() uint32 { + return ms.getOrig().DroppedAttributesCount +} + // SetDroppedAttributesCount replaces the droppedattributescount associated with this Resource. -func (ms Resource) SetDroppedAttributesCount(v uint32) { +func (ms MutableResource) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms Resource) CopyTo(dest Resource) { +func (ms Resource) CopyTo(dest MutableResource) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableResource) CopyTo(dest MutableResource) { + newResource(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/pcommon/generated_resource_test.go b/pdata/pcommon/generated_resource_test.go index 30710081bd6..2702ef536ff 100644 --- a/pdata/pcommon/generated_resource_test.go +++ b/pdata/pcommon/generated_resource_test.go @@ -26,11 +26,11 @@ import ( ) func TestResource_MoveTo(t *testing.T) { - ms := Resource(internal.GenerateTestResource()) + ms := MutableResource{internal.GenerateTestResource()} dest := NewResource() ms.MoveTo(dest) assert.Equal(t, NewResource(), ms) - assert.Equal(t, Resource(internal.GenerateTestResource()), dest) + assert.Equal(t, MutableResource(internal.GenerateTestResource()), dest) } func TestResource_CopyTo(t *testing.T) { @@ -38,7 +38,7 @@ func TestResource_CopyTo(t *testing.T) { orig := NewResource() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Resource(internal.GenerateTestResource()) + orig = MutableResource(internal.GenerateTestResource()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } diff --git a/pdata/plog/generated_logs.go b/pdata/plog/generated_logs.go index b9071256387..cd628999171 100644 --- a/pdata/plog/generated_logs.go +++ b/pdata/plog/generated_logs.go @@ -35,19 +35,29 @@ import ( // Important: zero-initialized instance is not valid for use. type ResourceLogsSlice internal.ResourceLogsSlice +type MutableResourceLogsSlice internal.MutableResourceLogsSlice + func newResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) ResourceLogsSlice { return ResourceLogsSlice(internal.NewResourceLogsSlice(orig)) } +func newMutableResourceLogsSlice(orig *[]*otlplogs.ResourceLogs) MutableResourceLogsSlice { + return MutableResourceLogsSlice(internal.NewResourceLogsSlice(orig)) +} + func (ms ResourceLogsSlice) getOrig() *[]*otlplogs.ResourceLogs { return internal.GetOrigResourceLogsSlice(internal.ResourceLogsSlice(ms)) } +func (ms MutableResourceLogsSlice) getOrig() *[]*otlplogs.ResourceLogs { + return internal.GetMutableOrigResourceLogsSlice(internal.MutableResourceLogsSlice(ms)) +} + // NewResourceLogsSlice creates a ResourceLogsSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewResourceLogsSlice() ResourceLogsSlice { +func NewResourceLogsSlice() MutableResourceLogsSlice { orig := []*otlplogs.ResourceLogs(nil) - return newResourceLogsSlice(&orig) + return newMutableResourceLogsSlice(&orig) } // Len returns the number of elements in the slice. @@ -57,6 +67,10 @@ func (es ResourceLogsSlice) Len() int { return len(*es.getOrig()) } +func (es MutableResourceLogsSlice) 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: @@ -69,14 +83,18 @@ func (es ResourceLogsSlice) At(ix int) ResourceLogs { return newResourceLogs((*es.getOrig())[ix]) } +func (es MutableResourceLogsSlice) At(ix int) MutableResourceLogs { + return newMutableResourceLogs((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { +func (es ResourceLogsSlice) CopyTo(dest MutableResourceLogsSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newResourceLogs((*es.getOrig())[i]).CopyTo(newResourceLogs((*dest.getOrig())[i])) + newResourceLogs((*es.getOrig())[i]).CopyTo(newMutableResourceLogs((*dest.getOrig())[i])) } return } @@ -84,11 +102,16 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { wrappers := make([]*otlplogs.ResourceLogs, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newResourceLogs((*es.getOrig())[i]).CopyTo(newResourceLogs(wrappers[i])) + newResourceLogs((*es.getOrig())[i]).CopyTo(newMutableResourceLogs(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableResourceLogsSlice) CopyTo(dest MutableResourceLogsSlice) { + newResourceLogsSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -101,7 +124,7 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ResourceLogsSlice) EnsureCapacity(newCap int) { +func (es MutableResourceLogsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -114,7 +137,7 @@ func (es ResourceLogsSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ResourceLogs. // It returns the newly added ResourceLogs. -func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { +func (es MutableResourceLogsSlice) AppendEmpty() MutableResourceLogs { *es.getOrig() = append(*es.getOrig(), &otlplogs.ResourceLogs{}) return es.At(es.Len() - 1) } @@ -122,13 +145,13 @@ func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { // Sort sorts the ResourceLogs elements within ResourceLogsSlice given the // provided less function so that two instances of ResourceLogsSlice // can be compared. -func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool) { +func (es MutableResourceLogsSlice) Sort(less func(a, b MutableResourceLogs) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableResourceLogsSlice) MoveAndAppendTo(dest MutableResourceLogsSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -140,7 +163,7 @@ func (es ResourceLogsSlice) MoveAndAppendTo(dest ResourceLogsSlice) { // 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) { +func (es MutableResourceLogsSlice) RemoveIf(f func(MutableResourceLogs) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -168,25 +191,35 @@ func (es ResourceLogsSlice) RemoveIf(f func(ResourceLogs) bool) { type ResourceLogs internal.ResourceLogs +type MutableResourceLogs internal.MutableResourceLogs + func newResourceLogs(orig *otlplogs.ResourceLogs) ResourceLogs { return ResourceLogs(internal.NewResourceLogs(orig)) } +func newMutableResourceLogs(orig *otlplogs.ResourceLogs) MutableResourceLogs { + return MutableResourceLogs(internal.NewResourceLogs(orig)) +} + func (ms ResourceLogs) getOrig() *otlplogs.ResourceLogs { return internal.GetOrigResourceLogs(internal.ResourceLogs(ms)) } +func (ms MutableResourceLogs) getOrig() *otlplogs.ResourceLogs { + return internal.GetMutableOrigResourceLogs(internal.MutableResourceLogs(ms)) +} + // NewResourceLogs creates a new empty ResourceLogs. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewResourceLogs() ResourceLogs { - return newResourceLogs(&otlplogs.ResourceLogs{}) +func NewResourceLogs() MutableResourceLogs { + return newMutableResourceLogs(&otlplogs.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) { +func (ms MutableResourceLogs) MoveTo(dest MutableResourceLogs) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlplogs.ResourceLogs{} } @@ -196,13 +229,23 @@ func (ms ResourceLogs) Resource() pcommon.Resource { return pcommon.Resource(internal.NewResource(&ms.getOrig().Resource)) } +// Resource returns the resource associated with this ResourceLogs. +func (ms MutableResourceLogs) Resource() pcommon.MutableResource { + return pcommon.MutableResource(internal.NewMutableResource(&ms.getOrig().Resource)) +} + // SchemaUrl returns the schemaurl associated with this ResourceLogs. func (ms ResourceLogs) SchemaUrl() string { return ms.getOrig().SchemaUrl } +// MutableSchemaUrl returns the schemaurl associated with this ResourceLogs. +func (ms MutableResourceLogs) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + // SetSchemaUrl replaces the schemaurl associated with this ResourceLogs. -func (ms ResourceLogs) SetSchemaUrl(v string) { +func (ms MutableResourceLogs) SetSchemaUrl(v string) { ms.getOrig().SchemaUrl = v } @@ -211,13 +254,23 @@ func (ms ResourceLogs) ScopeLogs() ScopeLogsSlice { return ScopeLogsSlice(internal.NewScopeLogsSlice(&ms.getOrig().ScopeLogs)) } +// ScopeLogs returns the ScopeLogs associated with this ResourceLogs. +func (ms MutableResourceLogs) ScopeLogs() MutableScopeLogsSlice { + return MutableScopeLogsSlice(internal.NewMutableScopeLogsSlice(&ms.getOrig().ScopeLogs)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ResourceLogs) CopyTo(dest ResourceLogs) { +func (ms ResourceLogs) CopyTo(dest MutableResourceLogs) { ms.Resource().CopyTo(dest.Resource()) dest.SetSchemaUrl(ms.SchemaUrl()) ms.ScopeLogs().CopyTo(dest.ScopeLogs()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableResourceLogs) CopyTo(dest MutableResourceLogs) { + newResourceLogs(ms.getOrig()).CopyTo(dest) +} + // ScopeLogsSlice logically represents a slice of ScopeLogs. // // This is a reference type. If passed by value and callee modifies it, the @@ -227,19 +280,29 @@ func (ms ResourceLogs) CopyTo(dest ResourceLogs) { // Important: zero-initialized instance is not valid for use. type ScopeLogsSlice internal.ScopeLogsSlice +type MutableScopeLogsSlice internal.MutableScopeLogsSlice + func newScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) ScopeLogsSlice { return ScopeLogsSlice(internal.NewScopeLogsSlice(orig)) } +func newMutableScopeLogsSlice(orig *[]*otlplogs.ScopeLogs) MutableScopeLogsSlice { + return MutableScopeLogsSlice(internal.NewScopeLogsSlice(orig)) +} + func (ms ScopeLogsSlice) getOrig() *[]*otlplogs.ScopeLogs { return internal.GetOrigScopeLogsSlice(internal.ScopeLogsSlice(ms)) } +func (ms MutableScopeLogsSlice) getOrig() *[]*otlplogs.ScopeLogs { + return internal.GetMutableOrigScopeLogsSlice(internal.MutableScopeLogsSlice(ms)) +} + // NewScopeLogsSlice creates a ScopeLogsSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewScopeLogsSlice() ScopeLogsSlice { +func NewScopeLogsSlice() MutableScopeLogsSlice { orig := []*otlplogs.ScopeLogs(nil) - return newScopeLogsSlice(&orig) + return newMutableScopeLogsSlice(&orig) } // Len returns the number of elements in the slice. @@ -249,6 +312,10 @@ func (es ScopeLogsSlice) Len() int { return len(*es.getOrig()) } +func (es MutableScopeLogsSlice) 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: @@ -261,14 +328,18 @@ func (es ScopeLogsSlice) At(ix int) ScopeLogs { return newScopeLogs((*es.getOrig())[ix]) } +func (es MutableScopeLogsSlice) At(ix int) MutableScopeLogs { + return newMutableScopeLogs((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { +func (es ScopeLogsSlice) CopyTo(dest MutableScopeLogsSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newScopeLogs((*es.getOrig())[i]).CopyTo(newScopeLogs((*dest.getOrig())[i])) + newScopeLogs((*es.getOrig())[i]).CopyTo(newMutableScopeLogs((*dest.getOrig())[i])) } return } @@ -276,11 +347,16 @@ func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { wrappers := make([]*otlplogs.ScopeLogs, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newScopeLogs((*es.getOrig())[i]).CopyTo(newScopeLogs(wrappers[i])) + newScopeLogs((*es.getOrig())[i]).CopyTo(newMutableScopeLogs(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableScopeLogsSlice) CopyTo(dest MutableScopeLogsSlice) { + newScopeLogsSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -293,7 +369,7 @@ func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ScopeLogsSlice) EnsureCapacity(newCap int) { +func (es MutableScopeLogsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -306,7 +382,7 @@ func (es ScopeLogsSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ScopeLogs. // It returns the newly added ScopeLogs. -func (es ScopeLogsSlice) AppendEmpty() ScopeLogs { +func (es MutableScopeLogsSlice) AppendEmpty() MutableScopeLogs { *es.getOrig() = append(*es.getOrig(), &otlplogs.ScopeLogs{}) return es.At(es.Len() - 1) } @@ -314,13 +390,13 @@ func (es ScopeLogsSlice) AppendEmpty() ScopeLogs { // Sort sorts the ScopeLogs elements within ScopeLogsSlice given the // provided less function so that two instances of ScopeLogsSlice // can be compared. -func (es ScopeLogsSlice) Sort(less func(a, b ScopeLogs) bool) { +func (es MutableScopeLogsSlice) Sort(less func(a, b MutableScopeLogs) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableScopeLogsSlice) MoveAndAppendTo(dest MutableScopeLogsSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -332,7 +408,7 @@ func (es ScopeLogsSlice) MoveAndAppendTo(dest ScopeLogsSlice) { // 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) { +func (es MutableScopeLogsSlice) RemoveIf(f func(MutableScopeLogs) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -360,25 +436,35 @@ func (es ScopeLogsSlice) RemoveIf(f func(ScopeLogs) bool) { type ScopeLogs internal.ScopeLogs +type MutableScopeLogs internal.MutableScopeLogs + func newScopeLogs(orig *otlplogs.ScopeLogs) ScopeLogs { return ScopeLogs(internal.NewScopeLogs(orig)) } +func newMutableScopeLogs(orig *otlplogs.ScopeLogs) MutableScopeLogs { + return MutableScopeLogs(internal.NewScopeLogs(orig)) +} + func (ms ScopeLogs) getOrig() *otlplogs.ScopeLogs { return internal.GetOrigScopeLogs(internal.ScopeLogs(ms)) } +func (ms MutableScopeLogs) getOrig() *otlplogs.ScopeLogs { + return internal.GetMutableOrigScopeLogs(internal.MutableScopeLogs(ms)) +} + // NewScopeLogs creates a new empty ScopeLogs. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewScopeLogs() ScopeLogs { - return newScopeLogs(&otlplogs.ScopeLogs{}) +func NewScopeLogs() MutableScopeLogs { + return newMutableScopeLogs(&otlplogs.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) { +func (ms MutableScopeLogs) MoveTo(dest MutableScopeLogs) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlplogs.ScopeLogs{} } @@ -388,13 +474,23 @@ func (ms ScopeLogs) Scope() pcommon.InstrumentationScope { return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.getOrig().Scope)) } +// Scope returns the scope associated with this ScopeLogs. +func (ms MutableScopeLogs) Scope() pcommon.MutableInstrumentationScope { + return pcommon.MutableInstrumentationScope(internal.NewMutableInstrumentationScope(&ms.getOrig().Scope)) +} + // SchemaUrl returns the schemaurl associated with this ScopeLogs. func (ms ScopeLogs) SchemaUrl() string { return ms.getOrig().SchemaUrl } +// MutableSchemaUrl returns the schemaurl associated with this ScopeLogs. +func (ms MutableScopeLogs) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + // SetSchemaUrl replaces the schemaurl associated with this ScopeLogs. -func (ms ScopeLogs) SetSchemaUrl(v string) { +func (ms MutableScopeLogs) SetSchemaUrl(v string) { ms.getOrig().SchemaUrl = v } @@ -403,13 +499,23 @@ func (ms ScopeLogs) LogRecords() LogRecordSlice { return LogRecordSlice(internal.NewLogRecordSlice(&ms.getOrig().LogRecords)) } +// LogRecords returns the LogRecords associated with this ScopeLogs. +func (ms MutableScopeLogs) LogRecords() MutableLogRecordSlice { + return MutableLogRecordSlice(internal.NewMutableLogRecordSlice(&ms.getOrig().LogRecords)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ScopeLogs) CopyTo(dest ScopeLogs) { +func (ms ScopeLogs) CopyTo(dest MutableScopeLogs) { ms.Scope().CopyTo(dest.Scope()) dest.SetSchemaUrl(ms.SchemaUrl()) ms.LogRecords().CopyTo(dest.LogRecords()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableScopeLogs) CopyTo(dest MutableScopeLogs) { + newScopeLogs(ms.getOrig()).CopyTo(dest) +} + // LogRecordSlice logically represents a slice of LogRecord. // // This is a reference type. If passed by value and callee modifies it, the @@ -419,19 +525,29 @@ func (ms ScopeLogs) CopyTo(dest ScopeLogs) { // Important: zero-initialized instance is not valid for use. type LogRecordSlice internal.LogRecordSlice +type MutableLogRecordSlice internal.MutableLogRecordSlice + func newLogRecordSlice(orig *[]*otlplogs.LogRecord) LogRecordSlice { return LogRecordSlice(internal.NewLogRecordSlice(orig)) } +func newMutableLogRecordSlice(orig *[]*otlplogs.LogRecord) MutableLogRecordSlice { + return MutableLogRecordSlice(internal.NewLogRecordSlice(orig)) +} + func (ms LogRecordSlice) getOrig() *[]*otlplogs.LogRecord { return internal.GetOrigLogRecordSlice(internal.LogRecordSlice(ms)) } +func (ms MutableLogRecordSlice) getOrig() *[]*otlplogs.LogRecord { + return internal.GetMutableOrigLogRecordSlice(internal.MutableLogRecordSlice(ms)) +} + // NewLogRecordSlice creates a LogRecordSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewLogRecordSlice() LogRecordSlice { +func NewLogRecordSlice() MutableLogRecordSlice { orig := []*otlplogs.LogRecord(nil) - return newLogRecordSlice(&orig) + return newMutableLogRecordSlice(&orig) } // Len returns the number of elements in the slice. @@ -441,6 +557,10 @@ func (es LogRecordSlice) Len() int { return len(*es.getOrig()) } +func (es MutableLogRecordSlice) 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: @@ -453,14 +573,18 @@ func (es LogRecordSlice) At(ix int) LogRecord { return newLogRecord((*es.getOrig())[ix]) } +func (es MutableLogRecordSlice) At(ix int) MutableLogRecord { + return newMutableLogRecord((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { +func (es LogRecordSlice) CopyTo(dest MutableLogRecordSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newLogRecord((*es.getOrig())[i]).CopyTo(newLogRecord((*dest.getOrig())[i])) + newLogRecord((*es.getOrig())[i]).CopyTo(newMutableLogRecord((*dest.getOrig())[i])) } return } @@ -468,11 +592,16 @@ func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { wrappers := make([]*otlplogs.LogRecord, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newLogRecord((*es.getOrig())[i]).CopyTo(newLogRecord(wrappers[i])) + newLogRecord((*es.getOrig())[i]).CopyTo(newMutableLogRecord(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableLogRecordSlice) CopyTo(dest MutableLogRecordSlice) { + newLogRecordSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -485,7 +614,7 @@ func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es LogRecordSlice) EnsureCapacity(newCap int) { +func (es MutableLogRecordSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -498,7 +627,7 @@ func (es LogRecordSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty LogRecord. // It returns the newly added LogRecord. -func (es LogRecordSlice) AppendEmpty() LogRecord { +func (es MutableLogRecordSlice) AppendEmpty() MutableLogRecord { *es.getOrig() = append(*es.getOrig(), &otlplogs.LogRecord{}) return es.At(es.Len() - 1) } @@ -506,13 +635,13 @@ func (es LogRecordSlice) AppendEmpty() LogRecord { // Sort sorts the LogRecord elements within LogRecordSlice given the // provided less function so that two instances of LogRecordSlice // can be compared. -func (es LogRecordSlice) Sort(less func(a, b LogRecord) bool) { +func (es MutableLogRecordSlice) Sort(less func(a, b MutableLogRecord) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableLogRecordSlice) MoveAndAppendTo(dest MutableLogRecordSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -524,7 +653,7 @@ func (es LogRecordSlice) MoveAndAppendTo(dest LogRecordSlice) { // 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) { +func (es MutableLogRecordSlice) RemoveIf(f func(MutableLogRecord) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -553,25 +682,35 @@ func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool) { type LogRecord internal.LogRecord +type MutableLogRecord internal.MutableLogRecord + func newLogRecord(orig *otlplogs.LogRecord) LogRecord { return LogRecord(internal.NewLogRecord(orig)) } +func newMutableLogRecord(orig *otlplogs.LogRecord) MutableLogRecord { + return MutableLogRecord(internal.NewLogRecord(orig)) +} + func (ms LogRecord) getOrig() *otlplogs.LogRecord { return internal.GetOrigLogRecord(internal.LogRecord(ms)) } +func (ms MutableLogRecord) getOrig() *otlplogs.LogRecord { + return internal.GetMutableOrigLogRecord(internal.MutableLogRecord(ms)) +} + // NewLogRecord creates a new empty LogRecord. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewLogRecord() LogRecord { - return newLogRecord(&otlplogs.LogRecord{}) +func NewLogRecord() MutableLogRecord { + return newMutableLogRecord(&otlplogs.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) { +func (ms MutableLogRecord) MoveTo(dest MutableLogRecord) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlplogs.LogRecord{} } @@ -581,8 +720,13 @@ func (ms LogRecord) ObservedTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().ObservedTimeUnixNano) } +// ObservedTimestamp returns the observedtimestamp associated with this LogRecord. +func (ms MutableLogRecord) ObservedTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().ObservedTimeUnixNano) +} + // SetObservedTimestamp replaces the observedtimestamp associated with this LogRecord. -func (ms LogRecord) SetObservedTimestamp(v pcommon.Timestamp) { +func (ms MutableLogRecord) SetObservedTimestamp(v pcommon.Timestamp) { ms.getOrig().ObservedTimeUnixNano = uint64(v) } @@ -591,8 +735,13 @@ func (ms LogRecord) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this LogRecord. +func (ms MutableLogRecord) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this LogRecord. -func (ms LogRecord) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableLogRecord) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -601,8 +750,13 @@ func (ms LogRecord) TraceID() pcommon.TraceID { return pcommon.TraceID(ms.getOrig().TraceId) } +// TraceID returns the traceid associated with this LogRecord. +func (ms MutableLogRecord) TraceID() pcommon.TraceID { + return pcommon.TraceID(ms.getOrig().TraceId) +} + // SetTraceID replaces the traceid associated with this LogRecord. -func (ms LogRecord) SetTraceID(v pcommon.TraceID) { +func (ms MutableLogRecord) SetTraceID(v pcommon.TraceID) { ms.getOrig().TraceId = data.TraceID(v) } @@ -611,8 +765,13 @@ func (ms LogRecord) SpanID() pcommon.SpanID { return pcommon.SpanID(ms.getOrig().SpanId) } +// SpanID returns the spanid associated with this LogRecord. +func (ms MutableLogRecord) SpanID() pcommon.SpanID { + return pcommon.SpanID(ms.getOrig().SpanId) +} + // SetSpanID replaces the spanid associated with this LogRecord. -func (ms LogRecord) SetSpanID(v pcommon.SpanID) { +func (ms MutableLogRecord) SetSpanID(v pcommon.SpanID) { ms.getOrig().SpanId = data.SpanID(v) } @@ -621,8 +780,13 @@ func (ms LogRecord) Flags() LogRecordFlags { return LogRecordFlags(ms.getOrig().Flags) } +// Flags returns the flags associated with this LogRecord. +func (ms MutableLogRecord) Flags() LogRecordFlags { + return LogRecordFlags(ms.getOrig().Flags) +} + // SetFlags replaces the flags associated with this LogRecord. -func (ms LogRecord) SetFlags(v LogRecordFlags) { +func (ms MutableLogRecord) SetFlags(v LogRecordFlags) { ms.getOrig().Flags = uint32(v) } @@ -631,8 +795,13 @@ func (ms LogRecord) SeverityText() string { return ms.getOrig().SeverityText } +// MutableSeverityText returns the severitytext associated with this LogRecord. +func (ms MutableLogRecord) SeverityText() string { + return ms.getOrig().SeverityText +} + // SetSeverityText replaces the severitytext associated with this LogRecord. -func (ms LogRecord) SetSeverityText(v string) { +func (ms MutableLogRecord) SetSeverityText(v string) { ms.getOrig().SeverityText = v } @@ -641,8 +810,13 @@ func (ms LogRecord) SeverityNumber() SeverityNumber { return SeverityNumber(ms.getOrig().SeverityNumber) } +// SeverityNumber returns the severitynumber associated with this LogRecord. +func (ms MutableLogRecord) SeverityNumber() SeverityNumber { + return SeverityNumber(ms.getOrig().SeverityNumber) +} + // SetSeverityNumber replaces the severitynumber associated with this LogRecord. -func (ms LogRecord) SetSeverityNumber(v SeverityNumber) { +func (ms MutableLogRecord) SetSeverityNumber(v SeverityNumber) { ms.getOrig().SeverityNumber = otlplogs.SeverityNumber(v) } @@ -651,23 +825,38 @@ func (ms LogRecord) Body() pcommon.Value { return pcommon.Value(internal.NewValue(&ms.getOrig().Body)) } +// Body returns the body associated with this LogRecord. +func (ms MutableLogRecord) Body() pcommon.MutableValue { + return pcommon.MutableValue(internal.NewMutableValue(&ms.getOrig().Body)) +} + // Attributes returns the Attributes associated with this LogRecord. func (ms LogRecord) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this LogRecord. +func (ms MutableLogRecord) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // DroppedAttributesCount returns the droppedattributescount associated with this LogRecord. func (ms LogRecord) DroppedAttributesCount() uint32 { return ms.getOrig().DroppedAttributesCount } +// MutableDroppedAttributesCount returns the droppedattributescount associated with this LogRecord. +func (ms MutableLogRecord) DroppedAttributesCount() uint32 { + return ms.getOrig().DroppedAttributesCount +} + // SetDroppedAttributesCount replaces the droppedattributescount associated with this LogRecord. -func (ms LogRecord) SetDroppedAttributesCount(v uint32) { +func (ms MutableLogRecord) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms LogRecord) CopyTo(dest LogRecord) { +func (ms LogRecord) CopyTo(dest MutableLogRecord) { dest.SetObservedTimestamp(ms.ObservedTimestamp()) dest.SetTimestamp(ms.Timestamp()) dest.SetTraceID(ms.TraceID()) @@ -679,3 +868,8 @@ func (ms LogRecord) CopyTo(dest LogRecord) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableLogRecord) CopyTo(dest MutableLogRecord) { + newLogRecord(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/plog/generated_logs_test.go b/pdata/plog/generated_logs_test.go index 178650370f7..bc215917405 100644 --- a/pdata/plog/generated_logs_test.go +++ b/pdata/plog/generated_logs_test.go @@ -41,7 +41,7 @@ func TestResourceLogsSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestResourceLogs(internal.ResourceLogs(el)) + internal.FillTestResourceLogs(internal.MutableResourceLogs(el)) assert.Equal(t, testVal, el) } } @@ -139,11 +139,11 @@ func TestResourceLogsSlice_RemoveIf(t *testing.T) { } func TestResourceLogs_MoveTo(t *testing.T) { - ms := ResourceLogs(internal.GenerateTestResourceLogs()) + ms := MutableResourceLogs{internal.GenerateTestResourceLogs()} dest := NewResourceLogs() ms.MoveTo(dest) assert.Equal(t, NewResourceLogs(), ms) - assert.Equal(t, ResourceLogs(internal.GenerateTestResourceLogs()), dest) + assert.Equal(t, MutableResourceLogs(internal.GenerateTestResourceLogs()), dest) } func TestResourceLogs_CopyTo(t *testing.T) { @@ -151,7 +151,7 @@ func TestResourceLogs_CopyTo(t *testing.T) { orig := NewResourceLogs() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ResourceLogs(internal.GenerateTestResourceLogs()) + orig = MutableResourceLogs(internal.GenerateTestResourceLogs()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -189,7 +189,7 @@ func TestScopeLogsSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestScopeLogs(internal.ScopeLogs(el)) + internal.FillTestScopeLogs(internal.MutableScopeLogs(el)) assert.Equal(t, testVal, el) } } @@ -287,11 +287,11 @@ func TestScopeLogsSlice_RemoveIf(t *testing.T) { } func TestScopeLogs_MoveTo(t *testing.T) { - ms := ScopeLogs(internal.GenerateTestScopeLogs()) + ms := MutableScopeLogs{internal.GenerateTestScopeLogs()} dest := NewScopeLogs() ms.MoveTo(dest) assert.Equal(t, NewScopeLogs(), ms) - assert.Equal(t, ScopeLogs(internal.GenerateTestScopeLogs()), dest) + assert.Equal(t, MutableScopeLogs(internal.GenerateTestScopeLogs()), dest) } func TestScopeLogs_CopyTo(t *testing.T) { @@ -299,7 +299,7 @@ func TestScopeLogs_CopyTo(t *testing.T) { orig := NewScopeLogs() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ScopeLogs(internal.GenerateTestScopeLogs()) + orig = MutableScopeLogs(internal.GenerateTestScopeLogs()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -337,7 +337,7 @@ func TestLogRecordSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestLogRecord(internal.LogRecord(el)) + internal.FillTestLogRecord(internal.MutableLogRecord(el)) assert.Equal(t, testVal, el) } } @@ -435,11 +435,11 @@ func TestLogRecordSlice_RemoveIf(t *testing.T) { } func TestLogRecord_MoveTo(t *testing.T) { - ms := LogRecord(internal.GenerateTestLogRecord()) + ms := MutableLogRecord{internal.GenerateTestLogRecord()} dest := NewLogRecord() ms.MoveTo(dest) assert.Equal(t, NewLogRecord(), ms) - assert.Equal(t, LogRecord(internal.GenerateTestLogRecord()), dest) + assert.Equal(t, MutableLogRecord(internal.GenerateTestLogRecord()), dest) } func TestLogRecord_CopyTo(t *testing.T) { @@ -447,7 +447,7 @@ func TestLogRecord_CopyTo(t *testing.T) { orig := NewLogRecord() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = LogRecord(internal.GenerateTestLogRecord()) + orig = MutableLogRecord(internal.GenerateTestLogRecord()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } diff --git a/pdata/plog/plogotlp/generated_logs_otlp.go b/pdata/plog/plogotlp/generated_logs_otlp.go index 14279cc3a6e..a3565a8ede5 100644 --- a/pdata/plog/plogotlp/generated_logs_otlp.go +++ b/pdata/plog/plogotlp/generated_logs_otlp.go @@ -32,25 +32,35 @@ import ( type ExportPartialSuccess internal.LogsExportPartialSuccess +type MutableExportPartialSuccess internal.MutableLogsExportPartialSuccess + func newExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) ExportPartialSuccess { return ExportPartialSuccess(internal.NewLogsExportPartialSuccess(orig)) } +func newMutableExportPartialSuccess(orig *otlpcollectorlog.ExportLogsPartialSuccess) MutableExportPartialSuccess { + return MutableExportPartialSuccess(internal.NewLogsExportPartialSuccess(orig)) +} + func (ms ExportPartialSuccess) getOrig() *otlpcollectorlog.ExportLogsPartialSuccess { return internal.GetOrigLogsExportPartialSuccess(internal.LogsExportPartialSuccess(ms)) } +func (ms MutableExportPartialSuccess) getOrig() *otlpcollectorlog.ExportLogsPartialSuccess { + return internal.GetMutableOrigLogsExportPartialSuccess(internal.MutableLogsExportPartialSuccess(ms)) +} + // NewExportPartialSuccess creates a new empty ExportPartialSuccess. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExportPartialSuccess() ExportPartialSuccess { - return newExportPartialSuccess(&otlpcollectorlog.ExportLogsPartialSuccess{}) +func NewExportPartialSuccess() MutableExportPartialSuccess { + return newMutableExportPartialSuccess(&otlpcollectorlog.ExportLogsPartialSuccess{}) } // 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) { +func (ms MutableExportPartialSuccess) MoveTo(dest MutableExportPartialSuccess) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpcollectorlog.ExportLogsPartialSuccess{} } @@ -60,8 +70,13 @@ func (ms ExportPartialSuccess) RejectedLogRecords() int64 { return ms.getOrig().RejectedLogRecords } +// MutableRejectedLogRecords returns the rejectedlogrecords associated with this ExportPartialSuccess. +func (ms MutableExportPartialSuccess) RejectedLogRecords() int64 { + return ms.getOrig().RejectedLogRecords +} + // SetRejectedLogRecords replaces the rejectedlogrecords associated with this ExportPartialSuccess. -func (ms ExportPartialSuccess) SetRejectedLogRecords(v int64) { +func (ms MutableExportPartialSuccess) SetRejectedLogRecords(v int64) { ms.getOrig().RejectedLogRecords = v } @@ -70,13 +85,23 @@ func (ms ExportPartialSuccess) ErrorMessage() string { return ms.getOrig().ErrorMessage } +// MutableErrorMessage returns the errormessage associated with this ExportPartialSuccess. +func (ms MutableExportPartialSuccess) ErrorMessage() string { + return ms.getOrig().ErrorMessage +} + // SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. -func (ms ExportPartialSuccess) SetErrorMessage(v string) { +func (ms MutableExportPartialSuccess) SetErrorMessage(v string) { ms.getOrig().ErrorMessage = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms ExportPartialSuccess) CopyTo(dest ExportPartialSuccess) { +func (ms ExportPartialSuccess) CopyTo(dest MutableExportPartialSuccess) { dest.SetRejectedLogRecords(ms.RejectedLogRecords()) dest.SetErrorMessage(ms.ErrorMessage()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExportPartialSuccess) CopyTo(dest MutableExportPartialSuccess) { + newExportPartialSuccess(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/plog/plogotlp/generated_logs_otlp_test.go b/pdata/plog/plogotlp/generated_logs_otlp_test.go index 28c9f7c568c..66bdb41277e 100644 --- a/pdata/plog/plogotlp/generated_logs_otlp_test.go +++ b/pdata/plog/plogotlp/generated_logs_otlp_test.go @@ -26,11 +26,11 @@ import ( ) func TestExportPartialSuccess_MoveTo(t *testing.T) { - ms := ExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()) + ms := MutableExportPartialSuccess{internal.GenerateTestLogsExportPartialSuccess()} dest := NewExportPartialSuccess() ms.MoveTo(dest) assert.Equal(t, NewExportPartialSuccess(), ms) - assert.Equal(t, ExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()), dest) + assert.Equal(t, MutableExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()), dest) } func TestExportPartialSuccess_CopyTo(t *testing.T) { @@ -38,7 +38,7 @@ func TestExportPartialSuccess_CopyTo(t *testing.T) { orig := NewExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()) + orig = MutableExportPartialSuccess(internal.GenerateTestLogsExportPartialSuccess()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } diff --git a/pdata/pmetric/generated_metrics.go b/pdata/pmetric/generated_metrics.go index 2f97d3ccde1..d96cb472583 100644 --- a/pdata/pmetric/generated_metrics.go +++ b/pdata/pmetric/generated_metrics.go @@ -35,19 +35,29 @@ import ( // Important: zero-initialized instance is not valid for use. type ResourceMetricsSlice internal.ResourceMetricsSlice +type MutableResourceMetricsSlice internal.MutableResourceMetricsSlice + func newResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) ResourceMetricsSlice { return ResourceMetricsSlice(internal.NewResourceMetricsSlice(orig)) } +func newMutableResourceMetricsSlice(orig *[]*otlpmetrics.ResourceMetrics) MutableResourceMetricsSlice { + return MutableResourceMetricsSlice(internal.NewResourceMetricsSlice(orig)) +} + func (ms ResourceMetricsSlice) getOrig() *[]*otlpmetrics.ResourceMetrics { return internal.GetOrigResourceMetricsSlice(internal.ResourceMetricsSlice(ms)) } +func (ms MutableResourceMetricsSlice) getOrig() *[]*otlpmetrics.ResourceMetrics { + return internal.GetMutableOrigResourceMetricsSlice(internal.MutableResourceMetricsSlice(ms)) +} + // NewResourceMetricsSlice creates a ResourceMetricsSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewResourceMetricsSlice() ResourceMetricsSlice { +func NewResourceMetricsSlice() MutableResourceMetricsSlice { orig := []*otlpmetrics.ResourceMetrics(nil) - return newResourceMetricsSlice(&orig) + return newMutableResourceMetricsSlice(&orig) } // Len returns the number of elements in the slice. @@ -57,6 +67,10 @@ func (es ResourceMetricsSlice) Len() int { return len(*es.getOrig()) } +func (es MutableResourceMetricsSlice) 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: @@ -69,14 +83,18 @@ func (es ResourceMetricsSlice) At(ix int) ResourceMetrics { return newResourceMetrics((*es.getOrig())[ix]) } +func (es MutableResourceMetricsSlice) At(ix int) MutableResourceMetrics { + return newMutableResourceMetrics((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { +func (es ResourceMetricsSlice) CopyTo(dest MutableResourceMetricsSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newResourceMetrics((*es.getOrig())[i]).CopyTo(newResourceMetrics((*dest.getOrig())[i])) + newResourceMetrics((*es.getOrig())[i]).CopyTo(newMutableResourceMetrics((*dest.getOrig())[i])) } return } @@ -84,11 +102,16 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { wrappers := make([]*otlpmetrics.ResourceMetrics, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newResourceMetrics((*es.getOrig())[i]).CopyTo(newResourceMetrics(wrappers[i])) + newResourceMetrics((*es.getOrig())[i]).CopyTo(newMutableResourceMetrics(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableResourceMetricsSlice) CopyTo(dest MutableResourceMetricsSlice) { + newResourceMetricsSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -101,7 +124,7 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ResourceMetricsSlice) EnsureCapacity(newCap int) { +func (es MutableResourceMetricsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -114,7 +137,7 @@ func (es ResourceMetricsSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ResourceMetrics. // It returns the newly added ResourceMetrics. -func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { +func (es MutableResourceMetricsSlice) AppendEmpty() MutableResourceMetrics { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.ResourceMetrics{}) return es.At(es.Len() - 1) } @@ -122,13 +145,13 @@ func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { // Sort sorts the ResourceMetrics elements within ResourceMetricsSlice given the // provided less function so that two instances of ResourceMetricsSlice // can be compared. -func (es ResourceMetricsSlice) Sort(less func(a, b ResourceMetrics) bool) { +func (es MutableResourceMetricsSlice) Sort(less func(a, b MutableResourceMetrics) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableResourceMetricsSlice) MoveAndAppendTo(dest MutableResourceMetricsSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -140,7 +163,7 @@ func (es ResourceMetricsSlice) MoveAndAppendTo(dest ResourceMetricsSlice) { // 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) { +func (es MutableResourceMetricsSlice) RemoveIf(f func(MutableResourceMetrics) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -168,25 +191,35 @@ func (es ResourceMetricsSlice) RemoveIf(f func(ResourceMetrics) bool) { type ResourceMetrics internal.ResourceMetrics +type MutableResourceMetrics internal.MutableResourceMetrics + func newResourceMetrics(orig *otlpmetrics.ResourceMetrics) ResourceMetrics { return ResourceMetrics(internal.NewResourceMetrics(orig)) } +func newMutableResourceMetrics(orig *otlpmetrics.ResourceMetrics) MutableResourceMetrics { + return MutableResourceMetrics(internal.NewResourceMetrics(orig)) +} + func (ms ResourceMetrics) getOrig() *otlpmetrics.ResourceMetrics { return internal.GetOrigResourceMetrics(internal.ResourceMetrics(ms)) } +func (ms MutableResourceMetrics) getOrig() *otlpmetrics.ResourceMetrics { + return internal.GetMutableOrigResourceMetrics(internal.MutableResourceMetrics(ms)) +} + // NewResourceMetrics creates a new empty ResourceMetrics. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewResourceMetrics() ResourceMetrics { - return newResourceMetrics(&otlpmetrics.ResourceMetrics{}) +func NewResourceMetrics() MutableResourceMetrics { + return newMutableResourceMetrics(&otlpmetrics.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) { +func (ms MutableResourceMetrics) MoveTo(dest MutableResourceMetrics) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.ResourceMetrics{} } @@ -196,13 +229,23 @@ func (ms ResourceMetrics) Resource() pcommon.Resource { return pcommon.Resource(internal.NewResource(&ms.getOrig().Resource)) } +// Resource returns the resource associated with this ResourceMetrics. +func (ms MutableResourceMetrics) Resource() pcommon.MutableResource { + return pcommon.MutableResource(internal.NewMutableResource(&ms.getOrig().Resource)) +} + // SchemaUrl returns the schemaurl associated with this ResourceMetrics. func (ms ResourceMetrics) SchemaUrl() string { return ms.getOrig().SchemaUrl } +// MutableSchemaUrl returns the schemaurl associated with this ResourceMetrics. +func (ms MutableResourceMetrics) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + // SetSchemaUrl replaces the schemaurl associated with this ResourceMetrics. -func (ms ResourceMetrics) SetSchemaUrl(v string) { +func (ms MutableResourceMetrics) SetSchemaUrl(v string) { ms.getOrig().SchemaUrl = v } @@ -211,13 +254,23 @@ func (ms ResourceMetrics) ScopeMetrics() ScopeMetricsSlice { return ScopeMetricsSlice(internal.NewScopeMetricsSlice(&ms.getOrig().ScopeMetrics)) } +// ScopeMetrics returns the ScopeMetrics associated with this ResourceMetrics. +func (ms MutableResourceMetrics) ScopeMetrics() MutableScopeMetricsSlice { + return MutableScopeMetricsSlice(internal.NewMutableScopeMetricsSlice(&ms.getOrig().ScopeMetrics)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ResourceMetrics) CopyTo(dest ResourceMetrics) { +func (ms ResourceMetrics) CopyTo(dest MutableResourceMetrics) { ms.Resource().CopyTo(dest.Resource()) dest.SetSchemaUrl(ms.SchemaUrl()) ms.ScopeMetrics().CopyTo(dest.ScopeMetrics()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableResourceMetrics) CopyTo(dest MutableResourceMetrics) { + newResourceMetrics(ms.getOrig()).CopyTo(dest) +} + // ScopeMetricsSlice logically represents a slice of ScopeMetrics. // // This is a reference type. If passed by value and callee modifies it, the @@ -227,19 +280,29 @@ func (ms ResourceMetrics) CopyTo(dest ResourceMetrics) { // Important: zero-initialized instance is not valid for use. type ScopeMetricsSlice internal.ScopeMetricsSlice +type MutableScopeMetricsSlice internal.MutableScopeMetricsSlice + func newScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) ScopeMetricsSlice { return ScopeMetricsSlice(internal.NewScopeMetricsSlice(orig)) } +func newMutableScopeMetricsSlice(orig *[]*otlpmetrics.ScopeMetrics) MutableScopeMetricsSlice { + return MutableScopeMetricsSlice(internal.NewScopeMetricsSlice(orig)) +} + func (ms ScopeMetricsSlice) getOrig() *[]*otlpmetrics.ScopeMetrics { return internal.GetOrigScopeMetricsSlice(internal.ScopeMetricsSlice(ms)) } +func (ms MutableScopeMetricsSlice) getOrig() *[]*otlpmetrics.ScopeMetrics { + return internal.GetMutableOrigScopeMetricsSlice(internal.MutableScopeMetricsSlice(ms)) +} + // NewScopeMetricsSlice creates a ScopeMetricsSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewScopeMetricsSlice() ScopeMetricsSlice { +func NewScopeMetricsSlice() MutableScopeMetricsSlice { orig := []*otlpmetrics.ScopeMetrics(nil) - return newScopeMetricsSlice(&orig) + return newMutableScopeMetricsSlice(&orig) } // Len returns the number of elements in the slice. @@ -249,6 +312,10 @@ func (es ScopeMetricsSlice) Len() int { return len(*es.getOrig()) } +func (es MutableScopeMetricsSlice) 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: @@ -261,14 +328,18 @@ func (es ScopeMetricsSlice) At(ix int) ScopeMetrics { return newScopeMetrics((*es.getOrig())[ix]) } +func (es MutableScopeMetricsSlice) At(ix int) MutableScopeMetrics { + return newMutableScopeMetrics((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { +func (es ScopeMetricsSlice) CopyTo(dest MutableScopeMetricsSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newScopeMetrics((*es.getOrig())[i]).CopyTo(newScopeMetrics((*dest.getOrig())[i])) + newScopeMetrics((*es.getOrig())[i]).CopyTo(newMutableScopeMetrics((*dest.getOrig())[i])) } return } @@ -276,11 +347,16 @@ func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { wrappers := make([]*otlpmetrics.ScopeMetrics, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newScopeMetrics((*es.getOrig())[i]).CopyTo(newScopeMetrics(wrappers[i])) + newScopeMetrics((*es.getOrig())[i]).CopyTo(newMutableScopeMetrics(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableScopeMetricsSlice) CopyTo(dest MutableScopeMetricsSlice) { + newScopeMetricsSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -293,7 +369,7 @@ func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ScopeMetricsSlice) EnsureCapacity(newCap int) { +func (es MutableScopeMetricsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -306,7 +382,7 @@ func (es ScopeMetricsSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ScopeMetrics. // It returns the newly added ScopeMetrics. -func (es ScopeMetricsSlice) AppendEmpty() ScopeMetrics { +func (es MutableScopeMetricsSlice) AppendEmpty() MutableScopeMetrics { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.ScopeMetrics{}) return es.At(es.Len() - 1) } @@ -314,13 +390,13 @@ func (es ScopeMetricsSlice) AppendEmpty() ScopeMetrics { // Sort sorts the ScopeMetrics elements within ScopeMetricsSlice given the // provided less function so that two instances of ScopeMetricsSlice // can be compared. -func (es ScopeMetricsSlice) Sort(less func(a, b ScopeMetrics) bool) { +func (es MutableScopeMetricsSlice) Sort(less func(a, b MutableScopeMetrics) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableScopeMetricsSlice) MoveAndAppendTo(dest MutableScopeMetricsSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -332,7 +408,7 @@ func (es ScopeMetricsSlice) MoveAndAppendTo(dest ScopeMetricsSlice) { // 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) { +func (es MutableScopeMetricsSlice) RemoveIf(f func(MutableScopeMetrics) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -360,25 +436,35 @@ func (es ScopeMetricsSlice) RemoveIf(f func(ScopeMetrics) bool) { type ScopeMetrics internal.ScopeMetrics +type MutableScopeMetrics internal.MutableScopeMetrics + func newScopeMetrics(orig *otlpmetrics.ScopeMetrics) ScopeMetrics { return ScopeMetrics(internal.NewScopeMetrics(orig)) } +func newMutableScopeMetrics(orig *otlpmetrics.ScopeMetrics) MutableScopeMetrics { + return MutableScopeMetrics(internal.NewScopeMetrics(orig)) +} + func (ms ScopeMetrics) getOrig() *otlpmetrics.ScopeMetrics { return internal.GetOrigScopeMetrics(internal.ScopeMetrics(ms)) } +func (ms MutableScopeMetrics) getOrig() *otlpmetrics.ScopeMetrics { + return internal.GetMutableOrigScopeMetrics(internal.MutableScopeMetrics(ms)) +} + // NewScopeMetrics creates a new empty ScopeMetrics. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewScopeMetrics() ScopeMetrics { - return newScopeMetrics(&otlpmetrics.ScopeMetrics{}) +func NewScopeMetrics() MutableScopeMetrics { + return newMutableScopeMetrics(&otlpmetrics.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) { +func (ms MutableScopeMetrics) MoveTo(dest MutableScopeMetrics) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.ScopeMetrics{} } @@ -388,13 +474,23 @@ func (ms ScopeMetrics) Scope() pcommon.InstrumentationScope { return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.getOrig().Scope)) } +// Scope returns the scope associated with this ScopeMetrics. +func (ms MutableScopeMetrics) Scope() pcommon.MutableInstrumentationScope { + return pcommon.MutableInstrumentationScope(internal.NewMutableInstrumentationScope(&ms.getOrig().Scope)) +} + // SchemaUrl returns the schemaurl associated with this ScopeMetrics. func (ms ScopeMetrics) SchemaUrl() string { return ms.getOrig().SchemaUrl } +// MutableSchemaUrl returns the schemaurl associated with this ScopeMetrics. +func (ms MutableScopeMetrics) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + // SetSchemaUrl replaces the schemaurl associated with this ScopeMetrics. -func (ms ScopeMetrics) SetSchemaUrl(v string) { +func (ms MutableScopeMetrics) SetSchemaUrl(v string) { ms.getOrig().SchemaUrl = v } @@ -403,13 +499,23 @@ func (ms ScopeMetrics) Metrics() MetricSlice { return MetricSlice(internal.NewMetricSlice(&ms.getOrig().Metrics)) } +// Metrics returns the Metrics associated with this ScopeMetrics. +func (ms MutableScopeMetrics) Metrics() MutableMetricSlice { + return MutableMetricSlice(internal.NewMutableMetricSlice(&ms.getOrig().Metrics)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ScopeMetrics) CopyTo(dest ScopeMetrics) { +func (ms ScopeMetrics) CopyTo(dest MutableScopeMetrics) { ms.Scope().CopyTo(dest.Scope()) dest.SetSchemaUrl(ms.SchemaUrl()) ms.Metrics().CopyTo(dest.Metrics()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableScopeMetrics) CopyTo(dest MutableScopeMetrics) { + newScopeMetrics(ms.getOrig()).CopyTo(dest) +} + // MetricSlice logically represents a slice of Metric. // // This is a reference type. If passed by value and callee modifies it, the @@ -419,19 +525,29 @@ func (ms ScopeMetrics) CopyTo(dest ScopeMetrics) { // Important: zero-initialized instance is not valid for use. type MetricSlice internal.MetricSlice +type MutableMetricSlice internal.MutableMetricSlice + func newMetricSlice(orig *[]*otlpmetrics.Metric) MetricSlice { return MetricSlice(internal.NewMetricSlice(orig)) } +func newMutableMetricSlice(orig *[]*otlpmetrics.Metric) MutableMetricSlice { + return MutableMetricSlice(internal.NewMetricSlice(orig)) +} + func (ms MetricSlice) getOrig() *[]*otlpmetrics.Metric { return internal.GetOrigMetricSlice(internal.MetricSlice(ms)) } +func (ms MutableMetricSlice) getOrig() *[]*otlpmetrics.Metric { + return internal.GetMutableOrigMetricSlice(internal.MutableMetricSlice(ms)) +} + // NewMetricSlice creates a MetricSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewMetricSlice() MetricSlice { +func NewMetricSlice() MutableMetricSlice { orig := []*otlpmetrics.Metric(nil) - return newMetricSlice(&orig) + return newMutableMetricSlice(&orig) } // Len returns the number of elements in the slice. @@ -441,6 +557,10 @@ func (es MetricSlice) Len() int { return len(*es.getOrig()) } +func (es MutableMetricSlice) 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: @@ -453,14 +573,18 @@ func (es MetricSlice) At(ix int) Metric { return newMetric((*es.getOrig())[ix]) } +func (es MutableMetricSlice) At(ix int) MutableMetric { + return newMutableMetric((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es MetricSlice) CopyTo(dest MetricSlice) { +func (es MetricSlice) CopyTo(dest MutableMetricSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newMetric((*es.getOrig())[i]).CopyTo(newMetric((*dest.getOrig())[i])) + newMetric((*es.getOrig())[i]).CopyTo(newMutableMetric((*dest.getOrig())[i])) } return } @@ -468,11 +592,16 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { wrappers := make([]*otlpmetrics.Metric, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newMetric((*es.getOrig())[i]).CopyTo(newMetric(wrappers[i])) + newMetric((*es.getOrig())[i]).CopyTo(newMutableMetric(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableMetricSlice) CopyTo(dest MutableMetricSlice) { + newMetricSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -485,7 +614,7 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es MetricSlice) EnsureCapacity(newCap int) { +func (es MutableMetricSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -498,7 +627,7 @@ func (es MetricSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty Metric. // It returns the newly added Metric. -func (es MetricSlice) AppendEmpty() Metric { +func (es MutableMetricSlice) AppendEmpty() MutableMetric { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.Metric{}) return es.At(es.Len() - 1) } @@ -506,13 +635,13 @@ func (es MetricSlice) AppendEmpty() Metric { // Sort sorts the Metric elements within MetricSlice given the // provided less function so that two instances of MetricSlice // can be compared. -func (es MetricSlice) Sort(less func(a, b Metric) bool) { +func (es MutableMetricSlice) Sort(less func(a, b MutableMetric) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableMetricSlice) MoveAndAppendTo(dest MutableMetricSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -524,7 +653,7 @@ func (es MetricSlice) MoveAndAppendTo(dest MetricSlice) { // 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) { +func (es MutableMetricSlice) RemoveIf(f func(MutableMetric) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -553,25 +682,35 @@ func (es MetricSlice) RemoveIf(f func(Metric) bool) { type Metric internal.Metric +type MutableMetric internal.MutableMetric + func newMetric(orig *otlpmetrics.Metric) Metric { return Metric(internal.NewMetric(orig)) } +func newMutableMetric(orig *otlpmetrics.Metric) MutableMetric { + return MutableMetric(internal.NewMetric(orig)) +} + func (ms Metric) getOrig() *otlpmetrics.Metric { return internal.GetOrigMetric(internal.Metric(ms)) } +func (ms MutableMetric) getOrig() *otlpmetrics.Metric { + return internal.GetMutableOrigMetric(internal.MutableMetric(ms)) +} + // NewMetric creates a new empty Metric. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewMetric() Metric { - return newMetric(&otlpmetrics.Metric{}) +func NewMetric() MutableMetric { + return newMutableMetric(&otlpmetrics.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) { +func (ms MutableMetric) MoveTo(dest MutableMetric) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.Metric{} } @@ -581,8 +720,13 @@ func (ms Metric) Name() string { return ms.getOrig().Name } +// MutableName returns the name associated with this Metric. +func (ms MutableMetric) Name() string { + return ms.getOrig().Name +} + // SetName replaces the name associated with this Metric. -func (ms Metric) SetName(v string) { +func (ms MutableMetric) SetName(v string) { ms.getOrig().Name = v } @@ -591,8 +735,13 @@ func (ms Metric) Description() string { return ms.getOrig().Description } +// MutableDescription returns the description associated with this Metric. +func (ms MutableMetric) Description() string { + return ms.getOrig().Description +} + // SetDescription replaces the description associated with this Metric. -func (ms Metric) SetDescription(v string) { +func (ms MutableMetric) SetDescription(v string) { ms.getOrig().Description = v } @@ -601,8 +750,13 @@ func (ms Metric) Unit() string { return ms.getOrig().Unit } +// MutableUnit returns the unit associated with this Metric. +func (ms MutableMetric) Unit() string { + return ms.getOrig().Unit +} + // SetUnit replaces the unit associated with this Metric. -func (ms Metric) SetUnit(v string) { +func (ms MutableMetric) SetUnit(v string) { ms.getOrig().Unit = v } @@ -642,11 +796,11 @@ func (ms Metric) Gauge() Gauge { // // After this, Type() function will return MetricTypeGauge". // -// Calling this function on zero-initialized Metric will cause a panic. -func (ms Metric) SetEmptyGauge() Gauge { +// Calling this function on zero-initialized MutableMetric will cause a panic. +func (ms MutableMetric) SetEmptyGauge() MutableGauge { val := &otlpmetrics.Gauge{} ms.getOrig().Data = &otlpmetrics.Metric_Gauge{Gauge: val} - return newGauge(val) + return newMutableGauge(val) } // Sum returns the sum associated with this Metric. @@ -667,11 +821,11 @@ func (ms Metric) Sum() Sum { // // After this, Type() function will return MetricTypeSum". // -// Calling this function on zero-initialized Metric will cause a panic. -func (ms Metric) SetEmptySum() Sum { +// Calling this function on zero-initialized MutableMetric will cause a panic. +func (ms MutableMetric) SetEmptySum() MutableSum { val := &otlpmetrics.Sum{} ms.getOrig().Data = &otlpmetrics.Metric_Sum{Sum: val} - return newSum(val) + return newMutableSum(val) } // Histogram returns the histogram associated with this Metric. @@ -692,11 +846,11 @@ func (ms Metric) Histogram() Histogram { // // After this, Type() function will return MetricTypeHistogram". // -// Calling this function on zero-initialized Metric will cause a panic. -func (ms Metric) SetEmptyHistogram() Histogram { +// Calling this function on zero-initialized MutableMetric will cause a panic. +func (ms MutableMetric) SetEmptyHistogram() MutableHistogram { val := &otlpmetrics.Histogram{} ms.getOrig().Data = &otlpmetrics.Metric_Histogram{Histogram: val} - return newHistogram(val) + return newMutableHistogram(val) } // ExponentialHistogram returns the exponentialhistogram associated with this Metric. @@ -717,11 +871,11 @@ func (ms Metric) ExponentialHistogram() ExponentialHistogram { // // After this, Type() function will return MetricTypeExponentialHistogram". // -// Calling this function on zero-initialized Metric will cause a panic. -func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram { +// Calling this function on zero-initialized MutableMetric will cause a panic. +func (ms MutableMetric) SetEmptyExponentialHistogram() MutableExponentialHistogram { val := &otlpmetrics.ExponentialHistogram{} ms.getOrig().Data = &otlpmetrics.Metric_ExponentialHistogram{ExponentialHistogram: val} - return newExponentialHistogram(val) + return newMutableExponentialHistogram(val) } // Summary returns the summary associated with this Metric. @@ -742,15 +896,15 @@ func (ms Metric) Summary() Summary { // // After this, Type() function will return MetricTypeSummary". // -// Calling this function on zero-initialized Metric will cause a panic. -func (ms Metric) SetEmptySummary() Summary { +// Calling this function on zero-initialized MutableMetric will cause a panic. +func (ms MutableMetric) SetEmptySummary() MutableSummary { val := &otlpmetrics.Summary{} ms.getOrig().Data = &otlpmetrics.Metric_Summary{Summary: val} - return newSummary(val) + return newMutableSummary(val) } // CopyTo copies all properties from the current struct overriding the destination. -func (ms Metric) CopyTo(dest Metric) { +func (ms Metric) CopyTo(dest MutableMetric) { dest.SetName(ms.Name()) dest.SetDescription(ms.Description()) dest.SetUnit(ms.Unit()) @@ -769,6 +923,11 @@ func (ms Metric) CopyTo(dest Metric) { } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableMetric) CopyTo(dest MutableMetric) { + newMetric(ms.getOrig()).CopyTo(dest) +} + // Gauge represents the type of a numeric metric that always exports the "current value" for every data point. // // This is a reference type, if passed by value and callee modifies it the @@ -779,25 +938,35 @@ func (ms Metric) CopyTo(dest Metric) { type Gauge internal.Gauge +type MutableGauge internal.MutableGauge + func newGauge(orig *otlpmetrics.Gauge) Gauge { return Gauge(internal.NewGauge(orig)) } +func newMutableGauge(orig *otlpmetrics.Gauge) MutableGauge { + return MutableGauge(internal.NewGauge(orig)) +} + func (ms Gauge) getOrig() *otlpmetrics.Gauge { return internal.GetOrigGauge(internal.Gauge(ms)) } +func (ms MutableGauge) getOrig() *otlpmetrics.Gauge { + return internal.GetMutableOrigGauge(internal.MutableGauge(ms)) +} + // NewGauge creates a new empty Gauge. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewGauge() Gauge { - return newGauge(&otlpmetrics.Gauge{}) +func NewGauge() MutableGauge { + return newMutableGauge(&otlpmetrics.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) { +func (ms MutableGauge) MoveTo(dest MutableGauge) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.Gauge{} } @@ -807,11 +976,21 @@ func (ms Gauge) DataPoints() NumberDataPointSlice { return NumberDataPointSlice(internal.NewNumberDataPointSlice(&ms.getOrig().DataPoints)) } +// DataPoints returns the DataPoints associated with this Gauge. +func (ms MutableGauge) DataPoints() MutableNumberDataPointSlice { + return MutableNumberDataPointSlice(internal.NewMutableNumberDataPointSlice(&ms.getOrig().DataPoints)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms Gauge) CopyTo(dest Gauge) { +func (ms Gauge) CopyTo(dest MutableGauge) { ms.DataPoints().CopyTo(dest.DataPoints()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableGauge) CopyTo(dest MutableGauge) { + newGauge(ms.getOrig()).CopyTo(dest) +} + // Sum represents the type of a numeric metric that is calculated as a sum of all reported measurements over a time interval. // // This is a reference type, if passed by value and callee modifies it the @@ -822,25 +1001,35 @@ func (ms Gauge) CopyTo(dest Gauge) { type Sum internal.Sum +type MutableSum internal.MutableSum + func newSum(orig *otlpmetrics.Sum) Sum { return Sum(internal.NewSum(orig)) } +func newMutableSum(orig *otlpmetrics.Sum) MutableSum { + return MutableSum(internal.NewSum(orig)) +} + func (ms Sum) getOrig() *otlpmetrics.Sum { return internal.GetOrigSum(internal.Sum(ms)) } +func (ms MutableSum) getOrig() *otlpmetrics.Sum { + return internal.GetMutableOrigSum(internal.MutableSum(ms)) +} + // NewSum creates a new empty Sum. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSum() Sum { - return newSum(&otlpmetrics.Sum{}) +func NewSum() MutableSum { + return newMutableSum(&otlpmetrics.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) { +func (ms MutableSum) MoveTo(dest MutableSum) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.Sum{} } @@ -850,8 +1039,13 @@ func (ms Sum) AggregationTemporality() AggregationTemporality { return AggregationTemporality(ms.getOrig().AggregationTemporality) } +// AggregationTemporality returns the aggregationtemporality associated with this Sum. +func (ms MutableSum) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.getOrig().AggregationTemporality) +} + // SetAggregationTemporality replaces the aggregationtemporality associated with this Sum. -func (ms Sum) SetAggregationTemporality(v AggregationTemporality) { +func (ms MutableSum) SetAggregationTemporality(v AggregationTemporality) { ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) } @@ -860,8 +1054,13 @@ func (ms Sum) IsMonotonic() bool { return ms.getOrig().IsMonotonic } +// MutableIsMonotonic returns the ismonotonic associated with this Sum. +func (ms MutableSum) IsMonotonic() bool { + return ms.getOrig().IsMonotonic +} + // SetIsMonotonic replaces the ismonotonic associated with this Sum. -func (ms Sum) SetIsMonotonic(v bool) { +func (ms MutableSum) SetIsMonotonic(v bool) { ms.getOrig().IsMonotonic = v } @@ -870,13 +1069,23 @@ func (ms Sum) DataPoints() NumberDataPointSlice { return NumberDataPointSlice(internal.NewNumberDataPointSlice(&ms.getOrig().DataPoints)) } +// DataPoints returns the DataPoints associated with this Sum. +func (ms MutableSum) DataPoints() MutableNumberDataPointSlice { + return MutableNumberDataPointSlice(internal.NewMutableNumberDataPointSlice(&ms.getOrig().DataPoints)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms Sum) CopyTo(dest Sum) { +func (ms Sum) CopyTo(dest MutableSum) { dest.SetAggregationTemporality(ms.AggregationTemporality()) dest.SetIsMonotonic(ms.IsMonotonic()) ms.DataPoints().CopyTo(dest.DataPoints()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSum) CopyTo(dest MutableSum) { + newSum(ms.getOrig()).CopyTo(dest) +} + // Histogram represents the type of a metric that is calculated by aggregating as a Histogram of all reported measurements over a time interval. // // This is a reference type, if passed by value and callee modifies it the @@ -887,25 +1096,35 @@ func (ms Sum) CopyTo(dest Sum) { type Histogram internal.Histogram +type MutableHistogram internal.MutableHistogram + func newHistogram(orig *otlpmetrics.Histogram) Histogram { return Histogram(internal.NewHistogram(orig)) } +func newMutableHistogram(orig *otlpmetrics.Histogram) MutableHistogram { + return MutableHistogram(internal.NewHistogram(orig)) +} + func (ms Histogram) getOrig() *otlpmetrics.Histogram { return internal.GetOrigHistogram(internal.Histogram(ms)) } +func (ms MutableHistogram) getOrig() *otlpmetrics.Histogram { + return internal.GetMutableOrigHistogram(internal.MutableHistogram(ms)) +} + // NewHistogram creates a new empty Histogram. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewHistogram() Histogram { - return newHistogram(&otlpmetrics.Histogram{}) +func NewHistogram() MutableHistogram { + return newMutableHistogram(&otlpmetrics.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) { +func (ms MutableHistogram) MoveTo(dest MutableHistogram) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.Histogram{} } @@ -915,8 +1134,13 @@ func (ms Histogram) AggregationTemporality() AggregationTemporality { return AggregationTemporality(ms.getOrig().AggregationTemporality) } +// AggregationTemporality returns the aggregationtemporality associated with this Histogram. +func (ms MutableHistogram) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.getOrig().AggregationTemporality) +} + // SetAggregationTemporality replaces the aggregationtemporality associated with this Histogram. -func (ms Histogram) SetAggregationTemporality(v AggregationTemporality) { +func (ms MutableHistogram) SetAggregationTemporality(v AggregationTemporality) { ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) } @@ -925,12 +1149,22 @@ func (ms Histogram) DataPoints() HistogramDataPointSlice { return HistogramDataPointSlice(internal.NewHistogramDataPointSlice(&ms.getOrig().DataPoints)) } +// DataPoints returns the DataPoints associated with this Histogram. +func (ms MutableHistogram) DataPoints() MutableHistogramDataPointSlice { + return MutableHistogramDataPointSlice(internal.NewMutableHistogramDataPointSlice(&ms.getOrig().DataPoints)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms Histogram) CopyTo(dest Histogram) { +func (ms Histogram) CopyTo(dest MutableHistogram) { dest.SetAggregationTemporality(ms.AggregationTemporality()) ms.DataPoints().CopyTo(dest.DataPoints()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableHistogram) CopyTo(dest MutableHistogram) { + newHistogram(ms.getOrig()).CopyTo(dest) +} + // ExponentialHistogram represents the type of a metric that is calculated by aggregating // as a ExponentialHistogram of all reported double measurements over a time interval. // @@ -942,25 +1176,35 @@ func (ms Histogram) CopyTo(dest Histogram) { type ExponentialHistogram internal.ExponentialHistogram +type MutableExponentialHistogram internal.MutableExponentialHistogram + func newExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) ExponentialHistogram { return ExponentialHistogram(internal.NewExponentialHistogram(orig)) } +func newMutableExponentialHistogram(orig *otlpmetrics.ExponentialHistogram) MutableExponentialHistogram { + return MutableExponentialHistogram(internal.NewExponentialHistogram(orig)) +} + func (ms ExponentialHistogram) getOrig() *otlpmetrics.ExponentialHistogram { return internal.GetOrigExponentialHistogram(internal.ExponentialHistogram(ms)) } +func (ms MutableExponentialHistogram) getOrig() *otlpmetrics.ExponentialHistogram { + return internal.GetMutableOrigExponentialHistogram(internal.MutableExponentialHistogram(ms)) +} + // NewExponentialHistogram creates a new empty ExponentialHistogram. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExponentialHistogram() ExponentialHistogram { - return newExponentialHistogram(&otlpmetrics.ExponentialHistogram{}) +func NewExponentialHistogram() MutableExponentialHistogram { + return newMutableExponentialHistogram(&otlpmetrics.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) { +func (ms MutableExponentialHistogram) MoveTo(dest MutableExponentialHistogram) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.ExponentialHistogram{} } @@ -970,8 +1214,13 @@ func (ms ExponentialHistogram) AggregationTemporality() AggregationTemporality { return AggregationTemporality(ms.getOrig().AggregationTemporality) } +// AggregationTemporality returns the aggregationtemporality associated with this ExponentialHistogram. +func (ms MutableExponentialHistogram) AggregationTemporality() AggregationTemporality { + return AggregationTemporality(ms.getOrig().AggregationTemporality) +} + // SetAggregationTemporality replaces the aggregationtemporality associated with this ExponentialHistogram. -func (ms ExponentialHistogram) SetAggregationTemporality(v AggregationTemporality) { +func (ms MutableExponentialHistogram) SetAggregationTemporality(v AggregationTemporality) { ms.getOrig().AggregationTemporality = otlpmetrics.AggregationTemporality(v) } @@ -980,12 +1229,22 @@ func (ms ExponentialHistogram) DataPoints() ExponentialHistogramDataPointSlice { return ExponentialHistogramDataPointSlice(internal.NewExponentialHistogramDataPointSlice(&ms.getOrig().DataPoints)) } +// DataPoints returns the DataPoints associated with this ExponentialHistogram. +func (ms MutableExponentialHistogram) DataPoints() MutableExponentialHistogramDataPointSlice { + return MutableExponentialHistogramDataPointSlice(internal.NewMutableExponentialHistogramDataPointSlice(&ms.getOrig().DataPoints)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ExponentialHistogram) CopyTo(dest ExponentialHistogram) { +func (ms ExponentialHistogram) CopyTo(dest MutableExponentialHistogram) { dest.SetAggregationTemporality(ms.AggregationTemporality()) ms.DataPoints().CopyTo(dest.DataPoints()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExponentialHistogram) CopyTo(dest MutableExponentialHistogram) { + newExponentialHistogram(ms.getOrig()).CopyTo(dest) +} + // Summary represents the type of a metric that is calculated by aggregating as a Summary of all reported double measurements over a time interval. // // This is a reference type, if passed by value and callee modifies it the @@ -996,25 +1255,35 @@ func (ms ExponentialHistogram) CopyTo(dest ExponentialHistogram) { type Summary internal.Summary +type MutableSummary internal.MutableSummary + func newSummary(orig *otlpmetrics.Summary) Summary { return Summary(internal.NewSummary(orig)) } +func newMutableSummary(orig *otlpmetrics.Summary) MutableSummary { + return MutableSummary(internal.NewSummary(orig)) +} + func (ms Summary) getOrig() *otlpmetrics.Summary { return internal.GetOrigSummary(internal.Summary(ms)) } +func (ms MutableSummary) getOrig() *otlpmetrics.Summary { + return internal.GetMutableOrigSummary(internal.MutableSummary(ms)) +} + // NewSummary creates a new empty Summary. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSummary() Summary { - return newSummary(&otlpmetrics.Summary{}) +func NewSummary() MutableSummary { + return newMutableSummary(&otlpmetrics.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) { +func (ms MutableSummary) MoveTo(dest MutableSummary) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.Summary{} } @@ -1024,11 +1293,21 @@ func (ms Summary) DataPoints() SummaryDataPointSlice { return SummaryDataPointSlice(internal.NewSummaryDataPointSlice(&ms.getOrig().DataPoints)) } +// DataPoints returns the DataPoints associated with this Summary. +func (ms MutableSummary) DataPoints() MutableSummaryDataPointSlice { + return MutableSummaryDataPointSlice(internal.NewMutableSummaryDataPointSlice(&ms.getOrig().DataPoints)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms Summary) CopyTo(dest Summary) { +func (ms Summary) CopyTo(dest MutableSummary) { ms.DataPoints().CopyTo(dest.DataPoints()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSummary) CopyTo(dest MutableSummary) { + newSummary(ms.getOrig()).CopyTo(dest) +} + // NumberDataPointSlice logically represents a slice of NumberDataPoint. // // This is a reference type. If passed by value and callee modifies it, the @@ -1038,19 +1317,29 @@ func (ms Summary) CopyTo(dest Summary) { // Important: zero-initialized instance is not valid for use. type NumberDataPointSlice internal.NumberDataPointSlice +type MutableNumberDataPointSlice internal.MutableNumberDataPointSlice + func newNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) NumberDataPointSlice { return NumberDataPointSlice(internal.NewNumberDataPointSlice(orig)) } +func newMutableNumberDataPointSlice(orig *[]*otlpmetrics.NumberDataPoint) MutableNumberDataPointSlice { + return MutableNumberDataPointSlice(internal.NewNumberDataPointSlice(orig)) +} + func (ms NumberDataPointSlice) getOrig() *[]*otlpmetrics.NumberDataPoint { return internal.GetOrigNumberDataPointSlice(internal.NumberDataPointSlice(ms)) } +func (ms MutableNumberDataPointSlice) getOrig() *[]*otlpmetrics.NumberDataPoint { + return internal.GetMutableOrigNumberDataPointSlice(internal.MutableNumberDataPointSlice(ms)) +} + // NewNumberDataPointSlice creates a NumberDataPointSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewNumberDataPointSlice() NumberDataPointSlice { +func NewNumberDataPointSlice() MutableNumberDataPointSlice { orig := []*otlpmetrics.NumberDataPoint(nil) - return newNumberDataPointSlice(&orig) + return newMutableNumberDataPointSlice(&orig) } // Len returns the number of elements in the slice. @@ -1060,6 +1349,10 @@ func (es NumberDataPointSlice) Len() int { return len(*es.getOrig()) } +func (es MutableNumberDataPointSlice) 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: @@ -1072,14 +1365,18 @@ func (es NumberDataPointSlice) At(ix int) NumberDataPoint { return newNumberDataPoint((*es.getOrig())[ix]) } +func (es MutableNumberDataPointSlice) At(ix int) MutableNumberDataPoint { + return newMutableNumberDataPoint((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { +func (es NumberDataPointSlice) CopyTo(dest MutableNumberDataPointSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newNumberDataPoint((*es.getOrig())[i]).CopyTo(newNumberDataPoint((*dest.getOrig())[i])) + newNumberDataPoint((*es.getOrig())[i]).CopyTo(newMutableNumberDataPoint((*dest.getOrig())[i])) } return } @@ -1087,11 +1384,16 @@ func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { wrappers := make([]*otlpmetrics.NumberDataPoint, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newNumberDataPoint((*es.getOrig())[i]).CopyTo(newNumberDataPoint(wrappers[i])) + newNumberDataPoint((*es.getOrig())[i]).CopyTo(newMutableNumberDataPoint(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableNumberDataPointSlice) CopyTo(dest MutableNumberDataPointSlice) { + newNumberDataPointSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -1104,7 +1406,7 @@ func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es NumberDataPointSlice) EnsureCapacity(newCap int) { +func (es MutableNumberDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -1117,7 +1419,7 @@ func (es NumberDataPointSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty NumberDataPoint. // It returns the newly added NumberDataPoint. -func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { +func (es MutableNumberDataPointSlice) AppendEmpty() MutableNumberDataPoint { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.NumberDataPoint{}) return es.At(es.Len() - 1) } @@ -1125,13 +1427,13 @@ func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { // Sort sorts the NumberDataPoint elements within NumberDataPointSlice given the // provided less function so that two instances of NumberDataPointSlice // can be compared. -func (es NumberDataPointSlice) Sort(less func(a, b NumberDataPoint) bool) { +func (es MutableNumberDataPointSlice) Sort(less func(a, b MutableNumberDataPoint) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableNumberDataPointSlice) MoveAndAppendTo(dest MutableNumberDataPointSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -1143,7 +1445,7 @@ func (es NumberDataPointSlice) MoveAndAppendTo(dest NumberDataPointSlice) { // 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) { +func (es MutableNumberDataPointSlice) RemoveIf(f func(MutableNumberDataPoint) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -1171,25 +1473,35 @@ func (es NumberDataPointSlice) RemoveIf(f func(NumberDataPoint) bool) { type NumberDataPoint internal.NumberDataPoint +type MutableNumberDataPoint internal.MutableNumberDataPoint + func newNumberDataPoint(orig *otlpmetrics.NumberDataPoint) NumberDataPoint { return NumberDataPoint(internal.NewNumberDataPoint(orig)) } +func newMutableNumberDataPoint(orig *otlpmetrics.NumberDataPoint) MutableNumberDataPoint { + return MutableNumberDataPoint(internal.NewNumberDataPoint(orig)) +} + func (ms NumberDataPoint) getOrig() *otlpmetrics.NumberDataPoint { return internal.GetOrigNumberDataPoint(internal.NumberDataPoint(ms)) } +func (ms MutableNumberDataPoint) getOrig() *otlpmetrics.NumberDataPoint { + return internal.GetMutableOrigNumberDataPoint(internal.MutableNumberDataPoint(ms)) +} + // NewNumberDataPoint creates a new empty NumberDataPoint. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewNumberDataPoint() NumberDataPoint { - return newNumberDataPoint(&otlpmetrics.NumberDataPoint{}) +func NewNumberDataPoint() MutableNumberDataPoint { + return newMutableNumberDataPoint(&otlpmetrics.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) { +func (ms MutableNumberDataPoint) MoveTo(dest MutableNumberDataPoint) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.NumberDataPoint{} } @@ -1199,13 +1511,23 @@ func (ms NumberDataPoint) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this NumberDataPoint. +func (ms MutableNumberDataPoint) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // StartTimestamp returns the starttimestamp associated with this NumberDataPoint. func (ms NumberDataPoint) StartTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) } +// StartTimestamp returns the starttimestamp associated with this NumberDataPoint. +func (ms MutableNumberDataPoint) StartTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) +} + // SetStartTimestamp replaces the starttimestamp associated with this NumberDataPoint. -func (ms NumberDataPoint) SetStartTimestamp(v pcommon.Timestamp) { +func (ms MutableNumberDataPoint) SetStartTimestamp(v pcommon.Timestamp) { ms.getOrig().StartTimeUnixNano = uint64(v) } @@ -1214,8 +1536,13 @@ func (ms NumberDataPoint) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this NumberDataPoint. +func (ms MutableNumberDataPoint) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this NumberDataPoint. -func (ms NumberDataPoint) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableNumberDataPoint) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -1236,8 +1563,12 @@ func (ms NumberDataPoint) DoubleValue() float64 { return ms.getOrig().GetAsDouble() } +func (ms MutableNumberDataPoint) DoubleValue() float64 { + return ms.getOrig().GetAsDouble() +} + // SetDoubleValue replaces the double associated with this NumberDataPoint. -func (ms NumberDataPoint) SetDoubleValue(v float64) { +func (ms MutableNumberDataPoint) SetDoubleValue(v float64) { ms.getOrig().Value = &otlpmetrics.NumberDataPoint_AsDouble{ AsDouble: v, } @@ -1248,8 +1579,12 @@ func (ms NumberDataPoint) IntValue() int64 { return ms.getOrig().GetAsInt() } +func (ms MutableNumberDataPoint) IntValue() int64 { + return ms.getOrig().GetAsInt() +} + // SetIntValue replaces the int associated with this NumberDataPoint. -func (ms NumberDataPoint) SetIntValue(v int64) { +func (ms MutableNumberDataPoint) SetIntValue(v int64) { ms.getOrig().Value = &otlpmetrics.NumberDataPoint_AsInt{ AsInt: v, } @@ -1260,18 +1595,28 @@ func (ms NumberDataPoint) Exemplars() ExemplarSlice { return ExemplarSlice(internal.NewExemplarSlice(&ms.getOrig().Exemplars)) } +// Exemplars returns the Exemplars associated with this NumberDataPoint. +func (ms MutableNumberDataPoint) Exemplars() MutableExemplarSlice { + return MutableExemplarSlice(internal.NewMutableExemplarSlice(&ms.getOrig().Exemplars)) +} + // Flags returns the flags associated with this NumberDataPoint. func (ms NumberDataPoint) Flags() DataPointFlags { return DataPointFlags(ms.getOrig().Flags) } +// Flags returns the flags associated with this NumberDataPoint. +func (ms MutableNumberDataPoint) Flags() DataPointFlags { + return DataPointFlags(ms.getOrig().Flags) +} + // SetFlags replaces the flags associated with this NumberDataPoint. -func (ms NumberDataPoint) SetFlags(v DataPointFlags) { +func (ms MutableNumberDataPoint) SetFlags(v DataPointFlags) { ms.getOrig().Flags = uint32(v) } // CopyTo copies all properties from the current struct overriding the destination. -func (ms NumberDataPoint) CopyTo(dest NumberDataPoint) { +func (ms NumberDataPoint) CopyTo(dest MutableNumberDataPoint) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetStartTimestamp(ms.StartTimestamp()) dest.SetTimestamp(ms.Timestamp()) @@ -1286,6 +1631,11 @@ func (ms NumberDataPoint) CopyTo(dest NumberDataPoint) { dest.SetFlags(ms.Flags()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableNumberDataPoint) CopyTo(dest MutableNumberDataPoint) { + newNumberDataPoint(ms.getOrig()).CopyTo(dest) +} + // HistogramDataPointSlice logically represents a slice of HistogramDataPoint. // // This is a reference type. If passed by value and callee modifies it, the @@ -1295,19 +1645,29 @@ func (ms NumberDataPoint) CopyTo(dest NumberDataPoint) { // Important: zero-initialized instance is not valid for use. type HistogramDataPointSlice internal.HistogramDataPointSlice +type MutableHistogramDataPointSlice internal.MutableHistogramDataPointSlice + func newHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) HistogramDataPointSlice { return HistogramDataPointSlice(internal.NewHistogramDataPointSlice(orig)) } +func newMutableHistogramDataPointSlice(orig *[]*otlpmetrics.HistogramDataPoint) MutableHistogramDataPointSlice { + return MutableHistogramDataPointSlice(internal.NewHistogramDataPointSlice(orig)) +} + func (ms HistogramDataPointSlice) getOrig() *[]*otlpmetrics.HistogramDataPoint { return internal.GetOrigHistogramDataPointSlice(internal.HistogramDataPointSlice(ms)) } +func (ms MutableHistogramDataPointSlice) getOrig() *[]*otlpmetrics.HistogramDataPoint { + return internal.GetMutableOrigHistogramDataPointSlice(internal.MutableHistogramDataPointSlice(ms)) +} + // NewHistogramDataPointSlice creates a HistogramDataPointSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewHistogramDataPointSlice() HistogramDataPointSlice { +func NewHistogramDataPointSlice() MutableHistogramDataPointSlice { orig := []*otlpmetrics.HistogramDataPoint(nil) - return newHistogramDataPointSlice(&orig) + return newMutableHistogramDataPointSlice(&orig) } // Len returns the number of elements in the slice. @@ -1317,6 +1677,10 @@ func (es HistogramDataPointSlice) Len() int { return len(*es.getOrig()) } +func (es MutableHistogramDataPointSlice) 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: @@ -1329,14 +1693,18 @@ func (es HistogramDataPointSlice) At(ix int) HistogramDataPoint { return newHistogramDataPoint((*es.getOrig())[ix]) } +func (es MutableHistogramDataPointSlice) At(ix int) MutableHistogramDataPoint { + return newMutableHistogramDataPoint((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { +func (es HistogramDataPointSlice) CopyTo(dest MutableHistogramDataPointSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newHistogramDataPoint((*es.getOrig())[i]).CopyTo(newHistogramDataPoint((*dest.getOrig())[i])) + newHistogramDataPoint((*es.getOrig())[i]).CopyTo(newMutableHistogramDataPoint((*dest.getOrig())[i])) } return } @@ -1344,11 +1712,16 @@ func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { wrappers := make([]*otlpmetrics.HistogramDataPoint, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newHistogramDataPoint((*es.getOrig())[i]).CopyTo(newHistogramDataPoint(wrappers[i])) + newHistogramDataPoint((*es.getOrig())[i]).CopyTo(newMutableHistogramDataPoint(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableHistogramDataPointSlice) CopyTo(dest MutableHistogramDataPointSlice) { + newHistogramDataPointSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -1361,7 +1734,7 @@ func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es HistogramDataPointSlice) EnsureCapacity(newCap int) { +func (es MutableHistogramDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -1374,7 +1747,7 @@ func (es HistogramDataPointSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty HistogramDataPoint. // It returns the newly added HistogramDataPoint. -func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { +func (es MutableHistogramDataPointSlice) AppendEmpty() MutableHistogramDataPoint { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.HistogramDataPoint{}) return es.At(es.Len() - 1) } @@ -1382,13 +1755,13 @@ func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { // Sort sorts the HistogramDataPoint elements within HistogramDataPointSlice given the // provided less function so that two instances of HistogramDataPointSlice // can be compared. -func (es HistogramDataPointSlice) Sort(less func(a, b HistogramDataPoint) bool) { +func (es MutableHistogramDataPointSlice) Sort(less func(a, b MutableHistogramDataPoint) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableHistogramDataPointSlice) MoveAndAppendTo(dest MutableHistogramDataPointSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -1400,7 +1773,7 @@ func (es HistogramDataPointSlice) MoveAndAppendTo(dest HistogramDataPointSlice) // 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) { +func (es MutableHistogramDataPointSlice) RemoveIf(f func(MutableHistogramDataPoint) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -1428,25 +1801,35 @@ func (es HistogramDataPointSlice) RemoveIf(f func(HistogramDataPoint) bool) { type HistogramDataPoint internal.HistogramDataPoint +type MutableHistogramDataPoint internal.MutableHistogramDataPoint + func newHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) HistogramDataPoint { return HistogramDataPoint(internal.NewHistogramDataPoint(orig)) } +func newMutableHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint) MutableHistogramDataPoint { + return MutableHistogramDataPoint(internal.NewHistogramDataPoint(orig)) +} + func (ms HistogramDataPoint) getOrig() *otlpmetrics.HistogramDataPoint { return internal.GetOrigHistogramDataPoint(internal.HistogramDataPoint(ms)) } +func (ms MutableHistogramDataPoint) getOrig() *otlpmetrics.HistogramDataPoint { + return internal.GetMutableOrigHistogramDataPoint(internal.MutableHistogramDataPoint(ms)) +} + // NewHistogramDataPoint creates a new empty HistogramDataPoint. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewHistogramDataPoint() HistogramDataPoint { - return newHistogramDataPoint(&otlpmetrics.HistogramDataPoint{}) +func NewHistogramDataPoint() MutableHistogramDataPoint { + return newMutableHistogramDataPoint(&otlpmetrics.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) { +func (ms MutableHistogramDataPoint) MoveTo(dest MutableHistogramDataPoint) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.HistogramDataPoint{} } @@ -1456,13 +1839,23 @@ func (ms HistogramDataPoint) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // StartTimestamp returns the starttimestamp associated with this HistogramDataPoint. func (ms HistogramDataPoint) StartTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) } +// StartTimestamp returns the starttimestamp associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) StartTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) +} + // SetStartTimestamp replaces the starttimestamp associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) { +func (ms MutableHistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) { ms.getOrig().StartTimeUnixNano = uint64(v) } @@ -1471,8 +1864,13 @@ func (ms HistogramDataPoint) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableHistogramDataPoint) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -1481,8 +1879,13 @@ func (ms HistogramDataPoint) Count() uint64 { return ms.getOrig().Count } +// MutableCount returns the count associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Count() uint64 { + return ms.getOrig().Count +} + // SetCount replaces the count associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetCount(v uint64) { +func (ms MutableHistogramDataPoint) SetCount(v uint64) { ms.getOrig().Count = v } @@ -1491,19 +1894,30 @@ func (ms HistogramDataPoint) Sum() float64 { return ms.getOrig().GetSum() } +// Sum returns the sum associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Sum() float64 { + return ms.getOrig().GetSum() +} + // HasSum returns true if the HistogramDataPoint contains a // Sum value, false otherwise. func (ms HistogramDataPoint) HasSum() bool { return ms.getOrig().Sum_ != nil } +// HasSum returns true if the HistogramDataPoint contains a +// Sum value, false otherwise. +func (ms MutableHistogramDataPoint) HasSum() bool { + return ms.getOrig().Sum_ != nil +} + // SetSum replaces the sum associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetSum(v float64) { +func (ms MutableHistogramDataPoint) SetSum(v float64) { ms.getOrig().Sum_ = &otlpmetrics.HistogramDataPoint_Sum{Sum: v} } // RemoveSum removes the sum associated with this HistogramDataPoint. -func (ms HistogramDataPoint) RemoveSum() { +func (ms MutableHistogramDataPoint) RemoveSum() { ms.getOrig().Sum_ = nil } @@ -1512,23 +1926,43 @@ func (ms HistogramDataPoint) BucketCounts() pcommon.UInt64Slice { return pcommon.UInt64Slice(internal.NewUInt64Slice(&ms.getOrig().BucketCounts)) } +// BucketCounts returns the bucketcounts associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) BucketCounts() pcommon.MutableUInt64Slice { + return pcommon.MutableUInt64Slice(internal.NewMutableUInt64Slice(&ms.getOrig().BucketCounts)) +} + // ExplicitBounds returns the explicitbounds associated with this HistogramDataPoint. func (ms HistogramDataPoint) ExplicitBounds() pcommon.Float64Slice { return pcommon.Float64Slice(internal.NewFloat64Slice(&ms.getOrig().ExplicitBounds)) } +// ExplicitBounds returns the explicitbounds associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) ExplicitBounds() pcommon.MutableFloat64Slice { + return pcommon.MutableFloat64Slice(internal.NewMutableFloat64Slice(&ms.getOrig().ExplicitBounds)) +} + // Exemplars returns the Exemplars associated with this HistogramDataPoint. func (ms HistogramDataPoint) Exemplars() ExemplarSlice { return ExemplarSlice(internal.NewExemplarSlice(&ms.getOrig().Exemplars)) } +// Exemplars returns the Exemplars associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Exemplars() MutableExemplarSlice { + return MutableExemplarSlice(internal.NewMutableExemplarSlice(&ms.getOrig().Exemplars)) +} + // Flags returns the flags associated with this HistogramDataPoint. func (ms HistogramDataPoint) Flags() DataPointFlags { return DataPointFlags(ms.getOrig().Flags) } +// Flags returns the flags associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Flags() DataPointFlags { + return DataPointFlags(ms.getOrig().Flags) +} + // SetFlags replaces the flags associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetFlags(v DataPointFlags) { +func (ms MutableHistogramDataPoint) SetFlags(v DataPointFlags) { ms.getOrig().Flags = uint32(v) } @@ -1537,19 +1971,30 @@ func (ms HistogramDataPoint) Min() float64 { return ms.getOrig().GetMin() } +// Min returns the min associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Min() float64 { + return ms.getOrig().GetMin() +} + // HasMin returns true if the HistogramDataPoint contains a // Min value, false otherwise. func (ms HistogramDataPoint) HasMin() bool { return ms.getOrig().Min_ != nil } +// HasMin returns true if the HistogramDataPoint contains a +// Min value, false otherwise. +func (ms MutableHistogramDataPoint) HasMin() bool { + return ms.getOrig().Min_ != nil +} + // SetMin replaces the min associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetMin(v float64) { +func (ms MutableHistogramDataPoint) SetMin(v float64) { ms.getOrig().Min_ = &otlpmetrics.HistogramDataPoint_Min{Min: v} } // RemoveMin removes the min associated with this HistogramDataPoint. -func (ms HistogramDataPoint) RemoveMin() { +func (ms MutableHistogramDataPoint) RemoveMin() { ms.getOrig().Min_ = nil } @@ -1558,24 +2003,35 @@ func (ms HistogramDataPoint) Max() float64 { return ms.getOrig().GetMax() } +// Max returns the max associated with this HistogramDataPoint. +func (ms MutableHistogramDataPoint) Max() float64 { + return ms.getOrig().GetMax() +} + // HasMax returns true if the HistogramDataPoint contains a // Max value, false otherwise. func (ms HistogramDataPoint) HasMax() bool { return ms.getOrig().Max_ != nil } +// HasMax returns true if the HistogramDataPoint contains a +// Max value, false otherwise. +func (ms MutableHistogramDataPoint) HasMax() bool { + return ms.getOrig().Max_ != nil +} + // SetMax replaces the max associated with this HistogramDataPoint. -func (ms HistogramDataPoint) SetMax(v float64) { +func (ms MutableHistogramDataPoint) SetMax(v float64) { ms.getOrig().Max_ = &otlpmetrics.HistogramDataPoint_Max{Max: v} } // RemoveMax removes the max associated with this HistogramDataPoint. -func (ms HistogramDataPoint) RemoveMax() { +func (ms MutableHistogramDataPoint) RemoveMax() { ms.getOrig().Max_ = nil } // CopyTo copies all properties from the current struct overriding the destination. -func (ms HistogramDataPoint) CopyTo(dest HistogramDataPoint) { +func (ms HistogramDataPoint) CopyTo(dest MutableHistogramDataPoint) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetStartTimestamp(ms.StartTimestamp()) dest.SetTimestamp(ms.Timestamp()) @@ -1598,6 +2054,11 @@ func (ms HistogramDataPoint) CopyTo(dest HistogramDataPoint) { } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableHistogramDataPoint) CopyTo(dest MutableHistogramDataPoint) { + newHistogramDataPoint(ms.getOrig()).CopyTo(dest) +} + // ExponentialHistogramDataPointSlice logically represents a slice of ExponentialHistogramDataPoint. // // This is a reference type. If passed by value and callee modifies it, the @@ -1607,19 +2068,29 @@ func (ms HistogramDataPoint) CopyTo(dest HistogramDataPoint) { // Important: zero-initialized instance is not valid for use. type ExponentialHistogramDataPointSlice internal.ExponentialHistogramDataPointSlice +type MutableExponentialHistogramDataPointSlice internal.MutableExponentialHistogramDataPointSlice + func newExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPointSlice { return ExponentialHistogramDataPointSlice(internal.NewExponentialHistogramDataPointSlice(orig)) } +func newMutableExponentialHistogramDataPointSlice(orig *[]*otlpmetrics.ExponentialHistogramDataPoint) MutableExponentialHistogramDataPointSlice { + return MutableExponentialHistogramDataPointSlice(internal.NewExponentialHistogramDataPointSlice(orig)) +} + func (ms ExponentialHistogramDataPointSlice) getOrig() *[]*otlpmetrics.ExponentialHistogramDataPoint { return internal.GetOrigExponentialHistogramDataPointSlice(internal.ExponentialHistogramDataPointSlice(ms)) } +func (ms MutableExponentialHistogramDataPointSlice) getOrig() *[]*otlpmetrics.ExponentialHistogramDataPoint { + return internal.GetMutableOrigExponentialHistogramDataPointSlice(internal.MutableExponentialHistogramDataPointSlice(ms)) +} + // NewExponentialHistogramDataPointSlice creates a ExponentialHistogramDataPointSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewExponentialHistogramDataPointSlice() ExponentialHistogramDataPointSlice { +func NewExponentialHistogramDataPointSlice() MutableExponentialHistogramDataPointSlice { orig := []*otlpmetrics.ExponentialHistogramDataPoint(nil) - return newExponentialHistogramDataPointSlice(&orig) + return newMutableExponentialHistogramDataPointSlice(&orig) } // Len returns the number of elements in the slice. @@ -1629,6 +2100,10 @@ func (es ExponentialHistogramDataPointSlice) Len() int { return len(*es.getOrig()) } +func (es MutableExponentialHistogramDataPointSlice) 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: @@ -1641,14 +2116,18 @@ func (es ExponentialHistogramDataPointSlice) At(ix int) ExponentialHistogramData return newExponentialHistogramDataPoint((*es.getOrig())[ix]) } +func (es MutableExponentialHistogramDataPointSlice) At(ix int) MutableExponentialHistogramDataPoint { + return newMutableExponentialHistogramDataPoint((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDataPointSlice) { +func (es ExponentialHistogramDataPointSlice) CopyTo(dest MutableExponentialHistogramDataPointSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newExponentialHistogramDataPoint((*es.getOrig())[i]).CopyTo(newExponentialHistogramDataPoint((*dest.getOrig())[i])) + newExponentialHistogramDataPoint((*es.getOrig())[i]).CopyTo(newMutableExponentialHistogramDataPoint((*dest.getOrig())[i])) } return } @@ -1656,11 +2135,16 @@ func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDat wrappers := make([]*otlpmetrics.ExponentialHistogramDataPoint, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newExponentialHistogramDataPoint((*es.getOrig())[i]).CopyTo(newExponentialHistogramDataPoint(wrappers[i])) + newExponentialHistogramDataPoint((*es.getOrig())[i]).CopyTo(newMutableExponentialHistogramDataPoint(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableExponentialHistogramDataPointSlice) CopyTo(dest MutableExponentialHistogramDataPointSlice) { + newExponentialHistogramDataPointSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -1673,7 +2157,7 @@ func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDat // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ExponentialHistogramDataPointSlice) EnsureCapacity(newCap int) { +func (es MutableExponentialHistogramDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -1686,7 +2170,7 @@ func (es ExponentialHistogramDataPointSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ExponentialHistogramDataPoint. // It returns the newly added ExponentialHistogramDataPoint. -func (es ExponentialHistogramDataPointSlice) AppendEmpty() ExponentialHistogramDataPoint { +func (es MutableExponentialHistogramDataPointSlice) AppendEmpty() MutableExponentialHistogramDataPoint { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.ExponentialHistogramDataPoint{}) return es.At(es.Len() - 1) } @@ -1694,13 +2178,13 @@ func (es ExponentialHistogramDataPointSlice) AppendEmpty() ExponentialHistogramD // Sort sorts the ExponentialHistogramDataPoint elements within ExponentialHistogramDataPointSlice given the // provided less function so that two instances of ExponentialHistogramDataPointSlice // can be compared. -func (es ExponentialHistogramDataPointSlice) Sort(less func(a, b ExponentialHistogramDataPoint) bool) { +func (es MutableExponentialHistogramDataPointSlice) Sort(less func(a, b MutableExponentialHistogramDataPoint) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableExponentialHistogramDataPointSlice) MoveAndAppendTo(dest MutableExponentialHistogramDataPointSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -1712,7 +2196,7 @@ func (es ExponentialHistogramDataPointSlice) MoveAndAppendTo(dest ExponentialHis // 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) { +func (es MutableExponentialHistogramDataPointSlice) RemoveIf(f func(MutableExponentialHistogramDataPoint) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -1743,25 +2227,35 @@ func (es ExponentialHistogramDataPointSlice) RemoveIf(f func(ExponentialHistogra type ExponentialHistogramDataPoint internal.ExponentialHistogramDataPoint +type MutableExponentialHistogramDataPoint internal.MutableExponentialHistogramDataPoint + func newExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) ExponentialHistogramDataPoint { return ExponentialHistogramDataPoint(internal.NewExponentialHistogramDataPoint(orig)) } +func newMutableExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistogramDataPoint) MutableExponentialHistogramDataPoint { + return MutableExponentialHistogramDataPoint(internal.NewExponentialHistogramDataPoint(orig)) +} + func (ms ExponentialHistogramDataPoint) getOrig() *otlpmetrics.ExponentialHistogramDataPoint { return internal.GetOrigExponentialHistogramDataPoint(internal.ExponentialHistogramDataPoint(ms)) } +func (ms MutableExponentialHistogramDataPoint) getOrig() *otlpmetrics.ExponentialHistogramDataPoint { + return internal.GetMutableOrigExponentialHistogramDataPoint(internal.MutableExponentialHistogramDataPoint(ms)) +} + // NewExponentialHistogramDataPoint creates a new empty ExponentialHistogramDataPoint. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExponentialHistogramDataPoint() ExponentialHistogramDataPoint { - return newExponentialHistogramDataPoint(&otlpmetrics.ExponentialHistogramDataPoint{}) +func NewExponentialHistogramDataPoint() MutableExponentialHistogramDataPoint { + return newMutableExponentialHistogramDataPoint(&otlpmetrics.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) { +func (ms MutableExponentialHistogramDataPoint) MoveTo(dest MutableExponentialHistogramDataPoint) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.ExponentialHistogramDataPoint{} } @@ -1771,13 +2265,23 @@ func (ms ExponentialHistogramDataPoint) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // StartTimestamp returns the starttimestamp associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) StartTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) } +// StartTimestamp returns the starttimestamp associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) StartTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) +} + // SetStartTimestamp replaces the starttimestamp associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) { +func (ms MutableExponentialHistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) { ms.getOrig().StartTimeUnixNano = uint64(v) } @@ -1786,8 +2290,13 @@ func (ms ExponentialHistogramDataPoint) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableExponentialHistogramDataPoint) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -1796,8 +2305,13 @@ func (ms ExponentialHistogramDataPoint) Count() uint64 { return ms.getOrig().Count } +// MutableCount returns the count associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Count() uint64 { + return ms.getOrig().Count +} + // SetCount replaces the count associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetCount(v uint64) { +func (ms MutableExponentialHistogramDataPoint) SetCount(v uint64) { ms.getOrig().Count = v } @@ -1806,19 +2320,30 @@ func (ms ExponentialHistogramDataPoint) Sum() float64 { return ms.getOrig().GetSum() } +// Sum returns the sum associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Sum() float64 { + return ms.getOrig().GetSum() +} + // HasSum returns true if the ExponentialHistogramDataPoint contains a // Sum value, false otherwise. func (ms ExponentialHistogramDataPoint) HasSum() bool { return ms.getOrig().Sum_ != nil } +// HasSum returns true if the ExponentialHistogramDataPoint contains a +// Sum value, false otherwise. +func (ms MutableExponentialHistogramDataPoint) HasSum() bool { + return ms.getOrig().Sum_ != nil +} + // SetSum replaces the sum associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetSum(v float64) { +func (ms MutableExponentialHistogramDataPoint) SetSum(v float64) { ms.getOrig().Sum_ = &otlpmetrics.ExponentialHistogramDataPoint_Sum{Sum: v} } // RemoveSum removes the sum associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) RemoveSum() { +func (ms MutableExponentialHistogramDataPoint) RemoveSum() { ms.getOrig().Sum_ = nil } @@ -1827,8 +2352,13 @@ func (ms ExponentialHistogramDataPoint) Scale() int32 { return ms.getOrig().Scale } +// MutableScale returns the scale associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Scale() int32 { + return ms.getOrig().Scale +} + // SetScale replaces the scale associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetScale(v int32) { +func (ms MutableExponentialHistogramDataPoint) SetScale(v int32) { ms.getOrig().Scale = v } @@ -1837,8 +2367,13 @@ func (ms ExponentialHistogramDataPoint) ZeroCount() uint64 { return ms.getOrig().ZeroCount } +// MutableZeroCount returns the zerocount associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) ZeroCount() uint64 { + return ms.getOrig().ZeroCount +} + // SetZeroCount replaces the zerocount associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetZeroCount(v uint64) { +func (ms MutableExponentialHistogramDataPoint) SetZeroCount(v uint64) { ms.getOrig().ZeroCount = v } @@ -1847,23 +2382,43 @@ func (ms ExponentialHistogramDataPoint) Positive() ExponentialHistogramDataPoint return ExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(&ms.getOrig().Positive)) } +// Positive returns the positive associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Positive() MutableExponentialHistogramDataPointBuckets { + return MutableExponentialHistogramDataPointBuckets(internal.NewMutableExponentialHistogramDataPointBuckets(&ms.getOrig().Positive)) +} + // Negative returns the negative associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Negative() ExponentialHistogramDataPointBuckets { return ExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(&ms.getOrig().Negative)) } +// Negative returns the negative associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Negative() MutableExponentialHistogramDataPointBuckets { + return MutableExponentialHistogramDataPointBuckets(internal.NewMutableExponentialHistogramDataPointBuckets(&ms.getOrig().Negative)) +} + // Exemplars returns the Exemplars associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Exemplars() ExemplarSlice { return ExemplarSlice(internal.NewExemplarSlice(&ms.getOrig().Exemplars)) } +// Exemplars returns the Exemplars associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Exemplars() MutableExemplarSlice { + return MutableExemplarSlice(internal.NewMutableExemplarSlice(&ms.getOrig().Exemplars)) +} + // Flags returns the flags associated with this ExponentialHistogramDataPoint. func (ms ExponentialHistogramDataPoint) Flags() DataPointFlags { return DataPointFlags(ms.getOrig().Flags) } +// Flags returns the flags associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Flags() DataPointFlags { + return DataPointFlags(ms.getOrig().Flags) +} + // SetFlags replaces the flags associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetFlags(v DataPointFlags) { +func (ms MutableExponentialHistogramDataPoint) SetFlags(v DataPointFlags) { ms.getOrig().Flags = uint32(v) } @@ -1872,19 +2427,30 @@ func (ms ExponentialHistogramDataPoint) Min() float64 { return ms.getOrig().GetMin() } +// Min returns the min associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Min() float64 { + return ms.getOrig().GetMin() +} + // HasMin returns true if the ExponentialHistogramDataPoint contains a // Min value, false otherwise. func (ms ExponentialHistogramDataPoint) HasMin() bool { return ms.getOrig().Min_ != nil } +// HasMin returns true if the ExponentialHistogramDataPoint contains a +// Min value, false otherwise. +func (ms MutableExponentialHistogramDataPoint) HasMin() bool { + return ms.getOrig().Min_ != nil +} + // SetMin replaces the min associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetMin(v float64) { +func (ms MutableExponentialHistogramDataPoint) SetMin(v float64) { ms.getOrig().Min_ = &otlpmetrics.ExponentialHistogramDataPoint_Min{Min: v} } // RemoveMin removes the min associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) RemoveMin() { +func (ms MutableExponentialHistogramDataPoint) RemoveMin() { ms.getOrig().Min_ = nil } @@ -1893,24 +2459,35 @@ func (ms ExponentialHistogramDataPoint) Max() float64 { return ms.getOrig().GetMax() } +// Max returns the max associated with this ExponentialHistogramDataPoint. +func (ms MutableExponentialHistogramDataPoint) Max() float64 { + return ms.getOrig().GetMax() +} + // HasMax returns true if the ExponentialHistogramDataPoint contains a // Max value, false otherwise. func (ms ExponentialHistogramDataPoint) HasMax() bool { return ms.getOrig().Max_ != nil } +// HasMax returns true if the ExponentialHistogramDataPoint contains a +// Max value, false otherwise. +func (ms MutableExponentialHistogramDataPoint) HasMax() bool { + return ms.getOrig().Max_ != nil +} + // SetMax replaces the max associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) SetMax(v float64) { +func (ms MutableExponentialHistogramDataPoint) SetMax(v float64) { ms.getOrig().Max_ = &otlpmetrics.ExponentialHistogramDataPoint_Max{Max: v} } // RemoveMax removes the max associated with this ExponentialHistogramDataPoint. -func (ms ExponentialHistogramDataPoint) RemoveMax() { +func (ms MutableExponentialHistogramDataPoint) RemoveMax() { ms.getOrig().Max_ = nil } // CopyTo copies all properties from the current struct overriding the destination. -func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoint) { +func (ms ExponentialHistogramDataPoint) CopyTo(dest MutableExponentialHistogramDataPoint) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetStartTimestamp(ms.StartTimestamp()) dest.SetTimestamp(ms.Timestamp()) @@ -1935,6 +2512,11 @@ func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoin } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExponentialHistogramDataPoint) CopyTo(dest MutableExponentialHistogramDataPoint) { + newExponentialHistogramDataPoint(ms.getOrig()).CopyTo(dest) +} + // ExponentialHistogramDataPointBuckets are a set of bucket counts, encoded in a contiguous array of counts. // // This is a reference type, if passed by value and callee modifies it the @@ -1945,25 +2527,35 @@ func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoin type ExponentialHistogramDataPointBuckets internal.ExponentialHistogramDataPointBuckets +type MutableExponentialHistogramDataPointBuckets internal.MutableExponentialHistogramDataPointBuckets + func newExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) ExponentialHistogramDataPointBuckets { return ExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(orig)) } +func newMutableExponentialHistogramDataPointBuckets(orig *otlpmetrics.ExponentialHistogramDataPoint_Buckets) MutableExponentialHistogramDataPointBuckets { + return MutableExponentialHistogramDataPointBuckets(internal.NewExponentialHistogramDataPointBuckets(orig)) +} + func (ms ExponentialHistogramDataPointBuckets) getOrig() *otlpmetrics.ExponentialHistogramDataPoint_Buckets { return internal.GetOrigExponentialHistogramDataPointBuckets(internal.ExponentialHistogramDataPointBuckets(ms)) } +func (ms MutableExponentialHistogramDataPointBuckets) getOrig() *otlpmetrics.ExponentialHistogramDataPoint_Buckets { + return internal.GetMutableOrigExponentialHistogramDataPointBuckets(internal.MutableExponentialHistogramDataPointBuckets(ms)) +} + // NewExponentialHistogramDataPointBuckets creates a new empty ExponentialHistogramDataPointBuckets. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExponentialHistogramDataPointBuckets() ExponentialHistogramDataPointBuckets { - return newExponentialHistogramDataPointBuckets(&otlpmetrics.ExponentialHistogramDataPoint_Buckets{}) +func NewExponentialHistogramDataPointBuckets() MutableExponentialHistogramDataPointBuckets { + return newMutableExponentialHistogramDataPointBuckets(&otlpmetrics.ExponentialHistogramDataPoint_Buckets{}) } // 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) { +func (ms MutableExponentialHistogramDataPointBuckets) MoveTo(dest MutableExponentialHistogramDataPointBuckets) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.ExponentialHistogramDataPoint_Buckets{} } @@ -1973,8 +2565,13 @@ func (ms ExponentialHistogramDataPointBuckets) Offset() int32 { return ms.getOrig().Offset } +// MutableOffset returns the offset associated with this ExponentialHistogramDataPointBuckets. +func (ms MutableExponentialHistogramDataPointBuckets) Offset() int32 { + return ms.getOrig().Offset +} + // SetOffset replaces the offset associated with this ExponentialHistogramDataPointBuckets. -func (ms ExponentialHistogramDataPointBuckets) SetOffset(v int32) { +func (ms MutableExponentialHistogramDataPointBuckets) SetOffset(v int32) { ms.getOrig().Offset = v } @@ -1983,12 +2580,22 @@ func (ms ExponentialHistogramDataPointBuckets) BucketCounts() pcommon.UInt64Slic return pcommon.UInt64Slice(internal.NewUInt64Slice(&ms.getOrig().BucketCounts)) } +// BucketCounts returns the bucketcounts associated with this ExponentialHistogramDataPointBuckets. +func (ms MutableExponentialHistogramDataPointBuckets) BucketCounts() pcommon.MutableUInt64Slice { + return pcommon.MutableUInt64Slice(internal.NewMutableUInt64Slice(&ms.getOrig().BucketCounts)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ExponentialHistogramDataPointBuckets) CopyTo(dest ExponentialHistogramDataPointBuckets) { +func (ms ExponentialHistogramDataPointBuckets) CopyTo(dest MutableExponentialHistogramDataPointBuckets) { dest.SetOffset(ms.Offset()) ms.BucketCounts().CopyTo(dest.BucketCounts()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExponentialHistogramDataPointBuckets) CopyTo(dest MutableExponentialHistogramDataPointBuckets) { + newExponentialHistogramDataPointBuckets(ms.getOrig()).CopyTo(dest) +} + // SummaryDataPointSlice logically represents a slice of SummaryDataPoint. // // This is a reference type. If passed by value and callee modifies it, the @@ -1998,19 +2605,29 @@ func (ms ExponentialHistogramDataPointBuckets) CopyTo(dest ExponentialHistogramD // Important: zero-initialized instance is not valid for use. type SummaryDataPointSlice internal.SummaryDataPointSlice +type MutableSummaryDataPointSlice internal.MutableSummaryDataPointSlice + func newSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) SummaryDataPointSlice { return SummaryDataPointSlice(internal.NewSummaryDataPointSlice(orig)) } +func newMutableSummaryDataPointSlice(orig *[]*otlpmetrics.SummaryDataPoint) MutableSummaryDataPointSlice { + return MutableSummaryDataPointSlice(internal.NewSummaryDataPointSlice(orig)) +} + func (ms SummaryDataPointSlice) getOrig() *[]*otlpmetrics.SummaryDataPoint { return internal.GetOrigSummaryDataPointSlice(internal.SummaryDataPointSlice(ms)) } +func (ms MutableSummaryDataPointSlice) getOrig() *[]*otlpmetrics.SummaryDataPoint { + return internal.GetMutableOrigSummaryDataPointSlice(internal.MutableSummaryDataPointSlice(ms)) +} + // NewSummaryDataPointSlice creates a SummaryDataPointSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewSummaryDataPointSlice() SummaryDataPointSlice { +func NewSummaryDataPointSlice() MutableSummaryDataPointSlice { orig := []*otlpmetrics.SummaryDataPoint(nil) - return newSummaryDataPointSlice(&orig) + return newMutableSummaryDataPointSlice(&orig) } // Len returns the number of elements in the slice. @@ -2020,6 +2637,10 @@ func (es SummaryDataPointSlice) Len() int { return len(*es.getOrig()) } +func (es MutableSummaryDataPointSlice) 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: @@ -2032,14 +2653,18 @@ func (es SummaryDataPointSlice) At(ix int) SummaryDataPoint { return newSummaryDataPoint((*es.getOrig())[ix]) } +func (es MutableSummaryDataPointSlice) At(ix int) MutableSummaryDataPoint { + return newMutableSummaryDataPoint((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { +func (es SummaryDataPointSlice) CopyTo(dest MutableSummaryDataPointSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newSummaryDataPoint((*es.getOrig())[i]).CopyTo(newSummaryDataPoint((*dest.getOrig())[i])) + newSummaryDataPoint((*es.getOrig())[i]).CopyTo(newMutableSummaryDataPoint((*dest.getOrig())[i])) } return } @@ -2047,11 +2672,16 @@ func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { wrappers := make([]*otlpmetrics.SummaryDataPoint, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newSummaryDataPoint((*es.getOrig())[i]).CopyTo(newSummaryDataPoint(wrappers[i])) + newSummaryDataPoint((*es.getOrig())[i]).CopyTo(newMutableSummaryDataPoint(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableSummaryDataPointSlice) CopyTo(dest MutableSummaryDataPointSlice) { + newSummaryDataPointSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -2064,7 +2694,7 @@ func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es SummaryDataPointSlice) EnsureCapacity(newCap int) { +func (es MutableSummaryDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -2077,7 +2707,7 @@ func (es SummaryDataPointSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty SummaryDataPoint. // It returns the newly added SummaryDataPoint. -func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { +func (es MutableSummaryDataPointSlice) AppendEmpty() MutableSummaryDataPoint { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.SummaryDataPoint{}) return es.At(es.Len() - 1) } @@ -2085,13 +2715,13 @@ func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { // Sort sorts the SummaryDataPoint elements within SummaryDataPointSlice given the // provided less function so that two instances of SummaryDataPointSlice // can be compared. -func (es SummaryDataPointSlice) Sort(less func(a, b SummaryDataPoint) bool) { +func (es MutableSummaryDataPointSlice) Sort(less func(a, b MutableSummaryDataPoint) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableSummaryDataPointSlice) MoveAndAppendTo(dest MutableSummaryDataPointSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -2103,7 +2733,7 @@ func (es SummaryDataPointSlice) MoveAndAppendTo(dest SummaryDataPointSlice) { // 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) { +func (es MutableSummaryDataPointSlice) RemoveIf(f func(MutableSummaryDataPoint) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -2131,25 +2761,35 @@ func (es SummaryDataPointSlice) RemoveIf(f func(SummaryDataPoint) bool) { type SummaryDataPoint internal.SummaryDataPoint +type MutableSummaryDataPoint internal.MutableSummaryDataPoint + func newSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) SummaryDataPoint { return SummaryDataPoint(internal.NewSummaryDataPoint(orig)) } +func newMutableSummaryDataPoint(orig *otlpmetrics.SummaryDataPoint) MutableSummaryDataPoint { + return MutableSummaryDataPoint(internal.NewSummaryDataPoint(orig)) +} + func (ms SummaryDataPoint) getOrig() *otlpmetrics.SummaryDataPoint { return internal.GetOrigSummaryDataPoint(internal.SummaryDataPoint(ms)) } +func (ms MutableSummaryDataPoint) getOrig() *otlpmetrics.SummaryDataPoint { + return internal.GetMutableOrigSummaryDataPoint(internal.MutableSummaryDataPoint(ms)) +} + // NewSummaryDataPoint creates a new empty SummaryDataPoint. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSummaryDataPoint() SummaryDataPoint { - return newSummaryDataPoint(&otlpmetrics.SummaryDataPoint{}) +func NewSummaryDataPoint() MutableSummaryDataPoint { + return newMutableSummaryDataPoint(&otlpmetrics.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) { +func (ms MutableSummaryDataPoint) MoveTo(dest MutableSummaryDataPoint) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.SummaryDataPoint{} } @@ -2159,13 +2799,23 @@ func (ms SummaryDataPoint) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // StartTimestamp returns the starttimestamp associated with this SummaryDataPoint. func (ms SummaryDataPoint) StartTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) } +// StartTimestamp returns the starttimestamp associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) StartTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) +} + // SetStartTimestamp replaces the starttimestamp associated with this SummaryDataPoint. -func (ms SummaryDataPoint) SetStartTimestamp(v pcommon.Timestamp) { +func (ms MutableSummaryDataPoint) SetStartTimestamp(v pcommon.Timestamp) { ms.getOrig().StartTimeUnixNano = uint64(v) } @@ -2174,8 +2824,13 @@ func (ms SummaryDataPoint) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this SummaryDataPoint. -func (ms SummaryDataPoint) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableSummaryDataPoint) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -2184,8 +2839,13 @@ func (ms SummaryDataPoint) Count() uint64 { return ms.getOrig().Count } +// MutableCount returns the count associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) Count() uint64 { + return ms.getOrig().Count +} + // SetCount replaces the count associated with this SummaryDataPoint. -func (ms SummaryDataPoint) SetCount(v uint64) { +func (ms MutableSummaryDataPoint) SetCount(v uint64) { ms.getOrig().Count = v } @@ -2194,8 +2854,13 @@ func (ms SummaryDataPoint) Sum() float64 { return ms.getOrig().Sum } +// MutableSum returns the sum associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) Sum() float64 { + return ms.getOrig().Sum +} + // SetSum replaces the sum associated with this SummaryDataPoint. -func (ms SummaryDataPoint) SetSum(v float64) { +func (ms MutableSummaryDataPoint) SetSum(v float64) { ms.getOrig().Sum = v } @@ -2204,18 +2869,28 @@ func (ms SummaryDataPoint) QuantileValues() SummaryDataPointValueAtQuantileSlice return SummaryDataPointValueAtQuantileSlice(internal.NewSummaryDataPointValueAtQuantileSlice(&ms.getOrig().QuantileValues)) } +// QuantileValues returns the QuantileValues associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) QuantileValues() MutableSummaryDataPointValueAtQuantileSlice { + return MutableSummaryDataPointValueAtQuantileSlice(internal.NewMutableSummaryDataPointValueAtQuantileSlice(&ms.getOrig().QuantileValues)) +} + // Flags returns the flags associated with this SummaryDataPoint. func (ms SummaryDataPoint) Flags() DataPointFlags { return DataPointFlags(ms.getOrig().Flags) } +// Flags returns the flags associated with this SummaryDataPoint. +func (ms MutableSummaryDataPoint) Flags() DataPointFlags { + return DataPointFlags(ms.getOrig().Flags) +} + // SetFlags replaces the flags associated with this SummaryDataPoint. -func (ms SummaryDataPoint) SetFlags(v DataPointFlags) { +func (ms MutableSummaryDataPoint) SetFlags(v DataPointFlags) { ms.getOrig().Flags = uint32(v) } // CopyTo copies all properties from the current struct overriding the destination. -func (ms SummaryDataPoint) CopyTo(dest SummaryDataPoint) { +func (ms SummaryDataPoint) CopyTo(dest MutableSummaryDataPoint) { ms.Attributes().CopyTo(dest.Attributes()) dest.SetStartTimestamp(ms.StartTimestamp()) dest.SetTimestamp(ms.Timestamp()) @@ -2225,6 +2900,11 @@ func (ms SummaryDataPoint) CopyTo(dest SummaryDataPoint) { dest.SetFlags(ms.Flags()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSummaryDataPoint) CopyTo(dest MutableSummaryDataPoint) { + newSummaryDataPoint(ms.getOrig()).CopyTo(dest) +} + // SummaryDataPointValueAtQuantileSlice logically represents a slice of SummaryDataPointValueAtQuantile. // // This is a reference type. If passed by value and callee modifies it, the @@ -2234,19 +2914,29 @@ func (ms SummaryDataPoint) CopyTo(dest SummaryDataPoint) { // Important: zero-initialized instance is not valid for use. type SummaryDataPointValueAtQuantileSlice internal.SummaryDataPointValueAtQuantileSlice +type MutableSummaryDataPointValueAtQuantileSlice internal.MutableSummaryDataPointValueAtQuantileSlice + func newSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantileSlice { return SummaryDataPointValueAtQuantileSlice(internal.NewSummaryDataPointValueAtQuantileSlice(orig)) } +func newMutableSummaryDataPointValueAtQuantileSlice(orig *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile) MutableSummaryDataPointValueAtQuantileSlice { + return MutableSummaryDataPointValueAtQuantileSlice(internal.NewSummaryDataPointValueAtQuantileSlice(orig)) +} + func (ms SummaryDataPointValueAtQuantileSlice) getOrig() *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile { return internal.GetOrigSummaryDataPointValueAtQuantileSlice(internal.SummaryDataPointValueAtQuantileSlice(ms)) } +func (ms MutableSummaryDataPointValueAtQuantileSlice) getOrig() *[]*otlpmetrics.SummaryDataPoint_ValueAtQuantile { + return internal.GetMutableOrigSummaryDataPointValueAtQuantileSlice(internal.MutableSummaryDataPointValueAtQuantileSlice(ms)) +} + // NewSummaryDataPointValueAtQuantileSlice creates a SummaryDataPointValueAtQuantileSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewSummaryDataPointValueAtQuantileSlice() SummaryDataPointValueAtQuantileSlice { +func NewSummaryDataPointValueAtQuantileSlice() MutableSummaryDataPointValueAtQuantileSlice { orig := []*otlpmetrics.SummaryDataPoint_ValueAtQuantile(nil) - return newSummaryDataPointValueAtQuantileSlice(&orig) + return newMutableSummaryDataPointValueAtQuantileSlice(&orig) } // Len returns the number of elements in the slice. @@ -2256,6 +2946,10 @@ func (es SummaryDataPointValueAtQuantileSlice) Len() int { return len(*es.getOrig()) } +func (es MutableSummaryDataPointValueAtQuantileSlice) 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: @@ -2268,14 +2962,18 @@ func (es SummaryDataPointValueAtQuantileSlice) At(ix int) SummaryDataPointValueA return newSummaryDataPointValueAtQuantile((*es.getOrig())[ix]) } +func (es MutableSummaryDataPointValueAtQuantileSlice) At(ix int) MutableSummaryDataPointValueAtQuantile { + return newMutableSummaryDataPointValueAtQuantile((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es SummaryDataPointValueAtQuantileSlice) CopyTo(dest SummaryDataPointValueAtQuantileSlice) { +func (es SummaryDataPointValueAtQuantileSlice) CopyTo(dest MutableSummaryDataPointValueAtQuantileSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newSummaryDataPointValueAtQuantile((*es.getOrig())[i]).CopyTo(newSummaryDataPointValueAtQuantile((*dest.getOrig())[i])) + newSummaryDataPointValueAtQuantile((*es.getOrig())[i]).CopyTo(newMutableSummaryDataPointValueAtQuantile((*dest.getOrig())[i])) } return } @@ -2283,11 +2981,16 @@ func (es SummaryDataPointValueAtQuantileSlice) CopyTo(dest SummaryDataPointValue wrappers := make([]*otlpmetrics.SummaryDataPoint_ValueAtQuantile, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newSummaryDataPointValueAtQuantile((*es.getOrig())[i]).CopyTo(newSummaryDataPointValueAtQuantile(wrappers[i])) + newSummaryDataPointValueAtQuantile((*es.getOrig())[i]).CopyTo(newMutableSummaryDataPointValueAtQuantile(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableSummaryDataPointValueAtQuantileSlice) CopyTo(dest MutableSummaryDataPointValueAtQuantileSlice) { + newSummaryDataPointValueAtQuantileSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -2300,7 +3003,7 @@ func (es SummaryDataPointValueAtQuantileSlice) CopyTo(dest SummaryDataPointValue // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es SummaryDataPointValueAtQuantileSlice) EnsureCapacity(newCap int) { +func (es MutableSummaryDataPointValueAtQuantileSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -2313,7 +3016,7 @@ func (es SummaryDataPointValueAtQuantileSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty SummaryDataPointValueAtQuantile. // It returns the newly added SummaryDataPointValueAtQuantile. -func (es SummaryDataPointValueAtQuantileSlice) AppendEmpty() SummaryDataPointValueAtQuantile { +func (es MutableSummaryDataPointValueAtQuantileSlice) AppendEmpty() MutableSummaryDataPointValueAtQuantile { *es.getOrig() = append(*es.getOrig(), &otlpmetrics.SummaryDataPoint_ValueAtQuantile{}) return es.At(es.Len() - 1) } @@ -2321,13 +3024,13 @@ func (es SummaryDataPointValueAtQuantileSlice) AppendEmpty() SummaryDataPointVal // Sort sorts the SummaryDataPointValueAtQuantile elements within SummaryDataPointValueAtQuantileSlice given the // provided less function so that two instances of SummaryDataPointValueAtQuantileSlice // can be compared. -func (es SummaryDataPointValueAtQuantileSlice) Sort(less func(a, b SummaryDataPointValueAtQuantile) bool) { +func (es MutableSummaryDataPointValueAtQuantileSlice) Sort(less func(a, b MutableSummaryDataPointValueAtQuantile) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableSummaryDataPointValueAtQuantileSlice) MoveAndAppendTo(dest MutableSummaryDataPointValueAtQuantileSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -2339,7 +3042,7 @@ func (es SummaryDataPointValueAtQuantileSlice) MoveAndAppendTo(dest SummaryDataP // 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) { +func (es MutableSummaryDataPointValueAtQuantileSlice) RemoveIf(f func(MutableSummaryDataPointValueAtQuantile) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -2367,25 +3070,35 @@ func (es SummaryDataPointValueAtQuantileSlice) RemoveIf(f func(SummaryDataPointV type SummaryDataPointValueAtQuantile internal.SummaryDataPointValueAtQuantile +type MutableSummaryDataPointValueAtQuantile internal.MutableSummaryDataPointValueAtQuantile + func newSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) SummaryDataPointValueAtQuantile { return SummaryDataPointValueAtQuantile(internal.NewSummaryDataPointValueAtQuantile(orig)) } +func newMutableSummaryDataPointValueAtQuantile(orig *otlpmetrics.SummaryDataPoint_ValueAtQuantile) MutableSummaryDataPointValueAtQuantile { + return MutableSummaryDataPointValueAtQuantile(internal.NewSummaryDataPointValueAtQuantile(orig)) +} + func (ms SummaryDataPointValueAtQuantile) getOrig() *otlpmetrics.SummaryDataPoint_ValueAtQuantile { return internal.GetOrigSummaryDataPointValueAtQuantile(internal.SummaryDataPointValueAtQuantile(ms)) } +func (ms MutableSummaryDataPointValueAtQuantile) getOrig() *otlpmetrics.SummaryDataPoint_ValueAtQuantile { + return internal.GetMutableOrigSummaryDataPointValueAtQuantile(internal.MutableSummaryDataPointValueAtQuantile(ms)) +} + // NewSummaryDataPointValueAtQuantile creates a new empty SummaryDataPointValueAtQuantile. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSummaryDataPointValueAtQuantile() SummaryDataPointValueAtQuantile { - return newSummaryDataPointValueAtQuantile(&otlpmetrics.SummaryDataPoint_ValueAtQuantile{}) +func NewSummaryDataPointValueAtQuantile() MutableSummaryDataPointValueAtQuantile { + return newMutableSummaryDataPointValueAtQuantile(&otlpmetrics.SummaryDataPoint_ValueAtQuantile{}) } // 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) { +func (ms MutableSummaryDataPointValueAtQuantile) MoveTo(dest MutableSummaryDataPointValueAtQuantile) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.SummaryDataPoint_ValueAtQuantile{} } @@ -2395,8 +3108,13 @@ func (ms SummaryDataPointValueAtQuantile) Quantile() float64 { return ms.getOrig().Quantile } +// MutableQuantile returns the quantile associated with this SummaryDataPointValueAtQuantile. +func (ms MutableSummaryDataPointValueAtQuantile) Quantile() float64 { + return ms.getOrig().Quantile +} + // SetQuantile replaces the quantile associated with this SummaryDataPointValueAtQuantile. -func (ms SummaryDataPointValueAtQuantile) SetQuantile(v float64) { +func (ms MutableSummaryDataPointValueAtQuantile) SetQuantile(v float64) { ms.getOrig().Quantile = v } @@ -2405,17 +3123,27 @@ func (ms SummaryDataPointValueAtQuantile) Value() float64 { return ms.getOrig().Value } +// MutableValue returns the value associated with this SummaryDataPointValueAtQuantile. +func (ms MutableSummaryDataPointValueAtQuantile) Value() float64 { + return ms.getOrig().Value +} + // SetValue replaces the value associated with this SummaryDataPointValueAtQuantile. -func (ms SummaryDataPointValueAtQuantile) SetValue(v float64) { +func (ms MutableSummaryDataPointValueAtQuantile) SetValue(v float64) { ms.getOrig().Value = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms SummaryDataPointValueAtQuantile) CopyTo(dest SummaryDataPointValueAtQuantile) { +func (ms SummaryDataPointValueAtQuantile) CopyTo(dest MutableSummaryDataPointValueAtQuantile) { dest.SetQuantile(ms.Quantile()) dest.SetValue(ms.Value()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSummaryDataPointValueAtQuantile) CopyTo(dest MutableSummaryDataPointValueAtQuantile) { + newSummaryDataPointValueAtQuantile(ms.getOrig()).CopyTo(dest) +} + // ExemplarSlice logically represents a slice of Exemplar. // // This is a reference type. If passed by value and callee modifies it, the @@ -2425,19 +3153,33 @@ func (ms SummaryDataPointValueAtQuantile) CopyTo(dest SummaryDataPointValueAtQua // Important: zero-initialized instance is not valid for use. type ExemplarSlice internal.ExemplarSlice +type MutableExemplarSlice internal.MutableExemplarSlice + func newExemplarSlice(orig *[]otlpmetrics.Exemplar) ExemplarSlice { return ExemplarSlice(internal.NewExemplarSlice(orig)) } +func newMutableExemplarSlice(orig *[]otlpmetrics.Exemplar) MutableExemplarSlice { + return MutableExemplarSlice(internal.NewExemplarSlice(orig)) +} + func (ms ExemplarSlice) getOrig() *[]otlpmetrics.Exemplar { return internal.GetOrigExemplarSlice(internal.ExemplarSlice(ms)) } +func (ms MutableExemplarSlice) getOrig() *[]otlpmetrics.Exemplar { + return internal.GetMutableOrigExemplarSlice(internal.MutableExemplarSlice(ms)) +} + +func (ms MutableExemplarSlice) immutable() ExemplarSlice { + return newExemplarSlice(ms.getOrig()) +} + // NewExemplarSlice creates a ExemplarSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewExemplarSlice() ExemplarSlice { +func NewExemplarSlice() MutableExemplarSlice { orig := []otlpmetrics.Exemplar(nil) - return ExemplarSlice(internal.NewExemplarSlice(&orig)) + return MutableExemplarSlice(internal.NewExemplarSlice(&orig)) } // Len returns the number of elements in the slice. @@ -2447,6 +3189,10 @@ func (es ExemplarSlice) Len() int { return len(*es.getOrig()) } +func (es MutableExemplarSlice) Len() int { + return newMutableExemplarSlice(es.getOrig()).Len() +} + // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: @@ -2459,8 +3205,12 @@ func (es ExemplarSlice) At(ix int) Exemplar { return newExemplar(&(*es.getOrig())[ix]) } +func (es MutableExemplarSlice) At(ix int) MutableExemplar { + return newMutableExemplar(&(*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { +func (es ExemplarSlice) CopyTo(dest MutableExemplarSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { @@ -2470,10 +3220,15 @@ func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { } for i := range *es.getOrig() { - newExemplar(&(*es.getOrig())[i]).CopyTo(newExemplar(&(*dest.getOrig())[i])) + newExemplar(&(*es.getOrig())[i]).CopyTo(newMutableExemplar(&(*dest.getOrig())[i])) } } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableExemplarSlice) CopyTo(dest MutableExemplarSlice) { + newExemplarSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -2486,7 +3241,7 @@ func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ExemplarSlice) EnsureCapacity(newCap int) { +func (es MutableExemplarSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -2499,14 +3254,14 @@ func (es ExemplarSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty Exemplar. // It returns the newly added Exemplar. -func (es ExemplarSlice) AppendEmpty() Exemplar { +func (es MutableExemplarSlice) AppendEmpty() MutableExemplar { *es.getOrig() = append(*es.getOrig(), 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) { +func (es MutableExemplarSlice) MoveAndAppendTo(dest MutableExemplarSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -2518,7 +3273,7 @@ func (es ExemplarSlice) MoveAndAppendTo(dest ExemplarSlice) { // 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) { +func (es MutableExemplarSlice) RemoveIf(f func(MutableExemplar) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -2549,25 +3304,35 @@ func (es ExemplarSlice) RemoveIf(f func(Exemplar) bool) { type Exemplar internal.Exemplar +type MutableExemplar internal.MutableExemplar + func newExemplar(orig *otlpmetrics.Exemplar) Exemplar { return Exemplar(internal.NewExemplar(orig)) } +func newMutableExemplar(orig *otlpmetrics.Exemplar) MutableExemplar { + return MutableExemplar(internal.NewExemplar(orig)) +} + func (ms Exemplar) getOrig() *otlpmetrics.Exemplar { return internal.GetOrigExemplar(internal.Exemplar(ms)) } +func (ms MutableExemplar) getOrig() *otlpmetrics.Exemplar { + return internal.GetMutableOrigExemplar(internal.MutableExemplar(ms)) +} + // NewExemplar creates a new empty Exemplar. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExemplar() Exemplar { - return newExemplar(&otlpmetrics.Exemplar{}) +func NewExemplar() MutableExemplar { + return newMutableExemplar(&otlpmetrics.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) { +func (ms MutableExemplar) MoveTo(dest MutableExemplar) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpmetrics.Exemplar{} } @@ -2577,8 +3342,13 @@ func (ms Exemplar) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this Exemplar. +func (ms MutableExemplar) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this Exemplar. -func (ms Exemplar) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableExemplar) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -2599,8 +3369,12 @@ func (ms Exemplar) DoubleValue() float64 { return ms.getOrig().GetAsDouble() } +func (ms MutableExemplar) DoubleValue() float64 { + return ms.getOrig().GetAsDouble() +} + // SetDoubleValue replaces the double associated with this Exemplar. -func (ms Exemplar) SetDoubleValue(v float64) { +func (ms MutableExemplar) SetDoubleValue(v float64) { ms.getOrig().Value = &otlpmetrics.Exemplar_AsDouble{ AsDouble: v, } @@ -2611,8 +3385,12 @@ func (ms Exemplar) IntValue() int64 { return ms.getOrig().GetAsInt() } +func (ms MutableExemplar) IntValue() int64 { + return ms.getOrig().GetAsInt() +} + // SetIntValue replaces the int associated with this Exemplar. -func (ms Exemplar) SetIntValue(v int64) { +func (ms MutableExemplar) SetIntValue(v int64) { ms.getOrig().Value = &otlpmetrics.Exemplar_AsInt{ AsInt: v, } @@ -2623,13 +3401,23 @@ func (ms Exemplar) FilteredAttributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().FilteredAttributes)) } +// FilteredAttributes returns the FilteredAttributes associated with this Exemplar. +func (ms MutableExemplar) FilteredAttributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().FilteredAttributes)) +} + // TraceID returns the traceid associated with this Exemplar. func (ms Exemplar) TraceID() pcommon.TraceID { return pcommon.TraceID(ms.getOrig().TraceId) } +// TraceID returns the traceid associated with this Exemplar. +func (ms MutableExemplar) TraceID() pcommon.TraceID { + return pcommon.TraceID(ms.getOrig().TraceId) +} + // SetTraceID replaces the traceid associated with this Exemplar. -func (ms Exemplar) SetTraceID(v pcommon.TraceID) { +func (ms MutableExemplar) SetTraceID(v pcommon.TraceID) { ms.getOrig().TraceId = data.TraceID(v) } @@ -2638,13 +3426,18 @@ func (ms Exemplar) SpanID() pcommon.SpanID { return pcommon.SpanID(ms.getOrig().SpanId) } +// SpanID returns the spanid associated with this Exemplar. +func (ms MutableExemplar) SpanID() pcommon.SpanID { + return pcommon.SpanID(ms.getOrig().SpanId) +} + // SetSpanID replaces the spanid associated with this Exemplar. -func (ms Exemplar) SetSpanID(v pcommon.SpanID) { +func (ms MutableExemplar) SetSpanID(v pcommon.SpanID) { ms.getOrig().SpanId = data.SpanID(v) } // CopyTo copies all properties from the current struct overriding the destination. -func (ms Exemplar) CopyTo(dest Exemplar) { +func (ms Exemplar) CopyTo(dest MutableExemplar) { dest.SetTimestamp(ms.Timestamp()) switch ms.ValueType() { case ExemplarValueTypeDouble: @@ -2657,3 +3450,8 @@ func (ms Exemplar) CopyTo(dest Exemplar) { dest.SetTraceID(ms.TraceID()) dest.SetSpanID(ms.SpanID()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExemplar) CopyTo(dest MutableExemplar) { + newExemplar(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/pmetric/generated_metrics_test.go b/pdata/pmetric/generated_metrics_test.go index 8a27d5d2a79..e38ebd4b8e2 100644 --- a/pdata/pmetric/generated_metrics_test.go +++ b/pdata/pmetric/generated_metrics_test.go @@ -41,7 +41,7 @@ func TestResourceMetricsSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestResourceMetrics(internal.ResourceMetrics(el)) + internal.FillTestResourceMetrics(internal.MutableResourceMetrics(el)) assert.Equal(t, testVal, el) } } @@ -139,11 +139,11 @@ func TestResourceMetricsSlice_RemoveIf(t *testing.T) { } func TestResourceMetrics_MoveTo(t *testing.T) { - ms := ResourceMetrics(internal.GenerateTestResourceMetrics()) + ms := MutableResourceMetrics{internal.GenerateTestResourceMetrics()} dest := NewResourceMetrics() ms.MoveTo(dest) assert.Equal(t, NewResourceMetrics(), ms) - assert.Equal(t, ResourceMetrics(internal.GenerateTestResourceMetrics()), dest) + assert.Equal(t, MutableResourceMetrics(internal.GenerateTestResourceMetrics()), dest) } func TestResourceMetrics_CopyTo(t *testing.T) { @@ -151,7 +151,7 @@ func TestResourceMetrics_CopyTo(t *testing.T) { orig := NewResourceMetrics() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ResourceMetrics(internal.GenerateTestResourceMetrics()) + orig = MutableResourceMetrics(internal.GenerateTestResourceMetrics()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -189,7 +189,7 @@ func TestScopeMetricsSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestScopeMetrics(internal.ScopeMetrics(el)) + internal.FillTestScopeMetrics(internal.MutableScopeMetrics(el)) assert.Equal(t, testVal, el) } } @@ -287,11 +287,11 @@ func TestScopeMetricsSlice_RemoveIf(t *testing.T) { } func TestScopeMetrics_MoveTo(t *testing.T) { - ms := ScopeMetrics(internal.GenerateTestScopeMetrics()) + ms := MutableScopeMetrics{internal.GenerateTestScopeMetrics()} dest := NewScopeMetrics() ms.MoveTo(dest) assert.Equal(t, NewScopeMetrics(), ms) - assert.Equal(t, ScopeMetrics(internal.GenerateTestScopeMetrics()), dest) + assert.Equal(t, MutableScopeMetrics(internal.GenerateTestScopeMetrics()), dest) } func TestScopeMetrics_CopyTo(t *testing.T) { @@ -299,7 +299,7 @@ func TestScopeMetrics_CopyTo(t *testing.T) { orig := NewScopeMetrics() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ScopeMetrics(internal.GenerateTestScopeMetrics()) + orig = MutableScopeMetrics(internal.GenerateTestScopeMetrics()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -337,7 +337,7 @@ func TestMetricSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestMetric(internal.Metric(el)) + internal.FillTestMetric(internal.MutableMetric(el)) assert.Equal(t, testVal, el) } } @@ -435,11 +435,11 @@ func TestMetricSlice_RemoveIf(t *testing.T) { } func TestMetric_MoveTo(t *testing.T) { - ms := Metric(internal.GenerateTestMetric()) + ms := MutableMetric{internal.GenerateTestMetric()} dest := NewMetric() ms.MoveTo(dest) assert.Equal(t, NewMetric(), ms) - assert.Equal(t, Metric(internal.GenerateTestMetric()), dest) + assert.Equal(t, MutableMetric(internal.GenerateTestMetric()), dest) } func TestMetric_CopyTo(t *testing.T) { @@ -447,7 +447,7 @@ func TestMetric_CopyTo(t *testing.T) { orig := NewMetric() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Metric(internal.GenerateTestMetric()) + orig = MutableMetric(internal.GenerateTestMetric()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -554,11 +554,11 @@ func TestMetric_CopyTo_Summary(t *testing.T) { } func TestGauge_MoveTo(t *testing.T) { - ms := Gauge(internal.GenerateTestGauge()) + ms := MutableGauge{internal.GenerateTestGauge()} dest := NewGauge() ms.MoveTo(dest) assert.Equal(t, NewGauge(), ms) - assert.Equal(t, Gauge(internal.GenerateTestGauge()), dest) + assert.Equal(t, MutableGauge(internal.GenerateTestGauge()), dest) } func TestGauge_CopyTo(t *testing.T) { @@ -566,7 +566,7 @@ func TestGauge_CopyTo(t *testing.T) { orig := NewGauge() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Gauge(internal.GenerateTestGauge()) + orig = MutableGauge(internal.GenerateTestGauge()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -579,11 +579,11 @@ func TestGauge_DataPoints(t *testing.T) { } func TestSum_MoveTo(t *testing.T) { - ms := Sum(internal.GenerateTestSum()) + ms := MutableSum{internal.GenerateTestSum()} dest := NewSum() ms.MoveTo(dest) assert.Equal(t, NewSum(), ms) - assert.Equal(t, Sum(internal.GenerateTestSum()), dest) + assert.Equal(t, MutableSum(internal.GenerateTestSum()), dest) } func TestSum_CopyTo(t *testing.T) { @@ -591,7 +591,7 @@ func TestSum_CopyTo(t *testing.T) { orig := NewSum() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Sum(internal.GenerateTestSum()) + orig = MutableSum(internal.GenerateTestSum()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -619,11 +619,11 @@ func TestSum_DataPoints(t *testing.T) { } func TestHistogram_MoveTo(t *testing.T) { - ms := Histogram(internal.GenerateTestHistogram()) + ms := MutableHistogram{internal.GenerateTestHistogram()} dest := NewHistogram() ms.MoveTo(dest) assert.Equal(t, NewHistogram(), ms) - assert.Equal(t, Histogram(internal.GenerateTestHistogram()), dest) + assert.Equal(t, MutableHistogram(internal.GenerateTestHistogram()), dest) } func TestHistogram_CopyTo(t *testing.T) { @@ -631,7 +631,7 @@ func TestHistogram_CopyTo(t *testing.T) { orig := NewHistogram() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Histogram(internal.GenerateTestHistogram()) + orig = MutableHistogram(internal.GenerateTestHistogram()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -652,11 +652,11 @@ func TestHistogram_DataPoints(t *testing.T) { } func TestExponentialHistogram_MoveTo(t *testing.T) { - ms := ExponentialHistogram(internal.GenerateTestExponentialHistogram()) + ms := MutableExponentialHistogram{internal.GenerateTestExponentialHistogram()} dest := NewExponentialHistogram() ms.MoveTo(dest) assert.Equal(t, NewExponentialHistogram(), ms) - assert.Equal(t, ExponentialHistogram(internal.GenerateTestExponentialHistogram()), dest) + assert.Equal(t, MutableExponentialHistogram(internal.GenerateTestExponentialHistogram()), dest) } func TestExponentialHistogram_CopyTo(t *testing.T) { @@ -664,7 +664,7 @@ func TestExponentialHistogram_CopyTo(t *testing.T) { orig := NewExponentialHistogram() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExponentialHistogram(internal.GenerateTestExponentialHistogram()) + orig = MutableExponentialHistogram(internal.GenerateTestExponentialHistogram()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -685,11 +685,11 @@ func TestExponentialHistogram_DataPoints(t *testing.T) { } func TestSummary_MoveTo(t *testing.T) { - ms := Summary(internal.GenerateTestSummary()) + ms := MutableSummary{internal.GenerateTestSummary()} dest := NewSummary() ms.MoveTo(dest) assert.Equal(t, NewSummary(), ms) - assert.Equal(t, Summary(internal.GenerateTestSummary()), dest) + assert.Equal(t, MutableSummary(internal.GenerateTestSummary()), dest) } func TestSummary_CopyTo(t *testing.T) { @@ -697,7 +697,7 @@ func TestSummary_CopyTo(t *testing.T) { orig := NewSummary() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Summary(internal.GenerateTestSummary()) + orig = MutableSummary(internal.GenerateTestSummary()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -722,7 +722,7 @@ func TestNumberDataPointSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestNumberDataPoint(internal.NumberDataPoint(el)) + internal.FillTestNumberDataPoint(internal.MutableNumberDataPoint(el)) assert.Equal(t, testVal, el) } } @@ -820,11 +820,11 @@ func TestNumberDataPointSlice_RemoveIf(t *testing.T) { } func TestNumberDataPoint_MoveTo(t *testing.T) { - ms := NumberDataPoint(internal.GenerateTestNumberDataPoint()) + ms := MutableNumberDataPoint{internal.GenerateTestNumberDataPoint()} dest := NewNumberDataPoint() ms.MoveTo(dest) assert.Equal(t, NewNumberDataPoint(), ms) - assert.Equal(t, NumberDataPoint(internal.GenerateTestNumberDataPoint()), dest) + assert.Equal(t, MutableNumberDataPoint(internal.GenerateTestNumberDataPoint()), dest) } func TestNumberDataPoint_CopyTo(t *testing.T) { @@ -832,7 +832,7 @@ func TestNumberDataPoint_CopyTo(t *testing.T) { orig := NewNumberDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = NumberDataPoint(internal.GenerateTestNumberDataPoint()) + orig = MutableNumberDataPoint(internal.GenerateTestNumberDataPoint()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -909,7 +909,7 @@ func TestHistogramDataPointSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestHistogramDataPoint(internal.HistogramDataPoint(el)) + internal.FillTestHistogramDataPoint(internal.MutableHistogramDataPoint(el)) assert.Equal(t, testVal, el) } } @@ -1007,11 +1007,11 @@ func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { } func TestHistogramDataPoint_MoveTo(t *testing.T) { - ms := HistogramDataPoint(internal.GenerateTestHistogramDataPoint()) + ms := MutableHistogramDataPoint{internal.GenerateTestHistogramDataPoint()} dest := NewHistogramDataPoint() ms.MoveTo(dest) assert.Equal(t, NewHistogramDataPoint(), ms) - assert.Equal(t, HistogramDataPoint(internal.GenerateTestHistogramDataPoint()), dest) + assert.Equal(t, MutableHistogramDataPoint(internal.GenerateTestHistogramDataPoint()), dest) } func TestHistogramDataPoint_CopyTo(t *testing.T) { @@ -1019,7 +1019,7 @@ func TestHistogramDataPoint_CopyTo(t *testing.T) { orig := NewHistogramDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = HistogramDataPoint(internal.GenerateTestHistogramDataPoint()) + orig = MutableHistogramDataPoint(internal.GenerateTestHistogramDataPoint()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1126,7 +1126,7 @@ func TestExponentialHistogramDataPointSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestExponentialHistogramDataPoint(internal.ExponentialHistogramDataPoint(el)) + internal.FillTestExponentialHistogramDataPoint(internal.MutableExponentialHistogramDataPoint(el)) assert.Equal(t, testVal, el) } } @@ -1224,11 +1224,11 @@ func TestExponentialHistogramDataPointSlice_RemoveIf(t *testing.T) { } func TestExponentialHistogramDataPoint_MoveTo(t *testing.T) { - ms := ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()) + ms := MutableExponentialHistogramDataPoint{internal.GenerateTestExponentialHistogramDataPoint()} dest := NewExponentialHistogramDataPoint() ms.MoveTo(dest) assert.Equal(t, NewExponentialHistogramDataPoint(), ms) - assert.Equal(t, ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()), dest) + assert.Equal(t, MutableExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()), dest) } func TestExponentialHistogramDataPoint_CopyTo(t *testing.T) { @@ -1236,7 +1236,7 @@ func TestExponentialHistogramDataPoint_CopyTo(t *testing.T) { orig := NewExponentialHistogramDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()) + orig = MutableExponentialHistogramDataPoint(internal.GenerateTestExponentialHistogramDataPoint()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1343,11 +1343,11 @@ func TestExponentialHistogramDataPoint_Max(t *testing.T) { } func TestExponentialHistogramDataPointBuckets_MoveTo(t *testing.T) { - ms := ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()) + ms := MutableExponentialHistogramDataPointBuckets{internal.GenerateTestExponentialHistogramDataPointBuckets()} dest := NewExponentialHistogramDataPointBuckets() ms.MoveTo(dest) assert.Equal(t, NewExponentialHistogramDataPointBuckets(), ms) - assert.Equal(t, ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()), dest) + assert.Equal(t, MutableExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()), dest) } func TestExponentialHistogramDataPointBuckets_CopyTo(t *testing.T) { @@ -1355,7 +1355,7 @@ func TestExponentialHistogramDataPointBuckets_CopyTo(t *testing.T) { orig := NewExponentialHistogramDataPointBuckets() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()) + orig = MutableExponentialHistogramDataPointBuckets(internal.GenerateTestExponentialHistogramDataPointBuckets()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1387,7 +1387,7 @@ func TestSummaryDataPointSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSummaryDataPoint(internal.SummaryDataPoint(el)) + internal.FillTestSummaryDataPoint(internal.MutableSummaryDataPoint(el)) assert.Equal(t, testVal, el) } } @@ -1485,11 +1485,11 @@ func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { } func TestSummaryDataPoint_MoveTo(t *testing.T) { - ms := SummaryDataPoint(internal.GenerateTestSummaryDataPoint()) + ms := MutableSummaryDataPoint{internal.GenerateTestSummaryDataPoint()} dest := NewSummaryDataPoint() ms.MoveTo(dest) assert.Equal(t, NewSummaryDataPoint(), ms) - assert.Equal(t, SummaryDataPoint(internal.GenerateTestSummaryDataPoint()), dest) + assert.Equal(t, MutableSummaryDataPoint(internal.GenerateTestSummaryDataPoint()), dest) } func TestSummaryDataPoint_CopyTo(t *testing.T) { @@ -1497,7 +1497,7 @@ func TestSummaryDataPoint_CopyTo(t *testing.T) { orig := NewSummaryDataPoint() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SummaryDataPoint(internal.GenerateTestSummaryDataPoint()) + orig = MutableSummaryDataPoint(internal.GenerateTestSummaryDataPoint()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1567,7 +1567,7 @@ func TestSummaryDataPointValueAtQuantileSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSummaryDataPointValueAtQuantile(internal.SummaryDataPointValueAtQuantile(el)) + internal.FillTestSummaryDataPointValueAtQuantile(internal.MutableSummaryDataPointValueAtQuantile(el)) assert.Equal(t, testVal, el) } } @@ -1665,11 +1665,11 @@ func TestSummaryDataPointValueAtQuantileSlice_RemoveIf(t *testing.T) { } func TestSummaryDataPointValueAtQuantile_MoveTo(t *testing.T) { - ms := SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()) + ms := MutableSummaryDataPointValueAtQuantile{internal.GenerateTestSummaryDataPointValueAtQuantile()} dest := NewSummaryDataPointValueAtQuantile() ms.MoveTo(dest) assert.Equal(t, NewSummaryDataPointValueAtQuantile(), ms) - assert.Equal(t, SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()), dest) + assert.Equal(t, MutableSummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()), dest) } func TestSummaryDataPointValueAtQuantile_CopyTo(t *testing.T) { @@ -1677,7 +1677,7 @@ func TestSummaryDataPointValueAtQuantile_CopyTo(t *testing.T) { orig := NewSummaryDataPointValueAtQuantile() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()) + orig = MutableSummaryDataPointValueAtQuantile(internal.GenerateTestSummaryDataPointValueAtQuantile()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -1709,7 +1709,7 @@ func TestExemplarSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestExemplar(internal.Exemplar(el)) + internal.FillTestExemplar(internal.MutableExemplar(el)) assert.Equal(t, testVal, el) } } @@ -1798,11 +1798,11 @@ func TestExemplarSlice_RemoveIf(t *testing.T) { } func TestExemplar_MoveTo(t *testing.T) { - ms := Exemplar(internal.GenerateTestExemplar()) + ms := MutableExemplar{internal.GenerateTestExemplar()} dest := NewExemplar() ms.MoveTo(dest) assert.Equal(t, NewExemplar(), ms) - assert.Equal(t, Exemplar(internal.GenerateTestExemplar()), dest) + assert.Equal(t, MutableExemplar(internal.GenerateTestExemplar()), dest) } func TestExemplar_CopyTo(t *testing.T) { @@ -1810,7 +1810,7 @@ func TestExemplar_CopyTo(t *testing.T) { orig := NewExemplar() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Exemplar(internal.GenerateTestExemplar()) + orig = MutableExemplar(internal.GenerateTestExemplar()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } diff --git a/pdata/pmetric/metrics.go b/pdata/pmetric/metrics.go index f1739630f69..133a0fc4d47 100644 --- a/pdata/pmetric/metrics.go +++ b/pdata/pmetric/metrics.go @@ -39,7 +39,7 @@ func NewMetrics() Metrics { // CopyTo copies the Metrics instance overriding the destination. func (ms Metrics) CopyTo(dest Metrics) { - ms.ResourceMetrics().CopyTo(dest.ResourceMetrics()) + ms.ResourceMetrics().CopyTo(dest.MutableResourceMetrics()) } // MoveTo moves the Metrics instance overriding the destination and @@ -54,6 +54,18 @@ func (ms Metrics) ResourceMetrics() ResourceMetricsSlice { return newResourceMetricsSlice(&ms.getOrig().ResourceMetrics) } +// MutableResourceMetrics returns the MutableResourceMetricsSlice associated with this Metrics object. +// This method should be called at once per ConsumeMetrics call if the slice has to be changed, +// otherwise use ResourceMetrics method. +func (ms Metrics) MutableResourceMetrics() MutableResourceMetricsSlice { + if ms.state == pcommon.StateShared { + rms := NewResourceMetricsSlice() + newResourceMetricsSlice(&ms.getOrig().ResourceMetrics).CopyTo(rms) + return rms + } + return newMutableResourceMetricsSlice(&ms.getOrig().ResourceMetrics) +} + // MetricCount calculates the total number of metrics. func (ms Metrics) MetricCount() int { metricCount := 0 diff --git a/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go b/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go index d16203f4e47..88630abb12e 100644 --- a/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go +++ b/pdata/pmetric/pmetricotlp/generated_metrics_otlp.go @@ -32,25 +32,35 @@ import ( type ExportPartialSuccess internal.MetricsExportPartialSuccess +type MutableExportPartialSuccess internal.MutableMetricsExportPartialSuccess + func newExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) ExportPartialSuccess { return ExportPartialSuccess(internal.NewMetricsExportPartialSuccess(orig)) } +func newMutableExportPartialSuccess(orig *otlpcollectormetrics.ExportMetricsPartialSuccess) MutableExportPartialSuccess { + return MutableExportPartialSuccess(internal.NewMetricsExportPartialSuccess(orig)) +} + func (ms ExportPartialSuccess) getOrig() *otlpcollectormetrics.ExportMetricsPartialSuccess { return internal.GetOrigMetricsExportPartialSuccess(internal.MetricsExportPartialSuccess(ms)) } +func (ms MutableExportPartialSuccess) getOrig() *otlpcollectormetrics.ExportMetricsPartialSuccess { + return internal.GetMutableOrigMetricsExportPartialSuccess(internal.MutableMetricsExportPartialSuccess(ms)) +} + // NewExportPartialSuccess creates a new empty ExportPartialSuccess. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExportPartialSuccess() ExportPartialSuccess { - return newExportPartialSuccess(&otlpcollectormetrics.ExportMetricsPartialSuccess{}) +func NewExportPartialSuccess() MutableExportPartialSuccess { + return newMutableExportPartialSuccess(&otlpcollectormetrics.ExportMetricsPartialSuccess{}) } // 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) { +func (ms MutableExportPartialSuccess) MoveTo(dest MutableExportPartialSuccess) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpcollectormetrics.ExportMetricsPartialSuccess{} } @@ -60,8 +70,13 @@ func (ms ExportPartialSuccess) RejectedDataPoints() int64 { return ms.getOrig().RejectedDataPoints } +// MutableRejectedDataPoints returns the rejecteddatapoints associated with this ExportPartialSuccess. +func (ms MutableExportPartialSuccess) RejectedDataPoints() int64 { + return ms.getOrig().RejectedDataPoints +} + // SetRejectedDataPoints replaces the rejecteddatapoints associated with this ExportPartialSuccess. -func (ms ExportPartialSuccess) SetRejectedDataPoints(v int64) { +func (ms MutableExportPartialSuccess) SetRejectedDataPoints(v int64) { ms.getOrig().RejectedDataPoints = v } @@ -70,13 +85,23 @@ func (ms ExportPartialSuccess) ErrorMessage() string { return ms.getOrig().ErrorMessage } +// MutableErrorMessage returns the errormessage associated with this ExportPartialSuccess. +func (ms MutableExportPartialSuccess) ErrorMessage() string { + return ms.getOrig().ErrorMessage +} + // SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. -func (ms ExportPartialSuccess) SetErrorMessage(v string) { +func (ms MutableExportPartialSuccess) SetErrorMessage(v string) { ms.getOrig().ErrorMessage = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms ExportPartialSuccess) CopyTo(dest ExportPartialSuccess) { +func (ms ExportPartialSuccess) CopyTo(dest MutableExportPartialSuccess) { dest.SetRejectedDataPoints(ms.RejectedDataPoints()) dest.SetErrorMessage(ms.ErrorMessage()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExportPartialSuccess) CopyTo(dest MutableExportPartialSuccess) { + newExportPartialSuccess(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go b/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go index 8a9742c0194..e1514035390 100644 --- a/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go +++ b/pdata/pmetric/pmetricotlp/generated_metrics_otlp_test.go @@ -26,11 +26,11 @@ import ( ) func TestExportPartialSuccess_MoveTo(t *testing.T) { - ms := ExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()) + ms := MutableExportPartialSuccess{internal.GenerateTestMetricsExportPartialSuccess()} dest := NewExportPartialSuccess() ms.MoveTo(dest) assert.Equal(t, NewExportPartialSuccess(), ms) - assert.Equal(t, ExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()), dest) + assert.Equal(t, MutableExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()), dest) } func TestExportPartialSuccess_CopyTo(t *testing.T) { @@ -38,7 +38,7 @@ func TestExportPartialSuccess_CopyTo(t *testing.T) { orig := NewExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()) + orig = MutableExportPartialSuccess(internal.GenerateTestMetricsExportPartialSuccess()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } diff --git a/pdata/ptrace/generated_traces.go b/pdata/ptrace/generated_traces.go index b84d11404b6..bcff9ce4293 100644 --- a/pdata/ptrace/generated_traces.go +++ b/pdata/ptrace/generated_traces.go @@ -35,19 +35,29 @@ import ( // Important: zero-initialized instance is not valid for use. type ResourceSpansSlice internal.ResourceSpansSlice +type MutableResourceSpansSlice internal.MutableResourceSpansSlice + func newResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) ResourceSpansSlice { return ResourceSpansSlice(internal.NewResourceSpansSlice(orig)) } +func newMutableResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) MutableResourceSpansSlice { + return MutableResourceSpansSlice(internal.NewResourceSpansSlice(orig)) +} + func (ms ResourceSpansSlice) getOrig() *[]*otlptrace.ResourceSpans { return internal.GetOrigResourceSpansSlice(internal.ResourceSpansSlice(ms)) } +func (ms MutableResourceSpansSlice) getOrig() *[]*otlptrace.ResourceSpans { + return internal.GetMutableOrigResourceSpansSlice(internal.MutableResourceSpansSlice(ms)) +} + // NewResourceSpansSlice creates a ResourceSpansSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewResourceSpansSlice() ResourceSpansSlice { +func NewResourceSpansSlice() MutableResourceSpansSlice { orig := []*otlptrace.ResourceSpans(nil) - return newResourceSpansSlice(&orig) + return newMutableResourceSpansSlice(&orig) } // Len returns the number of elements in the slice. @@ -57,6 +67,10 @@ func (es ResourceSpansSlice) Len() int { return len(*es.getOrig()) } +func (es MutableResourceSpansSlice) 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: @@ -69,14 +83,18 @@ func (es ResourceSpansSlice) At(ix int) ResourceSpans { return newResourceSpans((*es.getOrig())[ix]) } +func (es MutableResourceSpansSlice) At(ix int) MutableResourceSpans { + return newMutableResourceSpans((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { +func (es ResourceSpansSlice) CopyTo(dest MutableResourceSpansSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newResourceSpans((*es.getOrig())[i]).CopyTo(newResourceSpans((*dest.getOrig())[i])) + newResourceSpans((*es.getOrig())[i]).CopyTo(newMutableResourceSpans((*dest.getOrig())[i])) } return } @@ -84,11 +102,16 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { wrappers := make([]*otlptrace.ResourceSpans, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newResourceSpans((*es.getOrig())[i]).CopyTo(newResourceSpans(wrappers[i])) + newResourceSpans((*es.getOrig())[i]).CopyTo(newMutableResourceSpans(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableResourceSpansSlice) CopyTo(dest MutableResourceSpansSlice) { + newResourceSpansSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -101,7 +124,7 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ResourceSpansSlice) EnsureCapacity(newCap int) { +func (es MutableResourceSpansSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -114,7 +137,7 @@ func (es ResourceSpansSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ResourceSpans. // It returns the newly added ResourceSpans. -func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { +func (es MutableResourceSpansSlice) AppendEmpty() MutableResourceSpans { *es.getOrig() = append(*es.getOrig(), &otlptrace.ResourceSpans{}) return es.At(es.Len() - 1) } @@ -122,13 +145,13 @@ func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { // Sort sorts the ResourceSpans elements within ResourceSpansSlice given the // provided less function so that two instances of ResourceSpansSlice // can be compared. -func (es ResourceSpansSlice) Sort(less func(a, b ResourceSpans) bool) { +func (es MutableResourceSpansSlice) Sort(less func(a, b MutableResourceSpans) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableResourceSpansSlice) MoveAndAppendTo(dest MutableResourceSpansSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -140,7 +163,7 @@ func (es ResourceSpansSlice) MoveAndAppendTo(dest ResourceSpansSlice) { // 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) { +func (es MutableResourceSpansSlice) RemoveIf(f func(MutableResourceSpans) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -168,25 +191,35 @@ func (es ResourceSpansSlice) RemoveIf(f func(ResourceSpans) bool) { type ResourceSpans internal.ResourceSpans +type MutableResourceSpans internal.MutableResourceSpans + func newResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans { return ResourceSpans(internal.NewResourceSpans(orig)) } +func newMutableResourceSpans(orig *otlptrace.ResourceSpans) MutableResourceSpans { + return MutableResourceSpans(internal.NewResourceSpans(orig)) +} + func (ms ResourceSpans) getOrig() *otlptrace.ResourceSpans { return internal.GetOrigResourceSpans(internal.ResourceSpans(ms)) } +func (ms MutableResourceSpans) getOrig() *otlptrace.ResourceSpans { + return internal.GetMutableOrigResourceSpans(internal.MutableResourceSpans(ms)) +} + // NewResourceSpans creates a new empty ResourceSpans. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewResourceSpans() ResourceSpans { - return newResourceSpans(&otlptrace.ResourceSpans{}) +func NewResourceSpans() MutableResourceSpans { + return newMutableResourceSpans(&otlptrace.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) { +func (ms MutableResourceSpans) MoveTo(dest MutableResourceSpans) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.ResourceSpans{} } @@ -196,13 +229,23 @@ func (ms ResourceSpans) Resource() pcommon.Resource { return pcommon.Resource(internal.NewResource(&ms.getOrig().Resource)) } +// Resource returns the resource associated with this ResourceSpans. +func (ms MutableResourceSpans) Resource() pcommon.MutableResource { + return pcommon.MutableResource(internal.NewMutableResource(&ms.getOrig().Resource)) +} + // SchemaUrl returns the schemaurl associated with this ResourceSpans. func (ms ResourceSpans) SchemaUrl() string { return ms.getOrig().SchemaUrl } +// MutableSchemaUrl returns the schemaurl associated with this ResourceSpans. +func (ms MutableResourceSpans) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + // SetSchemaUrl replaces the schemaurl associated with this ResourceSpans. -func (ms ResourceSpans) SetSchemaUrl(v string) { +func (ms MutableResourceSpans) SetSchemaUrl(v string) { ms.getOrig().SchemaUrl = v } @@ -211,13 +254,23 @@ func (ms ResourceSpans) ScopeSpans() ScopeSpansSlice { return ScopeSpansSlice(internal.NewScopeSpansSlice(&ms.getOrig().ScopeSpans)) } +// ScopeSpans returns the ScopeSpans associated with this ResourceSpans. +func (ms MutableResourceSpans) ScopeSpans() MutableScopeSpansSlice { + return MutableScopeSpansSlice(internal.NewMutableScopeSpansSlice(&ms.getOrig().ScopeSpans)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ResourceSpans) CopyTo(dest ResourceSpans) { +func (ms ResourceSpans) CopyTo(dest MutableResourceSpans) { ms.Resource().CopyTo(dest.Resource()) dest.SetSchemaUrl(ms.SchemaUrl()) ms.ScopeSpans().CopyTo(dest.ScopeSpans()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableResourceSpans) CopyTo(dest MutableResourceSpans) { + newResourceSpans(ms.getOrig()).CopyTo(dest) +} + // ScopeSpansSlice logically represents a slice of ScopeSpans. // // This is a reference type. If passed by value and callee modifies it, the @@ -227,19 +280,29 @@ func (ms ResourceSpans) CopyTo(dest ResourceSpans) { // Important: zero-initialized instance is not valid for use. type ScopeSpansSlice internal.ScopeSpansSlice +type MutableScopeSpansSlice internal.MutableScopeSpansSlice + func newScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) ScopeSpansSlice { return ScopeSpansSlice(internal.NewScopeSpansSlice(orig)) } +func newMutableScopeSpansSlice(orig *[]*otlptrace.ScopeSpans) MutableScopeSpansSlice { + return MutableScopeSpansSlice(internal.NewScopeSpansSlice(orig)) +} + func (ms ScopeSpansSlice) getOrig() *[]*otlptrace.ScopeSpans { return internal.GetOrigScopeSpansSlice(internal.ScopeSpansSlice(ms)) } +func (ms MutableScopeSpansSlice) getOrig() *[]*otlptrace.ScopeSpans { + return internal.GetMutableOrigScopeSpansSlice(internal.MutableScopeSpansSlice(ms)) +} + // NewScopeSpansSlice creates a ScopeSpansSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewScopeSpansSlice() ScopeSpansSlice { +func NewScopeSpansSlice() MutableScopeSpansSlice { orig := []*otlptrace.ScopeSpans(nil) - return newScopeSpansSlice(&orig) + return newMutableScopeSpansSlice(&orig) } // Len returns the number of elements in the slice. @@ -249,6 +312,10 @@ func (es ScopeSpansSlice) Len() int { return len(*es.getOrig()) } +func (es MutableScopeSpansSlice) 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: @@ -261,14 +328,18 @@ func (es ScopeSpansSlice) At(ix int) ScopeSpans { return newScopeSpans((*es.getOrig())[ix]) } +func (es MutableScopeSpansSlice) At(ix int) MutableScopeSpans { + return newMutableScopeSpans((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { +func (es ScopeSpansSlice) CopyTo(dest MutableScopeSpansSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newScopeSpans((*es.getOrig())[i]).CopyTo(newScopeSpans((*dest.getOrig())[i])) + newScopeSpans((*es.getOrig())[i]).CopyTo(newMutableScopeSpans((*dest.getOrig())[i])) } return } @@ -276,11 +347,16 @@ func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { wrappers := make([]*otlptrace.ScopeSpans, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newScopeSpans((*es.getOrig())[i]).CopyTo(newScopeSpans(wrappers[i])) + newScopeSpans((*es.getOrig())[i]).CopyTo(newMutableScopeSpans(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableScopeSpansSlice) CopyTo(dest MutableScopeSpansSlice) { + newScopeSpansSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -293,7 +369,7 @@ func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es ScopeSpansSlice) EnsureCapacity(newCap int) { +func (es MutableScopeSpansSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -306,7 +382,7 @@ func (es ScopeSpansSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty ScopeSpans. // It returns the newly added ScopeSpans. -func (es ScopeSpansSlice) AppendEmpty() ScopeSpans { +func (es MutableScopeSpansSlice) AppendEmpty() MutableScopeSpans { *es.getOrig() = append(*es.getOrig(), &otlptrace.ScopeSpans{}) return es.At(es.Len() - 1) } @@ -314,13 +390,13 @@ func (es ScopeSpansSlice) AppendEmpty() ScopeSpans { // Sort sorts the ScopeSpans elements within ScopeSpansSlice given the // provided less function so that two instances of ScopeSpansSlice // can be compared. -func (es ScopeSpansSlice) Sort(less func(a, b ScopeSpans) bool) { +func (es MutableScopeSpansSlice) Sort(less func(a, b MutableScopeSpans) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableScopeSpansSlice) MoveAndAppendTo(dest MutableScopeSpansSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -332,7 +408,7 @@ func (es ScopeSpansSlice) MoveAndAppendTo(dest ScopeSpansSlice) { // 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) { +func (es MutableScopeSpansSlice) RemoveIf(f func(MutableScopeSpans) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -360,25 +436,35 @@ func (es ScopeSpansSlice) RemoveIf(f func(ScopeSpans) bool) { type ScopeSpans internal.ScopeSpans +type MutableScopeSpans internal.MutableScopeSpans + func newScopeSpans(orig *otlptrace.ScopeSpans) ScopeSpans { return ScopeSpans(internal.NewScopeSpans(orig)) } +func newMutableScopeSpans(orig *otlptrace.ScopeSpans) MutableScopeSpans { + return MutableScopeSpans(internal.NewScopeSpans(orig)) +} + func (ms ScopeSpans) getOrig() *otlptrace.ScopeSpans { return internal.GetOrigScopeSpans(internal.ScopeSpans(ms)) } +func (ms MutableScopeSpans) getOrig() *otlptrace.ScopeSpans { + return internal.GetMutableOrigScopeSpans(internal.MutableScopeSpans(ms)) +} + // NewScopeSpans creates a new empty ScopeSpans. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewScopeSpans() ScopeSpans { - return newScopeSpans(&otlptrace.ScopeSpans{}) +func NewScopeSpans() MutableScopeSpans { + return newMutableScopeSpans(&otlptrace.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) { +func (ms MutableScopeSpans) MoveTo(dest MutableScopeSpans) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.ScopeSpans{} } @@ -388,13 +474,23 @@ func (ms ScopeSpans) Scope() pcommon.InstrumentationScope { return pcommon.InstrumentationScope(internal.NewInstrumentationScope(&ms.getOrig().Scope)) } +// Scope returns the scope associated with this ScopeSpans. +func (ms MutableScopeSpans) Scope() pcommon.MutableInstrumentationScope { + return pcommon.MutableInstrumentationScope(internal.NewMutableInstrumentationScope(&ms.getOrig().Scope)) +} + // SchemaUrl returns the schemaurl associated with this ScopeSpans. func (ms ScopeSpans) SchemaUrl() string { return ms.getOrig().SchemaUrl } +// MutableSchemaUrl returns the schemaurl associated with this ScopeSpans. +func (ms MutableScopeSpans) SchemaUrl() string { + return ms.getOrig().SchemaUrl +} + // SetSchemaUrl replaces the schemaurl associated with this ScopeSpans. -func (ms ScopeSpans) SetSchemaUrl(v string) { +func (ms MutableScopeSpans) SetSchemaUrl(v string) { ms.getOrig().SchemaUrl = v } @@ -403,13 +499,23 @@ func (ms ScopeSpans) Spans() SpanSlice { return SpanSlice(internal.NewSpanSlice(&ms.getOrig().Spans)) } +// Spans returns the Spans associated with this ScopeSpans. +func (ms MutableScopeSpans) Spans() MutableSpanSlice { + return MutableSpanSlice(internal.NewMutableSpanSlice(&ms.getOrig().Spans)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms ScopeSpans) CopyTo(dest ScopeSpans) { +func (ms ScopeSpans) CopyTo(dest MutableScopeSpans) { ms.Scope().CopyTo(dest.Scope()) dest.SetSchemaUrl(ms.SchemaUrl()) ms.Spans().CopyTo(dest.Spans()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableScopeSpans) CopyTo(dest MutableScopeSpans) { + newScopeSpans(ms.getOrig()).CopyTo(dest) +} + // SpanSlice logically represents a slice of Span. // // This is a reference type. If passed by value and callee modifies it, the @@ -419,19 +525,29 @@ func (ms ScopeSpans) CopyTo(dest ScopeSpans) { // Important: zero-initialized instance is not valid for use. type SpanSlice internal.SpanSlice +type MutableSpanSlice internal.MutableSpanSlice + func newSpanSlice(orig *[]*otlptrace.Span) SpanSlice { return SpanSlice(internal.NewSpanSlice(orig)) } +func newMutableSpanSlice(orig *[]*otlptrace.Span) MutableSpanSlice { + return MutableSpanSlice(internal.NewSpanSlice(orig)) +} + func (ms SpanSlice) getOrig() *[]*otlptrace.Span { return internal.GetOrigSpanSlice(internal.SpanSlice(ms)) } +func (ms MutableSpanSlice) getOrig() *[]*otlptrace.Span { + return internal.GetMutableOrigSpanSlice(internal.MutableSpanSlice(ms)) +} + // NewSpanSlice creates a SpanSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewSpanSlice() SpanSlice { +func NewSpanSlice() MutableSpanSlice { orig := []*otlptrace.Span(nil) - return newSpanSlice(&orig) + return newMutableSpanSlice(&orig) } // Len returns the number of elements in the slice. @@ -441,6 +557,10 @@ func (es SpanSlice) Len() int { return len(*es.getOrig()) } +func (es MutableSpanSlice) 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: @@ -453,14 +573,18 @@ func (es SpanSlice) At(ix int) Span { return newSpan((*es.getOrig())[ix]) } +func (es MutableSpanSlice) At(ix int) MutableSpan { + return newMutableSpan((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es SpanSlice) CopyTo(dest SpanSlice) { +func (es SpanSlice) CopyTo(dest MutableSpanSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newSpan((*es.getOrig())[i]).CopyTo(newSpan((*dest.getOrig())[i])) + newSpan((*es.getOrig())[i]).CopyTo(newMutableSpan((*dest.getOrig())[i])) } return } @@ -468,11 +592,16 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { wrappers := make([]*otlptrace.Span, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newSpan((*es.getOrig())[i]).CopyTo(newSpan(wrappers[i])) + newSpan((*es.getOrig())[i]).CopyTo(newMutableSpan(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableSpanSlice) CopyTo(dest MutableSpanSlice) { + newSpanSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -485,7 +614,7 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es SpanSlice) EnsureCapacity(newCap int) { +func (es MutableSpanSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -498,7 +627,7 @@ func (es SpanSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty Span. // It returns the newly added Span. -func (es SpanSlice) AppendEmpty() Span { +func (es MutableSpanSlice) AppendEmpty() MutableSpan { *es.getOrig() = append(*es.getOrig(), &otlptrace.Span{}) return es.At(es.Len() - 1) } @@ -506,13 +635,13 @@ func (es SpanSlice) AppendEmpty() Span { // Sort sorts the Span elements within SpanSlice given the // provided less function so that two instances of SpanSlice // can be compared. -func (es SpanSlice) Sort(less func(a, b Span) bool) { +func (es MutableSpanSlice) Sort(less func(a, b MutableSpan) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableSpanSlice) MoveAndAppendTo(dest MutableSpanSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -524,7 +653,7 @@ func (es SpanSlice) MoveAndAppendTo(dest SpanSlice) { // 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) { +func (es MutableSpanSlice) RemoveIf(f func(MutableSpan) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -553,25 +682,35 @@ func (es SpanSlice) RemoveIf(f func(Span) bool) { type Span internal.Span +type MutableSpan internal.MutableSpan + func newSpan(orig *otlptrace.Span) Span { return Span(internal.NewSpan(orig)) } +func newMutableSpan(orig *otlptrace.Span) MutableSpan { + return MutableSpan(internal.NewSpan(orig)) +} + func (ms Span) getOrig() *otlptrace.Span { return internal.GetOrigSpan(internal.Span(ms)) } +func (ms MutableSpan) getOrig() *otlptrace.Span { + return internal.GetMutableOrigSpan(internal.MutableSpan(ms)) +} + // NewSpan creates a new empty Span. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSpan() Span { - return newSpan(&otlptrace.Span{}) +func NewSpan() MutableSpan { + return newMutableSpan(&otlptrace.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) { +func (ms MutableSpan) MoveTo(dest MutableSpan) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.Span{} } @@ -581,8 +720,13 @@ func (ms Span) TraceID() pcommon.TraceID { return pcommon.TraceID(ms.getOrig().TraceId) } +// TraceID returns the traceid associated with this Span. +func (ms MutableSpan) TraceID() pcommon.TraceID { + return pcommon.TraceID(ms.getOrig().TraceId) +} + // SetTraceID replaces the traceid associated with this Span. -func (ms Span) SetTraceID(v pcommon.TraceID) { +func (ms MutableSpan) SetTraceID(v pcommon.TraceID) { ms.getOrig().TraceId = data.TraceID(v) } @@ -591,8 +735,13 @@ func (ms Span) SpanID() pcommon.SpanID { return pcommon.SpanID(ms.getOrig().SpanId) } +// SpanID returns the spanid associated with this Span. +func (ms MutableSpan) SpanID() pcommon.SpanID { + return pcommon.SpanID(ms.getOrig().SpanId) +} + // SetSpanID replaces the spanid associated with this Span. -func (ms Span) SetSpanID(v pcommon.SpanID) { +func (ms MutableSpan) SetSpanID(v pcommon.SpanID) { ms.getOrig().SpanId = data.SpanID(v) } @@ -601,13 +750,23 @@ func (ms Span) TraceState() pcommon.TraceState { return pcommon.TraceState(internal.NewTraceState(&ms.getOrig().TraceState)) } +// TraceState returns the tracestate associated with this Span. +func (ms MutableSpan) TraceState() pcommon.MutableTraceState { + return pcommon.MutableTraceState(internal.NewMutableTraceState(&ms.getOrig().TraceState)) +} + // ParentSpanID returns the parentspanid associated with this Span. func (ms Span) ParentSpanID() pcommon.SpanID { return pcommon.SpanID(ms.getOrig().ParentSpanId) } +// ParentSpanID returns the parentspanid associated with this Span. +func (ms MutableSpan) ParentSpanID() pcommon.SpanID { + return pcommon.SpanID(ms.getOrig().ParentSpanId) +} + // SetParentSpanID replaces the parentspanid associated with this Span. -func (ms Span) SetParentSpanID(v pcommon.SpanID) { +func (ms MutableSpan) SetParentSpanID(v pcommon.SpanID) { ms.getOrig().ParentSpanId = data.SpanID(v) } @@ -616,8 +775,13 @@ func (ms Span) Name() string { return ms.getOrig().Name } +// MutableName returns the name associated with this Span. +func (ms MutableSpan) Name() string { + return ms.getOrig().Name +} + // SetName replaces the name associated with this Span. -func (ms Span) SetName(v string) { +func (ms MutableSpan) SetName(v string) { ms.getOrig().Name = v } @@ -626,8 +790,13 @@ func (ms Span) Kind() SpanKind { return SpanKind(ms.getOrig().Kind) } +// Kind returns the kind associated with this Span. +func (ms MutableSpan) Kind() SpanKind { + return SpanKind(ms.getOrig().Kind) +} + // SetKind replaces the kind associated with this Span. -func (ms Span) SetKind(v SpanKind) { +func (ms MutableSpan) SetKind(v SpanKind) { ms.getOrig().Kind = otlptrace.Span_SpanKind(v) } @@ -636,8 +805,13 @@ func (ms Span) StartTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) } +// StartTimestamp returns the starttimestamp associated with this Span. +func (ms MutableSpan) StartTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().StartTimeUnixNano) +} + // SetStartTimestamp replaces the starttimestamp associated with this Span. -func (ms Span) SetStartTimestamp(v pcommon.Timestamp) { +func (ms MutableSpan) SetStartTimestamp(v pcommon.Timestamp) { ms.getOrig().StartTimeUnixNano = uint64(v) } @@ -646,8 +820,13 @@ func (ms Span) EndTimestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().EndTimeUnixNano) } +// EndTimestamp returns the endtimestamp associated with this Span. +func (ms MutableSpan) EndTimestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().EndTimeUnixNano) +} + // SetEndTimestamp replaces the endtimestamp associated with this Span. -func (ms Span) SetEndTimestamp(v pcommon.Timestamp) { +func (ms MutableSpan) SetEndTimestamp(v pcommon.Timestamp) { ms.getOrig().EndTimeUnixNano = uint64(v) } @@ -656,13 +835,23 @@ func (ms Span) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this Span. +func (ms MutableSpan) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // DroppedAttributesCount returns the droppedattributescount associated with this Span. func (ms Span) DroppedAttributesCount() uint32 { return ms.getOrig().DroppedAttributesCount } +// MutableDroppedAttributesCount returns the droppedattributescount associated with this Span. +func (ms MutableSpan) DroppedAttributesCount() uint32 { + return ms.getOrig().DroppedAttributesCount +} + // SetDroppedAttributesCount replaces the droppedattributescount associated with this Span. -func (ms Span) SetDroppedAttributesCount(v uint32) { +func (ms MutableSpan) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } @@ -671,13 +860,23 @@ func (ms Span) Events() SpanEventSlice { return SpanEventSlice(internal.NewSpanEventSlice(&ms.getOrig().Events)) } +// Events returns the Events associated with this Span. +func (ms MutableSpan) Events() MutableSpanEventSlice { + return MutableSpanEventSlice(internal.NewMutableSpanEventSlice(&ms.getOrig().Events)) +} + // DroppedEventsCount returns the droppedeventscount associated with this Span. func (ms Span) DroppedEventsCount() uint32 { return ms.getOrig().DroppedEventsCount } +// MutableDroppedEventsCount returns the droppedeventscount associated with this Span. +func (ms MutableSpan) DroppedEventsCount() uint32 { + return ms.getOrig().DroppedEventsCount +} + // SetDroppedEventsCount replaces the droppedeventscount associated with this Span. -func (ms Span) SetDroppedEventsCount(v uint32) { +func (ms MutableSpan) SetDroppedEventsCount(v uint32) { ms.getOrig().DroppedEventsCount = v } @@ -686,13 +885,23 @@ func (ms Span) Links() SpanLinkSlice { return SpanLinkSlice(internal.NewSpanLinkSlice(&ms.getOrig().Links)) } +// Links returns the Links associated with this Span. +func (ms MutableSpan) Links() MutableSpanLinkSlice { + return MutableSpanLinkSlice(internal.NewMutableSpanLinkSlice(&ms.getOrig().Links)) +} + // DroppedLinksCount returns the droppedlinkscount associated with this Span. func (ms Span) DroppedLinksCount() uint32 { return ms.getOrig().DroppedLinksCount } +// MutableDroppedLinksCount returns the droppedlinkscount associated with this Span. +func (ms MutableSpan) DroppedLinksCount() uint32 { + return ms.getOrig().DroppedLinksCount +} + // SetDroppedLinksCount replaces the droppedlinkscount associated with this Span. -func (ms Span) SetDroppedLinksCount(v uint32) { +func (ms MutableSpan) SetDroppedLinksCount(v uint32) { ms.getOrig().DroppedLinksCount = v } @@ -701,8 +910,13 @@ func (ms Span) Status() Status { return Status(internal.NewStatus(&ms.getOrig().Status)) } +// Status returns the status associated with this Span. +func (ms MutableSpan) Status() MutableStatus { + return MutableStatus(internal.NewMutableStatus(&ms.getOrig().Status)) +} + // CopyTo copies all properties from the current struct overriding the destination. -func (ms Span) CopyTo(dest Span) { +func (ms Span) CopyTo(dest MutableSpan) { dest.SetTraceID(ms.TraceID()) dest.SetSpanID(ms.SpanID()) ms.TraceState().CopyTo(dest.TraceState()) @@ -720,6 +934,11 @@ func (ms Span) CopyTo(dest Span) { ms.Status().CopyTo(dest.Status()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSpan) CopyTo(dest MutableSpan) { + newSpan(ms.getOrig()).CopyTo(dest) +} + // SpanEventSlice logically represents a slice of SpanEvent. // // This is a reference type. If passed by value and callee modifies it, the @@ -729,19 +948,29 @@ func (ms Span) CopyTo(dest Span) { // Important: zero-initialized instance is not valid for use. type SpanEventSlice internal.SpanEventSlice +type MutableSpanEventSlice internal.MutableSpanEventSlice + func newSpanEventSlice(orig *[]*otlptrace.Span_Event) SpanEventSlice { return SpanEventSlice(internal.NewSpanEventSlice(orig)) } +func newMutableSpanEventSlice(orig *[]*otlptrace.Span_Event) MutableSpanEventSlice { + return MutableSpanEventSlice(internal.NewSpanEventSlice(orig)) +} + func (ms SpanEventSlice) getOrig() *[]*otlptrace.Span_Event { return internal.GetOrigSpanEventSlice(internal.SpanEventSlice(ms)) } +func (ms MutableSpanEventSlice) getOrig() *[]*otlptrace.Span_Event { + return internal.GetMutableOrigSpanEventSlice(internal.MutableSpanEventSlice(ms)) +} + // NewSpanEventSlice creates a SpanEventSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewSpanEventSlice() SpanEventSlice { +func NewSpanEventSlice() MutableSpanEventSlice { orig := []*otlptrace.Span_Event(nil) - return newSpanEventSlice(&orig) + return newMutableSpanEventSlice(&orig) } // Len returns the number of elements in the slice. @@ -751,6 +980,10 @@ func (es SpanEventSlice) Len() int { return len(*es.getOrig()) } +func (es MutableSpanEventSlice) 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: @@ -763,14 +996,18 @@ func (es SpanEventSlice) At(ix int) SpanEvent { return newSpanEvent((*es.getOrig())[ix]) } +func (es MutableSpanEventSlice) At(ix int) MutableSpanEvent { + return newMutableSpanEvent((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { +func (es SpanEventSlice) CopyTo(dest MutableSpanEventSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newSpanEvent((*es.getOrig())[i]).CopyTo(newSpanEvent((*dest.getOrig())[i])) + newSpanEvent((*es.getOrig())[i]).CopyTo(newMutableSpanEvent((*dest.getOrig())[i])) } return } @@ -778,11 +1015,16 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { wrappers := make([]*otlptrace.Span_Event, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newSpanEvent((*es.getOrig())[i]).CopyTo(newSpanEvent(wrappers[i])) + newSpanEvent((*es.getOrig())[i]).CopyTo(newMutableSpanEvent(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableSpanEventSlice) CopyTo(dest MutableSpanEventSlice) { + newSpanEventSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -795,7 +1037,7 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es SpanEventSlice) EnsureCapacity(newCap int) { +func (es MutableSpanEventSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -808,7 +1050,7 @@ func (es SpanEventSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty SpanEvent. // It returns the newly added SpanEvent. -func (es SpanEventSlice) AppendEmpty() SpanEvent { +func (es MutableSpanEventSlice) AppendEmpty() MutableSpanEvent { *es.getOrig() = append(*es.getOrig(), &otlptrace.Span_Event{}) return es.At(es.Len() - 1) } @@ -816,13 +1058,13 @@ func (es SpanEventSlice) AppendEmpty() SpanEvent { // Sort sorts the SpanEvent elements within SpanEventSlice given the // provided less function so that two instances of SpanEventSlice // can be compared. -func (es SpanEventSlice) Sort(less func(a, b SpanEvent) bool) { +func (es MutableSpanEventSlice) Sort(less func(a, b MutableSpanEvent) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableSpanEventSlice) MoveAndAppendTo(dest MutableSpanEventSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -834,7 +1076,7 @@ func (es SpanEventSlice) MoveAndAppendTo(dest SpanEventSlice) { // 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) { +func (es MutableSpanEventSlice) RemoveIf(f func(MutableSpanEvent) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -863,25 +1105,35 @@ func (es SpanEventSlice) RemoveIf(f func(SpanEvent) bool) { type SpanEvent internal.SpanEvent +type MutableSpanEvent internal.MutableSpanEvent + func newSpanEvent(orig *otlptrace.Span_Event) SpanEvent { return SpanEvent(internal.NewSpanEvent(orig)) } +func newMutableSpanEvent(orig *otlptrace.Span_Event) MutableSpanEvent { + return MutableSpanEvent(internal.NewSpanEvent(orig)) +} + func (ms SpanEvent) getOrig() *otlptrace.Span_Event { return internal.GetOrigSpanEvent(internal.SpanEvent(ms)) } +func (ms MutableSpanEvent) getOrig() *otlptrace.Span_Event { + return internal.GetMutableOrigSpanEvent(internal.MutableSpanEvent(ms)) +} + // NewSpanEvent creates a new empty SpanEvent. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSpanEvent() SpanEvent { - return newSpanEvent(&otlptrace.Span_Event{}) +func NewSpanEvent() MutableSpanEvent { + return newMutableSpanEvent(&otlptrace.Span_Event{}) } // 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) { +func (ms MutableSpanEvent) MoveTo(dest MutableSpanEvent) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.Span_Event{} } @@ -891,8 +1143,13 @@ func (ms SpanEvent) Timestamp() pcommon.Timestamp { return pcommon.Timestamp(ms.getOrig().TimeUnixNano) } +// Timestamp returns the timestamp associated with this SpanEvent. +func (ms MutableSpanEvent) Timestamp() pcommon.Timestamp { + return pcommon.Timestamp(ms.getOrig().TimeUnixNano) +} + // SetTimestamp replaces the timestamp associated with this SpanEvent. -func (ms SpanEvent) SetTimestamp(v pcommon.Timestamp) { +func (ms MutableSpanEvent) SetTimestamp(v pcommon.Timestamp) { ms.getOrig().TimeUnixNano = uint64(v) } @@ -901,8 +1158,13 @@ func (ms SpanEvent) Name() string { return ms.getOrig().Name } +// MutableName returns the name associated with this SpanEvent. +func (ms MutableSpanEvent) Name() string { + return ms.getOrig().Name +} + // SetName replaces the name associated with this SpanEvent. -func (ms SpanEvent) SetName(v string) { +func (ms MutableSpanEvent) SetName(v string) { ms.getOrig().Name = v } @@ -911,24 +1173,39 @@ func (ms SpanEvent) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this SpanEvent. +func (ms MutableSpanEvent) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // DroppedAttributesCount returns the droppedattributescount associated with this SpanEvent. func (ms SpanEvent) DroppedAttributesCount() uint32 { return ms.getOrig().DroppedAttributesCount } +// MutableDroppedAttributesCount returns the droppedattributescount associated with this SpanEvent. +func (ms MutableSpanEvent) DroppedAttributesCount() uint32 { + return ms.getOrig().DroppedAttributesCount +} + // SetDroppedAttributesCount replaces the droppedattributescount associated with this SpanEvent. -func (ms SpanEvent) SetDroppedAttributesCount(v uint32) { +func (ms MutableSpanEvent) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms SpanEvent) CopyTo(dest SpanEvent) { +func (ms SpanEvent) CopyTo(dest MutableSpanEvent) { dest.SetTimestamp(ms.Timestamp()) dest.SetName(ms.Name()) ms.Attributes().CopyTo(dest.Attributes()) dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSpanEvent) CopyTo(dest MutableSpanEvent) { + newSpanEvent(ms.getOrig()).CopyTo(dest) +} + // SpanLinkSlice logically represents a slice of SpanLink. // // This is a reference type. If passed by value and callee modifies it, the @@ -938,19 +1215,29 @@ func (ms SpanEvent) CopyTo(dest SpanEvent) { // Important: zero-initialized instance is not valid for use. type SpanLinkSlice internal.SpanLinkSlice +type MutableSpanLinkSlice internal.MutableSpanLinkSlice + func newSpanLinkSlice(orig *[]*otlptrace.Span_Link) SpanLinkSlice { return SpanLinkSlice(internal.NewSpanLinkSlice(orig)) } +func newMutableSpanLinkSlice(orig *[]*otlptrace.Span_Link) MutableSpanLinkSlice { + return MutableSpanLinkSlice(internal.NewSpanLinkSlice(orig)) +} + func (ms SpanLinkSlice) getOrig() *[]*otlptrace.Span_Link { return internal.GetOrigSpanLinkSlice(internal.SpanLinkSlice(ms)) } +func (ms MutableSpanLinkSlice) getOrig() *[]*otlptrace.Span_Link { + return internal.GetMutableOrigSpanLinkSlice(internal.MutableSpanLinkSlice(ms)) +} + // NewSpanLinkSlice creates a SpanLinkSlice with 0 elements. // Can use "EnsureCapacity" to initialize with a given capacity. -func NewSpanLinkSlice() SpanLinkSlice { +func NewSpanLinkSlice() MutableSpanLinkSlice { orig := []*otlptrace.Span_Link(nil) - return newSpanLinkSlice(&orig) + return newMutableSpanLinkSlice(&orig) } // Len returns the number of elements in the slice. @@ -960,6 +1247,10 @@ func (es SpanLinkSlice) Len() int { return len(*es.getOrig()) } +func (es MutableSpanLinkSlice) 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: @@ -972,14 +1263,18 @@ func (es SpanLinkSlice) At(ix int) SpanLink { return newSpanLink((*es.getOrig())[ix]) } +func (es MutableSpanLinkSlice) At(ix int) MutableSpanLink { + return newMutableSpanLink((*es.getOrig())[ix]) +} + // CopyTo copies all elements from the current slice overriding the destination. -func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { +func (es SpanLinkSlice) CopyTo(dest MutableSpanLinkSlice) { srcLen := es.Len() destCap := cap(*dest.getOrig()) if srcLen <= destCap { (*dest.getOrig()) = (*dest.getOrig())[:srcLen:destCap] for i := range *es.getOrig() { - newSpanLink((*es.getOrig())[i]).CopyTo(newSpanLink((*dest.getOrig())[i])) + newSpanLink((*es.getOrig())[i]).CopyTo(newMutableSpanLink((*dest.getOrig())[i])) } return } @@ -987,11 +1282,16 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { wrappers := make([]*otlptrace.Span_Link, srcLen) for i := range *es.getOrig() { wrappers[i] = &origs[i] - newSpanLink((*es.getOrig())[i]).CopyTo(newSpanLink(wrappers[i])) + newSpanLink((*es.getOrig())[i]).CopyTo(newMutableSpanLink(wrappers[i])) } *dest.getOrig() = wrappers } +// CopyTo copies all elements from the current slice overriding the destination. +func (es MutableSpanLinkSlice) CopyTo(dest MutableSpanLinkSlice) { + newSpanLinkSlice(es.getOrig()).CopyTo(dest) +} + // 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. @@ -1004,7 +1304,7 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { // e := es.AppendEmpty() // // Here should set all the values for e. // } -func (es SpanLinkSlice) EnsureCapacity(newCap int) { +func (es MutableSpanLinkSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.getOrig()) if newCap <= oldCap { return @@ -1017,7 +1317,7 @@ func (es SpanLinkSlice) EnsureCapacity(newCap int) { // AppendEmpty will append to the end of the slice an empty SpanLink. // It returns the newly added SpanLink. -func (es SpanLinkSlice) AppendEmpty() SpanLink { +func (es MutableSpanLinkSlice) AppendEmpty() MutableSpanLink { *es.getOrig() = append(*es.getOrig(), &otlptrace.Span_Link{}) return es.At(es.Len() - 1) } @@ -1025,13 +1325,13 @@ func (es SpanLinkSlice) AppendEmpty() SpanLink { // Sort sorts the SpanLink elements within SpanLinkSlice given the // provided less function so that two instances of SpanLinkSlice // can be compared. -func (es SpanLinkSlice) Sort(less func(a, b SpanLink) bool) { +func (es MutableSpanLinkSlice) Sort(less func(a, b MutableSpanLink) bool) { sort.SliceStable(*es.getOrig(), 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) { +func (es MutableSpanLinkSlice) MoveAndAppendTo(dest MutableSpanLinkSlice) { if *dest.getOrig() == nil { // We can simply move the entire vector and avoid any allocations. *dest.getOrig() = *es.getOrig() @@ -1043,7 +1343,7 @@ func (es SpanLinkSlice) MoveAndAppendTo(dest SpanLinkSlice) { // 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) { +func (es MutableSpanLinkSlice) RemoveIf(f func(MutableSpanLink) bool) { newLen := 0 for i := 0; i < len(*es.getOrig()); i++ { if f(es.At(i)) { @@ -1073,25 +1373,35 @@ func (es SpanLinkSlice) RemoveIf(f func(SpanLink) bool) { type SpanLink internal.SpanLink +type MutableSpanLink internal.MutableSpanLink + func newSpanLink(orig *otlptrace.Span_Link) SpanLink { return SpanLink(internal.NewSpanLink(orig)) } +func newMutableSpanLink(orig *otlptrace.Span_Link) MutableSpanLink { + return MutableSpanLink(internal.NewSpanLink(orig)) +} + func (ms SpanLink) getOrig() *otlptrace.Span_Link { return internal.GetOrigSpanLink(internal.SpanLink(ms)) } +func (ms MutableSpanLink) getOrig() *otlptrace.Span_Link { + return internal.GetMutableOrigSpanLink(internal.MutableSpanLink(ms)) +} + // NewSpanLink creates a new empty SpanLink. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewSpanLink() SpanLink { - return newSpanLink(&otlptrace.Span_Link{}) +func NewSpanLink() MutableSpanLink { + return newMutableSpanLink(&otlptrace.Span_Link{}) } // 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) { +func (ms MutableSpanLink) MoveTo(dest MutableSpanLink) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.Span_Link{} } @@ -1101,8 +1411,13 @@ func (ms SpanLink) TraceID() pcommon.TraceID { return pcommon.TraceID(ms.getOrig().TraceId) } +// TraceID returns the traceid associated with this SpanLink. +func (ms MutableSpanLink) TraceID() pcommon.TraceID { + return pcommon.TraceID(ms.getOrig().TraceId) +} + // SetTraceID replaces the traceid associated with this SpanLink. -func (ms SpanLink) SetTraceID(v pcommon.TraceID) { +func (ms MutableSpanLink) SetTraceID(v pcommon.TraceID) { ms.getOrig().TraceId = data.TraceID(v) } @@ -1111,8 +1426,13 @@ func (ms SpanLink) SpanID() pcommon.SpanID { return pcommon.SpanID(ms.getOrig().SpanId) } +// SpanID returns the spanid associated with this SpanLink. +func (ms MutableSpanLink) SpanID() pcommon.SpanID { + return pcommon.SpanID(ms.getOrig().SpanId) +} + // SetSpanID replaces the spanid associated with this SpanLink. -func (ms SpanLink) SetSpanID(v pcommon.SpanID) { +func (ms MutableSpanLink) SetSpanID(v pcommon.SpanID) { ms.getOrig().SpanId = data.SpanID(v) } @@ -1121,23 +1441,38 @@ func (ms SpanLink) TraceState() pcommon.TraceState { return pcommon.TraceState(internal.NewTraceState(&ms.getOrig().TraceState)) } +// TraceState returns the tracestate associated with this SpanLink. +func (ms MutableSpanLink) TraceState() pcommon.MutableTraceState { + return pcommon.MutableTraceState(internal.NewMutableTraceState(&ms.getOrig().TraceState)) +} + // Attributes returns the Attributes associated with this SpanLink. func (ms SpanLink) Attributes() pcommon.Map { return pcommon.Map(internal.NewMap(&ms.getOrig().Attributes)) } +// Attributes returns the Attributes associated with this SpanLink. +func (ms MutableSpanLink) Attributes() pcommon.MutableMap { + return pcommon.MutableMap(internal.NewMutableMap(&ms.getOrig().Attributes)) +} + // DroppedAttributesCount returns the droppedattributescount associated with this SpanLink. func (ms SpanLink) DroppedAttributesCount() uint32 { return ms.getOrig().DroppedAttributesCount } +// MutableDroppedAttributesCount returns the droppedattributescount associated with this SpanLink. +func (ms MutableSpanLink) DroppedAttributesCount() uint32 { + return ms.getOrig().DroppedAttributesCount +} + // SetDroppedAttributesCount replaces the droppedattributescount associated with this SpanLink. -func (ms SpanLink) SetDroppedAttributesCount(v uint32) { +func (ms MutableSpanLink) SetDroppedAttributesCount(v uint32) { ms.getOrig().DroppedAttributesCount = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms SpanLink) CopyTo(dest SpanLink) { +func (ms SpanLink) CopyTo(dest MutableSpanLink) { dest.SetTraceID(ms.TraceID()) dest.SetSpanID(ms.SpanID()) ms.TraceState().CopyTo(dest.TraceState()) @@ -1145,6 +1480,11 @@ func (ms SpanLink) CopyTo(dest SpanLink) { dest.SetDroppedAttributesCount(ms.DroppedAttributesCount()) } +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableSpanLink) CopyTo(dest MutableSpanLink) { + newSpanLink(ms.getOrig()).CopyTo(dest) +} + // Status is an optional final status for this span. Semantically, when Status was not // set, that means the span ended without errors and to assume Status.Ok (code = 0). // @@ -1156,25 +1496,35 @@ func (ms SpanLink) CopyTo(dest SpanLink) { type Status internal.Status +type MutableStatus internal.MutableStatus + func newStatus(orig *otlptrace.Status) Status { return Status(internal.NewStatus(orig)) } +func newMutableStatus(orig *otlptrace.Status) MutableStatus { + return MutableStatus(internal.NewStatus(orig)) +} + func (ms Status) getOrig() *otlptrace.Status { return internal.GetOrigStatus(internal.Status(ms)) } +func (ms MutableStatus) getOrig() *otlptrace.Status { + return internal.GetMutableOrigStatus(internal.MutableStatus(ms)) +} + // NewStatus creates a new empty Status. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewStatus() Status { - return newStatus(&otlptrace.Status{}) +func NewStatus() MutableStatus { + return newMutableStatus(&otlptrace.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) { +func (ms MutableStatus) MoveTo(dest MutableStatus) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlptrace.Status{} } @@ -1184,8 +1534,13 @@ func (ms Status) Code() StatusCode { return StatusCode(ms.getOrig().Code) } +// Code returns the code associated with this Status. +func (ms MutableStatus) Code() StatusCode { + return StatusCode(ms.getOrig().Code) +} + // SetCode replaces the code associated with this Status. -func (ms Status) SetCode(v StatusCode) { +func (ms MutableStatus) SetCode(v StatusCode) { ms.getOrig().Code = otlptrace.Status_StatusCode(v) } @@ -1194,13 +1549,23 @@ func (ms Status) Message() string { return ms.getOrig().Message } +// MutableMessage returns the message associated with this Status. +func (ms MutableStatus) Message() string { + return ms.getOrig().Message +} + // SetMessage replaces the message associated with this Status. -func (ms Status) SetMessage(v string) { +func (ms MutableStatus) SetMessage(v string) { ms.getOrig().Message = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms Status) CopyTo(dest Status) { +func (ms Status) CopyTo(dest MutableStatus) { dest.SetCode(ms.Code()) dest.SetMessage(ms.Message()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableStatus) CopyTo(dest MutableStatus) { + newStatus(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/ptrace/generated_traces_test.go b/pdata/ptrace/generated_traces_test.go index 51abb471ebe..582b6dd31f5 100644 --- a/pdata/ptrace/generated_traces_test.go +++ b/pdata/ptrace/generated_traces_test.go @@ -41,7 +41,7 @@ func TestResourceSpansSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestResourceSpans(internal.ResourceSpans(el)) + internal.FillTestResourceSpans(internal.MutableResourceSpans(el)) assert.Equal(t, testVal, el) } } @@ -139,11 +139,11 @@ func TestResourceSpansSlice_RemoveIf(t *testing.T) { } func TestResourceSpans_MoveTo(t *testing.T) { - ms := ResourceSpans(internal.GenerateTestResourceSpans()) + ms := MutableResourceSpans{internal.GenerateTestResourceSpans()} dest := NewResourceSpans() ms.MoveTo(dest) assert.Equal(t, NewResourceSpans(), ms) - assert.Equal(t, ResourceSpans(internal.GenerateTestResourceSpans()), dest) + assert.Equal(t, MutableResourceSpans(internal.GenerateTestResourceSpans()), dest) } func TestResourceSpans_CopyTo(t *testing.T) { @@ -151,7 +151,7 @@ func TestResourceSpans_CopyTo(t *testing.T) { orig := NewResourceSpans() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ResourceSpans(internal.GenerateTestResourceSpans()) + orig = MutableResourceSpans(internal.GenerateTestResourceSpans()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -189,7 +189,7 @@ func TestScopeSpansSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestScopeSpans(internal.ScopeSpans(el)) + internal.FillTestScopeSpans(internal.MutableScopeSpans(el)) assert.Equal(t, testVal, el) } } @@ -287,11 +287,11 @@ func TestScopeSpansSlice_RemoveIf(t *testing.T) { } func TestScopeSpans_MoveTo(t *testing.T) { - ms := ScopeSpans(internal.GenerateTestScopeSpans()) + ms := MutableScopeSpans{internal.GenerateTestScopeSpans()} dest := NewScopeSpans() ms.MoveTo(dest) assert.Equal(t, NewScopeSpans(), ms) - assert.Equal(t, ScopeSpans(internal.GenerateTestScopeSpans()), dest) + assert.Equal(t, MutableScopeSpans(internal.GenerateTestScopeSpans()), dest) } func TestScopeSpans_CopyTo(t *testing.T) { @@ -299,7 +299,7 @@ func TestScopeSpans_CopyTo(t *testing.T) { orig := NewScopeSpans() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ScopeSpans(internal.GenerateTestScopeSpans()) + orig = MutableScopeSpans(internal.GenerateTestScopeSpans()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -337,7 +337,7 @@ func TestSpanSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSpan(internal.Span(el)) + internal.FillTestSpan(internal.MutableSpan(el)) assert.Equal(t, testVal, el) } } @@ -435,11 +435,11 @@ func TestSpanSlice_RemoveIf(t *testing.T) { } func TestSpan_MoveTo(t *testing.T) { - ms := Span(internal.GenerateTestSpan()) + ms := MutableSpan{internal.GenerateTestSpan()} dest := NewSpan() ms.MoveTo(dest) assert.Equal(t, NewSpan(), ms) - assert.Equal(t, Span(internal.GenerateTestSpan()), dest) + assert.Equal(t, MutableSpan(internal.GenerateTestSpan()), dest) } func TestSpan_CopyTo(t *testing.T) { @@ -447,7 +447,7 @@ func TestSpan_CopyTo(t *testing.T) { orig := NewSpan() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Span(internal.GenerateTestSpan()) + orig = MutableSpan(internal.GenerateTestSpan()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -574,7 +574,7 @@ func TestSpanEventSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSpanEvent(internal.SpanEvent(el)) + internal.FillTestSpanEvent(internal.MutableSpanEvent(el)) assert.Equal(t, testVal, el) } } @@ -672,11 +672,11 @@ func TestSpanEventSlice_RemoveIf(t *testing.T) { } func TestSpanEvent_MoveTo(t *testing.T) { - ms := SpanEvent(internal.GenerateTestSpanEvent()) + ms := MutableSpanEvent{internal.GenerateTestSpanEvent()} dest := NewSpanEvent() ms.MoveTo(dest) assert.Equal(t, NewSpanEvent(), ms) - assert.Equal(t, SpanEvent(internal.GenerateTestSpanEvent()), dest) + assert.Equal(t, MutableSpanEvent(internal.GenerateTestSpanEvent()), dest) } func TestSpanEvent_CopyTo(t *testing.T) { @@ -684,7 +684,7 @@ func TestSpanEvent_CopyTo(t *testing.T) { orig := NewSpanEvent() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SpanEvent(internal.GenerateTestSpanEvent()) + orig = MutableSpanEvent(internal.GenerateTestSpanEvent()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -731,7 +731,7 @@ func TestSpanLinkSlice(t *testing.T) { for i := 0; i < es.Len(); i++ { el := es.AppendEmpty() assert.Equal(t, emptyVal, el) - internal.FillTestSpanLink(internal.SpanLink(el)) + internal.FillTestSpanLink(internal.MutableSpanLink(el)) assert.Equal(t, testVal, el) } } @@ -829,11 +829,11 @@ func TestSpanLinkSlice_RemoveIf(t *testing.T) { } func TestSpanLink_MoveTo(t *testing.T) { - ms := SpanLink(internal.GenerateTestSpanLink()) + ms := MutableSpanLink{internal.GenerateTestSpanLink()} dest := NewSpanLink() ms.MoveTo(dest) assert.Equal(t, NewSpanLink(), ms) - assert.Equal(t, SpanLink(internal.GenerateTestSpanLink()), dest) + assert.Equal(t, MutableSpanLink(internal.GenerateTestSpanLink()), dest) } func TestSpanLink_CopyTo(t *testing.T) { @@ -841,7 +841,7 @@ func TestSpanLink_CopyTo(t *testing.T) { orig := NewSpanLink() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = SpanLink(internal.GenerateTestSpanLink()) + orig = MutableSpanLink(internal.GenerateTestSpanLink()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } @@ -883,11 +883,11 @@ func TestSpanLink_DroppedAttributesCount(t *testing.T) { } func TestStatus_MoveTo(t *testing.T) { - ms := Status(internal.GenerateTestStatus()) + ms := MutableStatus{internal.GenerateTestStatus()} dest := NewStatus() ms.MoveTo(dest) assert.Equal(t, NewStatus(), ms) - assert.Equal(t, Status(internal.GenerateTestStatus()), dest) + assert.Equal(t, MutableStatus(internal.GenerateTestStatus()), dest) } func TestStatus_CopyTo(t *testing.T) { @@ -895,7 +895,7 @@ func TestStatus_CopyTo(t *testing.T) { orig := NewStatus() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = Status(internal.GenerateTestStatus()) + orig = MutableStatus(internal.GenerateTestStatus()) orig.CopyTo(ms) assert.Equal(t, orig, ms) } diff --git a/pdata/ptrace/ptraceotlp/generated_traces_otlp.go b/pdata/ptrace/ptraceotlp/generated_traces_otlp.go index 682a033f5cc..1f51984ff2a 100644 --- a/pdata/ptrace/ptraceotlp/generated_traces_otlp.go +++ b/pdata/ptrace/ptraceotlp/generated_traces_otlp.go @@ -32,25 +32,35 @@ import ( type ExportPartialSuccess internal.TracesExportPartialSuccess +type MutableExportPartialSuccess internal.MutableTracesExportPartialSuccess + func newExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) ExportPartialSuccess { return ExportPartialSuccess(internal.NewTracesExportPartialSuccess(orig)) } +func newMutableExportPartialSuccess(orig *otlpcollectortrace.ExportTracePartialSuccess) MutableExportPartialSuccess { + return MutableExportPartialSuccess(internal.NewTracesExportPartialSuccess(orig)) +} + func (ms ExportPartialSuccess) getOrig() *otlpcollectortrace.ExportTracePartialSuccess { return internal.GetOrigTracesExportPartialSuccess(internal.TracesExportPartialSuccess(ms)) } +func (ms MutableExportPartialSuccess) getOrig() *otlpcollectortrace.ExportTracePartialSuccess { + return internal.GetMutableOrigTracesExportPartialSuccess(internal.MutableTracesExportPartialSuccess(ms)) +} + // NewExportPartialSuccess creates a new empty ExportPartialSuccess. // // This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, // OR directly access the member if this is embedded in another struct. -func NewExportPartialSuccess() ExportPartialSuccess { - return newExportPartialSuccess(&otlpcollectortrace.ExportTracePartialSuccess{}) +func NewExportPartialSuccess() MutableExportPartialSuccess { + return newMutableExportPartialSuccess(&otlpcollectortrace.ExportTracePartialSuccess{}) } // 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) { +func (ms MutableExportPartialSuccess) MoveTo(dest MutableExportPartialSuccess) { *dest.getOrig() = *ms.getOrig() *ms.getOrig() = otlpcollectortrace.ExportTracePartialSuccess{} } @@ -60,8 +70,13 @@ func (ms ExportPartialSuccess) RejectedSpans() int64 { return ms.getOrig().RejectedSpans } +// MutableRejectedSpans returns the rejectedspans associated with this ExportPartialSuccess. +func (ms MutableExportPartialSuccess) RejectedSpans() int64 { + return ms.getOrig().RejectedSpans +} + // SetRejectedSpans replaces the rejectedspans associated with this ExportPartialSuccess. -func (ms ExportPartialSuccess) SetRejectedSpans(v int64) { +func (ms MutableExportPartialSuccess) SetRejectedSpans(v int64) { ms.getOrig().RejectedSpans = v } @@ -70,13 +85,23 @@ func (ms ExportPartialSuccess) ErrorMessage() string { return ms.getOrig().ErrorMessage } +// MutableErrorMessage returns the errormessage associated with this ExportPartialSuccess. +func (ms MutableExportPartialSuccess) ErrorMessage() string { + return ms.getOrig().ErrorMessage +} + // SetErrorMessage replaces the errormessage associated with this ExportPartialSuccess. -func (ms ExportPartialSuccess) SetErrorMessage(v string) { +func (ms MutableExportPartialSuccess) SetErrorMessage(v string) { ms.getOrig().ErrorMessage = v } // CopyTo copies all properties from the current struct overriding the destination. -func (ms ExportPartialSuccess) CopyTo(dest ExportPartialSuccess) { +func (ms ExportPartialSuccess) CopyTo(dest MutableExportPartialSuccess) { dest.SetRejectedSpans(ms.RejectedSpans()) dest.SetErrorMessage(ms.ErrorMessage()) } + +// CopyTo copies all properties from the current struct overriding the destination. +func (ms MutableExportPartialSuccess) CopyTo(dest MutableExportPartialSuccess) { + newExportPartialSuccess(ms.getOrig()).CopyTo(dest) +} diff --git a/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go b/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go index b7f3b32eacc..e1ec757d554 100644 --- a/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go +++ b/pdata/ptrace/ptraceotlp/generated_traces_otlp_test.go @@ -26,11 +26,11 @@ import ( ) func TestExportPartialSuccess_MoveTo(t *testing.T) { - ms := ExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()) + ms := MutableExportPartialSuccess{internal.GenerateTestTracesExportPartialSuccess()} dest := NewExportPartialSuccess() ms.MoveTo(dest) assert.Equal(t, NewExportPartialSuccess(), ms) - assert.Equal(t, ExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()), dest) + assert.Equal(t, MutableExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()), dest) } func TestExportPartialSuccess_CopyTo(t *testing.T) { @@ -38,7 +38,7 @@ func TestExportPartialSuccess_CopyTo(t *testing.T) { orig := NewExportPartialSuccess() orig.CopyTo(ms) assert.Equal(t, orig, ms) - orig = ExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()) + orig = MutableExportPartialSuccess(internal.GenerateTestTracesExportPartialSuccess()) orig.CopyTo(ms) assert.Equal(t, orig, ms) }