[chore] Implement pooling support for oneOf messages (#13692)

Updates
https://github.com/open-telemetry/opentelemetry-collector/issues/13631

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
Bogdan Drutu 2025-08-22 16:51:08 -07:00 committed by GitHub
parent 1a001d98c3
commit cbe449b18a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
70 changed files with 1034 additions and 443 deletions

View File

@ -14,6 +14,8 @@ type Field interface {
GenerateTestEncodingValues(ms *messageStruct) string
GeneratePoolOrig(ms *messageStruct) string
GenerateDeleteOrig(ms *messageStruct) string
GenerateCopyOrig(ms *messageStruct) string

View File

@ -72,6 +72,10 @@ func (mf *MessageField) GenerateCopyOrig(ms *messageStruct) string {
return template.Execute(t, mf.templateFields(ms))
}
func (mf *MessageField) GeneratePoolOrig(*messageStruct) string {
return ""
}
func (mf *MessageField) GenerateMarshalJSON(*messageStruct) string {
return mf.toProtoField().GenMarshalJSON()
}

View File

@ -44,6 +44,11 @@ const oneOfTestValuesTemplate = `
{{ .GenerateTestEncodingValues $.baseStruct $.OneOfField }}
{{- end }}`
const oneOfPoolOrigTemplate = `
{{- range .values }}
{{ .GeneratePoolOrig $.baseStruct $.OneOfField }}
{{- end }}`
const oneOfDeleteOrigTemplate = `switch ov := orig.{{ .originFieldName }}.(type) {
{{ range .values -}}
case *{{ $.originTypePrefix }}{{ .GetOriginFieldName }}:
@ -124,18 +129,12 @@ func (of *OneOfField) GenerateTestEncodingValues(ms *messageStruct) string {
return template.Execute(template.Parse("oneOfTestValuesTemplate", []byte(oneOfTestValuesTemplate)), of.templateFields(ms))
}
func (of *OneOfField) GeneratePoolOrig(ms *messageStruct) string {
return template.Execute(template.Parse("oneOfPoolOrigTemplate", []byte(oneOfPoolOrigTemplate)), of.templateFields(ms))
}
func (of *OneOfField) GenerateDeleteOrig(ms *messageStruct) string {
atLeastOneMessage := false
for i := range of.values {
if _, ok := of.values[i].(*OneOfMessageValue); ok {
atLeastOneMessage = true
break
}
}
if atLeastOneMessage {
return template.Execute(template.Parse("oneOfDeleteOrigTemplate", []byte(oneOfDeleteOrigTemplate)), of.templateFields(ms))
}
return ""
return template.Execute(template.Parse("oneOfDeleteOrigTemplate", []byte(oneOfDeleteOrigTemplate)), of.templateFields(ms))
}
func (of *OneOfField) GenerateCopyOrig(ms *messageStruct) string {
@ -173,6 +172,7 @@ func (of *OneOfField) templateFields(ms *messageStruct) map[string]any {
"structName": ms.getName(),
"typeFuncName": of.typeFuncName(),
"typeName": of.typeName,
"originName": ms.getOriginName(),
"originFieldName": of.originFieldName,
"lowerOriginFieldName": strings.ToLower(of.originFieldName),
"origAccessor": origAccessor(ms.getHasWrapper()),
@ -191,6 +191,7 @@ type oneOfValue interface {
GenerateTestValue(ms *messageStruct, of *OneOfField) string
GenerateTestFailingUnmarshalProtoValues(ms *messageStruct, of *OneOfField) string
GenerateTestEncodingValues(ms *messageStruct, of *OneOfField) string
GeneratePoolOrig(ms *messageStruct, of *OneOfField) string
GenerateDeleteOrig(ms *messageStruct, of *OneOfField) string
GenerateCopyOrig(ms *messageStruct, of *OneOfField) string
GenerateType(ms *messageStruct, of *OneOfField) string

View File

@ -96,6 +96,10 @@ func (omv *OneOfMessageValue) GenerateTestEncodingValues(ms *messageStruct, of *
return omv.toProtoField(ms, of, false).GenTestEncodingValues()
}
func (omv *OneOfMessageValue) GeneratePoolOrig(ms *messageStruct, of *OneOfField) string {
return omv.toProtoField(ms, of, false).GenPoolVarOrig()
}
func (omv *OneOfMessageValue) GenerateDeleteOrig(ms *messageStruct, of *OneOfField) string {
return omv.toProtoField(ms, of, false).GenDeleteOrig()
}

View File

@ -91,6 +91,10 @@ func (opv *OneOfPrimitiveValue) GenerateTestEncodingValues(ms *messageStruct, of
return opv.toProtoField(ms, of, false).GenTestEncodingValues()
}
func (opv *OneOfPrimitiveValue) GeneratePoolOrig(ms *messageStruct, of *OneOfField) string {
return opv.toProtoField(ms, of, false).GenPoolVarOrig()
}
func (opv *OneOfPrimitiveValue) GenerateDeleteOrig(ms *messageStruct, of *OneOfField) string {
return opv.toProtoField(ms, of, false).GenDeleteOrig()
}

View File

@ -76,18 +76,15 @@ type OptionalPrimitiveField struct {
}
func (opv *OptionalPrimitiveField) GenerateAccessors(ms *messageStruct) string {
t := template.Parse("optionalPrimitiveAccessorsTemplate", []byte(optionalPrimitiveAccessorsTemplate))
return template.Execute(t, opv.templateFields(ms))
return template.Execute(template.Parse("optionalPrimitiveAccessorsTemplate", []byte(optionalPrimitiveAccessorsTemplate)), opv.templateFields(ms))
}
func (opv *OptionalPrimitiveField) GenerateAccessorsTest(ms *messageStruct) string {
t := template.Parse("optionalPrimitiveAccessorsTestTemplate", []byte(optionalPrimitiveAccessorsTestTemplate))
return template.Execute(t, opv.templateFields(ms))
return template.Execute(template.Parse("optionalPrimitiveAccessorsTestTemplate", []byte(optionalPrimitiveAccessorsTestTemplate)), opv.templateFields(ms))
}
func (opv *OptionalPrimitiveField) GenerateTestValue(ms *messageStruct) string {
t := template.Parse("optionalPrimitiveSetTestTemplate", []byte(optionalPrimitiveSetTestTemplate))
return template.Execute(t, opv.templateFields(ms))
return template.Execute(template.Parse("optionalPrimitiveSetTestTemplate", []byte(optionalPrimitiveSetTestTemplate)), opv.templateFields(ms))
}
func (opv *OptionalPrimitiveField) GenerateTestFailingUnmarshalProtoValues(ms *messageStruct) string {
@ -98,13 +95,16 @@ func (opv *OptionalPrimitiveField) GenerateTestEncodingValues(ms *messageStruct)
return opv.toProtoField(ms, false).GenTestEncodingValues()
}
func (opv *OptionalPrimitiveField) GeneratePoolOrig(ms *messageStruct) string {
return opv.toProtoField(ms, false).GenPoolVarOrig()
}
func (opv *OptionalPrimitiveField) GenerateDeleteOrig(ms *messageStruct) string {
return opv.toProtoField(ms, false).GenDeleteOrig()
return "switch ov := orig." + opv.fieldName + "_.(type) {\n\tcase *" + ms.getOriginFullName() + "_" + opv.fieldName + ":\n\t" + opv.toProtoField(ms, false).GenDeleteOrig() + "\n}\n"
}
func (opv *OptionalPrimitiveField) GenerateCopyOrig(ms *messageStruct) string {
t := template.Parse("optionalPrimitiveCopyOrigTemplate", []byte(optionalPrimitiveCopyOrigTemplate))
return template.Execute(t, opv.templateFields(ms))
return template.Execute(template.Parse("optionalPrimitiveCopyOrigTemplate", []byte(optionalPrimitiveCopyOrigTemplate)), opv.templateFields(ms))
}
func (opv *OptionalPrimitiveField) GenerateMarshalJSON(ms *messageStruct) string {
@ -152,8 +152,9 @@ func (opv *OptionalPrimitiveField) templateFields(ms *messageStruct) map[string]
"lowerFieldName": strings.ToLower(opv.fieldName),
"testValue": pf.TestValue(),
"returnType": pf.GoType(),
"originStructName": ms.originFullName,
"originStructType": ms.originFullName + "_" + opv.fieldName,
"originName": ms.getOriginName(),
"originStructName": ms.getOriginFullName(),
"originStructType": ms.getOriginFullName() + "_" + opv.fieldName,
}
}

View File

@ -80,6 +80,10 @@ func (pf *PrimitiveField) GenerateTestEncodingValues(*messageStruct) string {
return pf.toProtoField().GenTestEncodingValues()
}
func (pf *PrimitiveField) GeneratePoolOrig(*messageStruct) string {
return ""
}
func (pf *PrimitiveField) GenerateDeleteOrig(*messageStruct) string {
return pf.toProtoField().GenDeleteOrig()
}

View File

@ -69,6 +69,10 @@ func (sf *SliceField) GenerateTestEncodingValues(*messageStruct) string {
return sf.toProtoField().GenTestEncodingValues()
}
func (sf *SliceField) GeneratePoolOrig(*messageStruct) string {
return ""
}
func (sf *SliceField) GenerateDeleteOrig(*messageStruct) string {
return sf.toProtoField().GenDeleteOrig()
}

View File

@ -32,11 +32,15 @@ func New{{ .structName }}(orig *{{ .originFullName }}, state *State) {{ .structN
{{ end }}
var protoPool{{ .originName }} = sync.Pool{
New: func() any {
return &{{ .originFullName }}{}
},
}
var (
protoPool{{ .originName }} = sync.Pool{
New: func() any {
return &{{ .originFullName }}{}
},
}
{{- range .fields }}{{ .GeneratePoolOrig $.messageStruct }}{{- end }}
)
func NewOrig{{ .originName }}() *{{ .originFullName }} {
if !UseProtoPooling.IsEnabled() {
@ -57,7 +61,7 @@ func DeleteOrig{{ .originName }}(orig *{{ .originFullName }}, nullable bool) {
{{ range .fields }}{{ .GenerateDeleteOrig $.messageStruct }}{{ end }}
orig.Reset()
if nullable {
if nullable {
protoPool{{ .originName }}.Put(orig)
}
}

View File

@ -75,6 +75,10 @@ func (ptf *TypedField) GenerateTestEncodingValues(*messageStruct) string {
return ptf.toProtoField().GenTestEncodingValues()
}
func (ptf *TypedField) GeneratePoolOrig(*messageStruct) string {
return ""
}
func (ptf *TypedField) GenerateDeleteOrig(*messageStruct) string {
return ptf.toProtoField().GenDeleteOrig()
}

View File

@ -7,6 +7,12 @@ import (
"go.opentelemetry.io/collector/internal/cmd/pdatagen/internal/template"
)
const deleteOrigOther = `{{ if ne .oneOfGroup "" -}}
if UseProtoPooling.IsEnabled() {
protoPool{{ .oneOfMessageName }}.Put(ov)
}
{{ end }}`
const deleteOrigMessage = `{{ if .repeated -}}
for i := range orig.{{ .fieldName }} {
{{ if .nullable -}}
@ -16,6 +22,9 @@ const deleteOrigMessage = `{{ if .repeated -}}
{{- end }}
}
{{- else if ne .oneOfGroup "" -}}
if UseProtoPooling.IsEnabled() {
protoPool{{ .oneOfMessageName }}.Put(ov)
}
DeleteOrig{{ .origName }}(ov.{{ .fieldName }}, true)
{{- else if .nullable -}}
DeleteOrig{{ .origName }}(orig.{{ .fieldName }}, true)
@ -29,5 +38,8 @@ func (pf *Field) GenDeleteOrig() string {
if pf.Type == TypeMessage {
return template.Execute(template.Parse("deleteOrigMessage", []byte(deleteOrigMessage)), tf)
}
if pf.OneOfGroup != "" {
return template.Execute(template.Parse("deleteOrigOther", []byte(deleteOrigOther)), tf)
}
return ""
}

View File

@ -128,6 +128,7 @@ func (pf *Field) getTemplateFields() map[string]any {
"origName": pf.messageName(),
"origFullName": pf.MessageFullName,
"oneOfGroup": pf.OneOfGroup,
"oneOfMessageName": ExtractNameFromFull(pf.OneOfMessageFullName),
"oneOfMessageFullName": pf.OneOfMessageFullName,
"repeated": pf.Repeated,
"nullable": pf.Nullable,

View File

@ -19,9 +19,14 @@ const unmarshalJSONPrimitive = ` case {{ .allJSONTags }}:
}
{{ else if .nullable -}}
{
ofm := &{{ .oneOfMessageFullName }}{}
ofm.{{ .fieldName }} = iter.Read{{ upperFirst .goType }}()
orig.{{ .oneOfGroup }} = ofm
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = iter.Read{{ upperFirst .goType }}()
orig.{{ .oneOfGroup }} = ov
}
{{ else -}}
orig.{{ .fieldName }} = iter.Read{{ upperFirst .goType }}()
@ -44,10 +49,15 @@ const unmarshalJSONMessage = ` case {{ .allJSONTags }}:
}
{{ else if ne .oneOfGroup "" -}}
{
ofm := &{{ .oneOfMessageFullName }}{}
ofm.{{ .fieldName }} = NewOrig{{ .origName }}()
UnmarshalJSONOrig{{ .origName }}(ofm.{{ .fieldName }}, iter)
orig.{{ .oneOfGroup }} = ofm
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = NewOrig{{ .origName }}()
UnmarshalJSONOrig{{ .origName }}(ov.{{ .fieldName }}, iter)
orig.{{ .oneOfGroup }} = ov
}
{{ else -}}
UnmarshalJSONOrig{{ .origName }}({{ if not .nullable }}&{{ end }}orig.{{ .fieldName }}, iter)

View File

@ -0,0 +1,24 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package proto // import "go.opentelemetry.io/collector/internal/cmd/pdatagen/internal/proto"
import (
"go.opentelemetry.io/collector/internal/cmd/pdatagen/internal/template"
)
const poolVarOrigTemplate = `
protoPool{{ .oneOfMessageName }} = sync.Pool{
New: func() any {
return &{{ .oneOfMessageFullName }}{}
},
}
`
func (pf *Field) GenPoolVarOrig() string {
tf := pf.getTemplateFields()
if pf.OneOfGroup != "" {
return template.Execute(template.Parse("poolVarOrigTemplate", []byte(poolVarOrigTemplate)), tf)
}
return ""
}

View File

@ -44,9 +44,14 @@ const unmarshalProtoFloat = `{{ if .repeated -}}
return err
}
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = math.Float{{ .bitSize }}frombits(num)
orig.{{ .oneOfGroup }} = ofv
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = math.Float{{ .bitSize }}frombits(num)
orig.{{ .oneOfGroup }} = ov
{{- else }}
orig.{{ .fieldName }} = math.Float{{ .bitSize }}frombits(num)
{{- end }}{{- end }}`
@ -86,9 +91,14 @@ const unmarshalProtoFixed = `{{ if .repeated -}}
return err
}
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = {{ .goType }}(num)
orig.{{ .oneOfGroup }} = ofv
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = {{ .goType }}(num)
orig.{{ .oneOfGroup }} = ov
{{- else }}
orig.{{ .fieldName }} = {{ .goType }}(num)
{{- end }}{{- end }}`
@ -128,9 +138,14 @@ const unmarshalProtoBool = `{{ if .repeated -}}
return err
}
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = num != 0
orig.{{ .oneOfGroup }} = ofv
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = num != 0
orig.{{ .oneOfGroup }} = ov
{{- else }}
orig.{{ .fieldName }} = num != 0
{{- end }}{{- end }}`
@ -168,9 +183,14 @@ const unmarshalProtoVarint = `{{ if .repeated -}}
return err
}
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = {{ .goType }}(num)
orig.{{ .oneOfGroup }} = ofv
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = {{ .goType }}(num)
orig.{{ .oneOfGroup }} = ov
{{- else }}
orig.{{ .fieldName }} = {{ .goType }}(num)
{{- end }}{{- end }}`
@ -187,9 +207,14 @@ const unmarshalProtoString = `
}
startPos := pos - length
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = string(buf[startPos:pos])
orig.{{ .oneOfGroup }} = ofv
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = string(buf[startPos:pos])
orig.{{ .oneOfGroup }} = ov
{{- else if .repeated -}}
orig.{{ .fieldName }} = append(orig.{{ .fieldName }}, string(buf[startPos:pos]))
{{- else -}}
@ -208,10 +233,15 @@ const unmarshalProtoBytes = `
}
startPos := pos - length
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = make([]byte, length)
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = make([]byte, length)
copy(ofv.{{ .fieldName }}, buf[startPos:pos])
orig.{{ .oneOfGroup }} = ofv
orig.{{ .oneOfGroup }} = ov
{{- else if .repeated -}}
orig.{{ .fieldName }} = append(orig.{{ .fieldName }}, make([]byte, length))
copy(orig.{{ .fieldName }}[len(orig.{{ .fieldName }}) - 1], buf[startPos:pos])
@ -232,13 +262,18 @@ const unmarshalProtoMessage = `
}
startPos := pos - length
{{ if ne .oneOfGroup "" -}}
ofv := &{{ .oneOfMessageFullName }}{}
ofv.{{ .fieldName }} = NewOrig{{ .origName }}()
err = UnmarshalProtoOrig{{ .origName }}(ofv.{{ .fieldName }}, buf[startPos:pos])
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = NewOrig{{ .origName }}()
err = UnmarshalProtoOrig{{ .origName }}(ov.{{ .fieldName }}, buf[startPos:pos])
if err != nil {
return err
}
orig.{{ .oneOfGroup }} = ofv
orig.{{ .oneOfGroup }} = ov
{{- else if .repeated -}}
orig.{{ .fieldName }} = append(orig.{{ .fieldName }}, {{ if .nullable }}NewOrig{{ .origName }}(){{ else }}{{ .defaultValue }}{{ end }})
err = UnmarshalProtoOrig{{ .origName }}({{ if not .nullable }}&{{ end }}orig.{{ .fieldName }}[len(orig.{{ .fieldName }})-1], buf[startPos:pos])
@ -288,7 +323,14 @@ const unmarshalProtoSignedVarint = `{{ if .repeated -}}
return err
}
{{ if ne .oneOfGroup "" -}}
orig.{{ .oneOfGroup }} = &{{ .oneOfMessageFullName }} { {{ .fieldName }}: int{{ .bitSize }}(uint{{ .bitSize }}(num >> 1) ^ uint{{ .bitSize }}(int{{ .bitSize }}((num&1)<<{{ sub .bitSize 1 }})>>{{ sub .bitSize 1 }})) }
var ov *{{ .oneOfMessageFullName }}
if !UseProtoPooling.IsEnabled() {
ov = &{{ .oneOfMessageFullName }}{}
} else {
ov = protoPool{{ .oneOfMessageName }}.Get().(*{{ .oneOfMessageFullName }})
}
ov.{{ .fieldName }} = int{{ .bitSize }}(uint{{ .bitSize }}(num >> 1) ^ uint{{ .bitSize }}(int{{ .bitSize }}((num&1)<<{{ sub .bitSize 1 }})>>{{ sub .bitSize 1 }}))
orig.{{ .oneOfGroup }} = ov
{{- else }}
orig.{{ .fieldName }} = int{{ .bitSize }}(uint{{ .bitSize }}(num >> 1) ^ uint{{ .bitSize }}(int{{ .bitSize }}((num&1)<<{{ sub .bitSize 1 }})>>{{ sub .bitSize 1 }}))
{{- end }}{{- end }}`

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolArrayValue = sync.Pool{
New: func() any {
return &otlpcommon.ArrayValue{}
},
}
var (
protoPoolArrayValue = sync.Pool{
New: func() any {
return &otlpcommon.ArrayValue{}
},
}
)
func NewOrigArrayValue() *otlpcommon.ArrayValue {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolAttributeUnit = sync.Pool{
New: func() any {
return &otlpprofiles.AttributeUnit{}
},
}
var (
protoPoolAttributeUnit = sync.Pool{
New: func() any {
return &otlpprofiles.AttributeUnit{}
},
}
)
func NewOrigAttributeUnit() *otlpprofiles.AttributeUnit {
if !UseProtoPooling.IsEnabled() {

View File

@ -32,11 +32,13 @@ func NewEntityRef(orig *otlpcommon.EntityRef, state *State) EntityRef {
return EntityRef{orig: orig, state: state}
}
var protoPoolEntityRef = sync.Pool{
New: func() any {
return &otlpcommon.EntityRef{}
},
}
var (
protoPoolEntityRef = sync.Pool{
New: func() any {
return &otlpcommon.EntityRef{}
},
}
)
func NewOrigEntityRef() *otlpcommon.EntityRef {
if !UseProtoPooling.IsEnabled() {

View File

@ -19,11 +19,25 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExemplar = sync.Pool{
New: func() any {
return &otlpmetrics.Exemplar{}
},
}
var (
protoPoolExemplar = sync.Pool{
New: func() any {
return &otlpmetrics.Exemplar{}
},
}
protoPoolExemplar_AsDouble = sync.Pool{
New: func() any {
return &otlpmetrics.Exemplar_AsDouble{}
},
}
protoPoolExemplar_AsInt = sync.Pool{
New: func() any {
return &otlpmetrics.Exemplar_AsInt{}
},
}
)
func NewOrigExemplar() *otlpmetrics.Exemplar {
if !UseProtoPooling.IsEnabled() {
@ -45,6 +59,17 @@ func DeleteOrigExemplar(orig *otlpmetrics.Exemplar, nullable bool) {
for i := range orig.FilteredAttributes {
DeleteOrigKeyValue(&orig.FilteredAttributes[i], false)
}
switch ov := orig.Value.(type) {
case *otlpmetrics.Exemplar_AsDouble:
if UseProtoPooling.IsEnabled() {
protoPoolExemplar_AsDouble.Put(ov)
}
case *otlpmetrics.Exemplar_AsInt:
if UseProtoPooling.IsEnabled() {
protoPoolExemplar_AsInt.Put(ov)
}
}
DeleteOrigSpanID(&orig.SpanId, false)
DeleteOrigTraceID(&orig.TraceId, false)
@ -132,16 +157,26 @@ func UnmarshalJSONOrigExemplar(orig *otlpmetrics.Exemplar, iter *json.Iterator)
case "asDouble", "as_double":
{
ofm := &otlpmetrics.Exemplar_AsDouble{}
ofm.AsDouble = iter.ReadFloat64()
orig.Value = ofm
var ov *otlpmetrics.Exemplar_AsDouble
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Exemplar_AsDouble{}
} else {
ov = protoPoolExemplar_AsDouble.Get().(*otlpmetrics.Exemplar_AsDouble)
}
ov.AsDouble = iter.ReadFloat64()
orig.Value = ov
}
case "asInt", "as_int":
{
ofm := &otlpmetrics.Exemplar_AsInt{}
ofm.AsInt = iter.ReadInt64()
orig.Value = ofm
var ov *otlpmetrics.Exemplar_AsInt
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Exemplar_AsInt{}
} else {
ov = protoPoolExemplar_AsInt.Get().(*otlpmetrics.Exemplar_AsInt)
}
ov.AsInt = iter.ReadInt64()
orig.Value = ov
}
case "spanId", "span_id":
@ -277,9 +312,14 @@ func UnmarshalProtoOrigExemplar(orig *otlpmetrics.Exemplar, buf []byte) error {
if err != nil {
return err
}
ofv := &otlpmetrics.Exemplar_AsDouble{}
ofv.AsDouble = math.Float64frombits(num)
orig.Value = ofv
var ov *otlpmetrics.Exemplar_AsDouble
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Exemplar_AsDouble{}
} else {
ov = protoPoolExemplar_AsDouble.Get().(*otlpmetrics.Exemplar_AsDouble)
}
ov.AsDouble = math.Float64frombits(num)
orig.Value = ov
case 6:
if wireType != proto.WireTypeI64 {
@ -290,9 +330,14 @@ func UnmarshalProtoOrigExemplar(orig *otlpmetrics.Exemplar, buf []byte) error {
if err != nil {
return err
}
ofv := &otlpmetrics.Exemplar_AsInt{}
ofv.AsInt = int64(num)
orig.Value = ofv
var ov *otlpmetrics.Exemplar_AsInt
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Exemplar_AsInt{}
} else {
ov = protoPoolExemplar_AsInt.Get().(*otlpmetrics.Exemplar_AsInt)
}
ov.AsInt = int64(num)
orig.Value = ov
case 4:
if wireType != proto.WireTypeLen {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExponentialHistogram = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogram{}
},
}
var (
protoPoolExponentialHistogram = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogram{}
},
}
)
func NewOrigExponentialHistogram() *otlpmetrics.ExponentialHistogram {
if !UseProtoPooling.IsEnabled() {

View File

@ -18,11 +18,30 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExponentialHistogramDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint{}
},
}
var (
protoPoolExponentialHistogramDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint{}
},
}
protoPoolExponentialHistogramDataPoint_Sum = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint_Sum{}
},
}
protoPoolExponentialHistogramDataPoint_Min = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint_Min{}
},
}
protoPoolExponentialHistogramDataPoint_Max = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint_Max{}
},
}
)
func NewOrigExponentialHistogramDataPoint() *otlpmetrics.ExponentialHistogramDataPoint {
if !UseProtoPooling.IsEnabled() {
@ -44,11 +63,32 @@ func DeleteOrigExponentialHistogramDataPoint(orig *otlpmetrics.ExponentialHistog
for i := range orig.Attributes {
DeleteOrigKeyValue(&orig.Attributes[i], false)
}
switch ov := orig.Sum_.(type) {
case *otlpmetrics.ExponentialHistogramDataPoint_Sum:
if UseProtoPooling.IsEnabled() {
protoPoolExponentialHistogramDataPoint_Sum.Put(ov)
}
}
DeleteOrigExponentialHistogramDataPoint_Buckets(&orig.Positive, false)
DeleteOrigExponentialHistogramDataPoint_Buckets(&orig.Negative, false)
for i := range orig.Exemplars {
DeleteOrigExemplar(&orig.Exemplars[i], false)
}
switch ov := orig.Min_.(type) {
case *otlpmetrics.ExponentialHistogramDataPoint_Min:
if UseProtoPooling.IsEnabled() {
protoPoolExponentialHistogramDataPoint_Min.Put(ov)
}
}
switch ov := orig.Max_.(type) {
case *otlpmetrics.ExponentialHistogramDataPoint_Max:
if UseProtoPooling.IsEnabled() {
protoPoolExponentialHistogramDataPoint_Max.Put(ov)
}
}
orig.Reset()
if nullable {
@ -211,9 +251,14 @@ func UnmarshalJSONOrigExponentialHistogramDataPoint(orig *otlpmetrics.Exponentia
orig.Count = iter.ReadUint64()
case "sum":
{
ofm := &otlpmetrics.ExponentialHistogramDataPoint_Sum{}
ofm.Sum = iter.ReadFloat64()
orig.Sum_ = ofm
var ov *otlpmetrics.ExponentialHistogramDataPoint_Sum
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.ExponentialHistogramDataPoint_Sum{}
} else {
ov = protoPoolExponentialHistogramDataPoint_Sum.Get().(*otlpmetrics.ExponentialHistogramDataPoint_Sum)
}
ov.Sum = iter.ReadFloat64()
orig.Sum_ = ov
}
case "scale":
@ -234,16 +279,26 @@ func UnmarshalJSONOrigExponentialHistogramDataPoint(orig *otlpmetrics.Exponentia
case "min":
{
ofm := &otlpmetrics.ExponentialHistogramDataPoint_Min{}
ofm.Min = iter.ReadFloat64()
orig.Min_ = ofm
var ov *otlpmetrics.ExponentialHistogramDataPoint_Min
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.ExponentialHistogramDataPoint_Min{}
} else {
ov = protoPoolExponentialHistogramDataPoint_Min.Get().(*otlpmetrics.ExponentialHistogramDataPoint_Min)
}
ov.Min = iter.ReadFloat64()
orig.Min_ = ov
}
case "max":
{
ofm := &otlpmetrics.ExponentialHistogramDataPoint_Max{}
ofm.Max = iter.ReadFloat64()
orig.Max_ = ofm
var ov *otlpmetrics.ExponentialHistogramDataPoint_Max
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.ExponentialHistogramDataPoint_Max{}
} else {
ov = protoPoolExponentialHistogramDataPoint_Max.Get().(*otlpmetrics.ExponentialHistogramDataPoint_Max)
}
ov.Max = iter.ReadFloat64()
orig.Max_ = ov
}
case "zeroThreshold", "zero_threshold":
@ -474,9 +529,14 @@ func UnmarshalProtoOrigExponentialHistogramDataPoint(orig *otlpmetrics.Exponenti
if err != nil {
return err
}
ofv := &otlpmetrics.ExponentialHistogramDataPoint_Sum{}
ofv.Sum = math.Float64frombits(num)
orig.Sum_ = ofv
var ov *otlpmetrics.ExponentialHistogramDataPoint_Sum
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.ExponentialHistogramDataPoint_Sum{}
} else {
ov = protoPoolExponentialHistogramDataPoint_Sum.Get().(*otlpmetrics.ExponentialHistogramDataPoint_Sum)
}
ov.Sum = math.Float64frombits(num)
orig.Sum_ = ov
case 6:
if wireType != proto.WireTypeVarint {
@ -571,9 +631,14 @@ func UnmarshalProtoOrigExponentialHistogramDataPoint(orig *otlpmetrics.Exponenti
if err != nil {
return err
}
ofv := &otlpmetrics.ExponentialHistogramDataPoint_Min{}
ofv.Min = math.Float64frombits(num)
orig.Min_ = ofv
var ov *otlpmetrics.ExponentialHistogramDataPoint_Min
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.ExponentialHistogramDataPoint_Min{}
} else {
ov = protoPoolExponentialHistogramDataPoint_Min.Get().(*otlpmetrics.ExponentialHistogramDataPoint_Min)
}
ov.Min = math.Float64frombits(num)
orig.Min_ = ov
case 13:
if wireType != proto.WireTypeI64 {
@ -584,9 +649,14 @@ func UnmarshalProtoOrigExponentialHistogramDataPoint(orig *otlpmetrics.Exponenti
if err != nil {
return err
}
ofv := &otlpmetrics.ExponentialHistogramDataPoint_Max{}
ofv.Max = math.Float64frombits(num)
orig.Max_ = ofv
var ov *otlpmetrics.ExponentialHistogramDataPoint_Max
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.ExponentialHistogramDataPoint_Max{}
} else {
ov = protoPoolExponentialHistogramDataPoint_Max.Get().(*otlpmetrics.ExponentialHistogramDataPoint_Max)
}
ov.Max = math.Float64frombits(num)
orig.Max_ = ov
case 14:
if wireType != proto.WireTypeI64 {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExponentialHistogramDataPoint_Buckets = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint_Buckets{}
},
}
var (
protoPoolExponentialHistogramDataPoint_Buckets = sync.Pool{
New: func() any {
return &otlpmetrics.ExponentialHistogramDataPoint_Buckets{}
},
}
)
func NewOrigExponentialHistogramDataPoint_Buckets() *otlpmetrics.ExponentialHistogramDataPoint_Buckets {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportLogsPartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectorlogs.ExportLogsPartialSuccess{}
},
}
var (
protoPoolExportLogsPartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectorlogs.ExportLogsPartialSuccess{}
},
}
)
func NewOrigExportLogsPartialSuccess() *otlpcollectorlogs.ExportLogsPartialSuccess {
if !UseProtoPooling.IsEnabled() {

View File

@ -32,11 +32,13 @@ func NewLogs(orig *otlpcollectorlogs.ExportLogsServiceRequest, state *State) Log
return Logs{orig: orig, state: state}
}
var protoPoolExportLogsServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectorlogs.ExportLogsServiceRequest{}
},
}
var (
protoPoolExportLogsServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectorlogs.ExportLogsServiceRequest{}
},
}
)
func NewOrigExportLogsServiceRequest() *otlpcollectorlogs.ExportLogsServiceRequest {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportLogsServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectorlogs.ExportLogsServiceResponse{}
},
}
var (
protoPoolExportLogsServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectorlogs.ExportLogsServiceResponse{}
},
}
)
func NewOrigExportLogsServiceResponse() *otlpcollectorlogs.ExportLogsServiceResponse {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportMetricsPartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectormetrics.ExportMetricsPartialSuccess{}
},
}
var (
protoPoolExportMetricsPartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectormetrics.ExportMetricsPartialSuccess{}
},
}
)
func NewOrigExportMetricsPartialSuccess() *otlpcollectormetrics.ExportMetricsPartialSuccess {
if !UseProtoPooling.IsEnabled() {

View File

@ -32,11 +32,13 @@ func NewMetrics(orig *otlpcollectormetrics.ExportMetricsServiceRequest, state *S
return Metrics{orig: orig, state: state}
}
var protoPoolExportMetricsServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectormetrics.ExportMetricsServiceRequest{}
},
}
var (
protoPoolExportMetricsServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectormetrics.ExportMetricsServiceRequest{}
},
}
)
func NewOrigExportMetricsServiceRequest() *otlpcollectormetrics.ExportMetricsServiceRequest {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportMetricsServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectormetrics.ExportMetricsServiceResponse{}
},
}
var (
protoPoolExportMetricsServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectormetrics.ExportMetricsServiceResponse{}
},
}
)
func NewOrigExportMetricsServiceResponse() *otlpcollectormetrics.ExportMetricsServiceResponse {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportProfilesPartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectorprofiles.ExportProfilesPartialSuccess{}
},
}
var (
protoPoolExportProfilesPartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectorprofiles.ExportProfilesPartialSuccess{}
},
}
)
func NewOrigExportProfilesPartialSuccess() *otlpcollectorprofiles.ExportProfilesPartialSuccess {
if !UseProtoPooling.IsEnabled() {

View File

@ -32,11 +32,13 @@ func NewProfiles(orig *otlpcollectorprofiles.ExportProfilesServiceRequest, state
return Profiles{orig: orig, state: state}
}
var protoPoolExportProfilesServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectorprofiles.ExportProfilesServiceRequest{}
},
}
var (
protoPoolExportProfilesServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectorprofiles.ExportProfilesServiceRequest{}
},
}
)
func NewOrigExportProfilesServiceRequest() *otlpcollectorprofiles.ExportProfilesServiceRequest {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportProfilesServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectorprofiles.ExportProfilesServiceResponse{}
},
}
var (
protoPoolExportProfilesServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectorprofiles.ExportProfilesServiceResponse{}
},
}
)
func NewOrigExportProfilesServiceResponse() *otlpcollectorprofiles.ExportProfilesServiceResponse {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportTracePartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectortrace.ExportTracePartialSuccess{}
},
}
var (
protoPoolExportTracePartialSuccess = sync.Pool{
New: func() any {
return &otlpcollectortrace.ExportTracePartialSuccess{}
},
}
)
func NewOrigExportTracePartialSuccess() *otlpcollectortrace.ExportTracePartialSuccess {
if !UseProtoPooling.IsEnabled() {

View File

@ -32,11 +32,13 @@ func NewTraces(orig *otlpcollectortrace.ExportTraceServiceRequest, state *State)
return Traces{orig: orig, state: state}
}
var protoPoolExportTraceServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectortrace.ExportTraceServiceRequest{}
},
}
var (
protoPoolExportTraceServiceRequest = sync.Pool{
New: func() any {
return &otlpcollectortrace.ExportTraceServiceRequest{}
},
}
)
func NewOrigExportTraceServiceRequest() *otlpcollectortrace.ExportTraceServiceRequest {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolExportTraceServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectortrace.ExportTraceServiceResponse{}
},
}
var (
protoPoolExportTraceServiceResponse = sync.Pool{
New: func() any {
return &otlpcollectortrace.ExportTraceServiceResponse{}
},
}
)
func NewOrigExportTraceServiceResponse() *otlpcollectortrace.ExportTraceServiceResponse {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolFunction = sync.Pool{
New: func() any {
return &otlpprofiles.Function{}
},
}
var (
protoPoolFunction = sync.Pool{
New: func() any {
return &otlpprofiles.Function{}
},
}
)
func NewOrigFunction() *otlpprofiles.Function {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolGauge = sync.Pool{
New: func() any {
return &otlpmetrics.Gauge{}
},
}
var (
protoPoolGauge = sync.Pool{
New: func() any {
return &otlpmetrics.Gauge{}
},
}
)
func NewOrigGauge() *otlpmetrics.Gauge {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolHistogram = sync.Pool{
New: func() any {
return &otlpmetrics.Histogram{}
},
}
var (
protoPoolHistogram = sync.Pool{
New: func() any {
return &otlpmetrics.Histogram{}
},
}
)
func NewOrigHistogram() *otlpmetrics.Histogram {
if !UseProtoPooling.IsEnabled() {

View File

@ -18,11 +18,30 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolHistogramDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.HistogramDataPoint{}
},
}
var (
protoPoolHistogramDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.HistogramDataPoint{}
},
}
protoPoolHistogramDataPoint_Sum = sync.Pool{
New: func() any {
return &otlpmetrics.HistogramDataPoint_Sum{}
},
}
protoPoolHistogramDataPoint_Min = sync.Pool{
New: func() any {
return &otlpmetrics.HistogramDataPoint_Min{}
},
}
protoPoolHistogramDataPoint_Max = sync.Pool{
New: func() any {
return &otlpmetrics.HistogramDataPoint_Max{}
},
}
)
func NewOrigHistogramDataPoint() *otlpmetrics.HistogramDataPoint {
if !UseProtoPooling.IsEnabled() {
@ -44,9 +63,30 @@ func DeleteOrigHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint, nullable
for i := range orig.Attributes {
DeleteOrigKeyValue(&orig.Attributes[i], false)
}
switch ov := orig.Sum_.(type) {
case *otlpmetrics.HistogramDataPoint_Sum:
if UseProtoPooling.IsEnabled() {
protoPoolHistogramDataPoint_Sum.Put(ov)
}
}
for i := range orig.Exemplars {
DeleteOrigExemplar(&orig.Exemplars[i], false)
}
switch ov := orig.Min_.(type) {
case *otlpmetrics.HistogramDataPoint_Min:
if UseProtoPooling.IsEnabled() {
protoPoolHistogramDataPoint_Min.Put(ov)
}
}
switch ov := orig.Max_.(type) {
case *otlpmetrics.HistogramDataPoint_Max:
if UseProtoPooling.IsEnabled() {
protoPoolHistogramDataPoint_Max.Put(ov)
}
}
orig.Reset()
if nullable {
@ -207,9 +247,14 @@ func UnmarshalJSONOrigHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint, i
orig.Count = iter.ReadUint64()
case "sum":
{
ofm := &otlpmetrics.HistogramDataPoint_Sum{}
ofm.Sum = iter.ReadFloat64()
orig.Sum_ = ofm
var ov *otlpmetrics.HistogramDataPoint_Sum
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.HistogramDataPoint_Sum{}
} else {
ov = protoPoolHistogramDataPoint_Sum.Get().(*otlpmetrics.HistogramDataPoint_Sum)
}
ov.Sum = iter.ReadFloat64()
orig.Sum_ = ov
}
case "bucketCounts", "bucket_counts":
@ -232,16 +277,26 @@ func UnmarshalJSONOrigHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint, i
orig.Flags = iter.ReadUint32()
case "min":
{
ofm := &otlpmetrics.HistogramDataPoint_Min{}
ofm.Min = iter.ReadFloat64()
orig.Min_ = ofm
var ov *otlpmetrics.HistogramDataPoint_Min
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.HistogramDataPoint_Min{}
} else {
ov = protoPoolHistogramDataPoint_Min.Get().(*otlpmetrics.HistogramDataPoint_Min)
}
ov.Min = iter.ReadFloat64()
orig.Min_ = ov
}
case "max":
{
ofm := &otlpmetrics.HistogramDataPoint_Max{}
ofm.Max = iter.ReadFloat64()
orig.Max_ = ofm
var ov *otlpmetrics.HistogramDataPoint_Max
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.HistogramDataPoint_Max{}
} else {
ov = protoPoolHistogramDataPoint_Max.Get().(*otlpmetrics.HistogramDataPoint_Max)
}
ov.Max = iter.ReadFloat64()
orig.Max_ = ov
}
default:
@ -457,9 +512,14 @@ func UnmarshalProtoOrigHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint,
if err != nil {
return err
}
ofv := &otlpmetrics.HistogramDataPoint_Sum{}
ofv.Sum = math.Float64frombits(num)
orig.Sum_ = ofv
var ov *otlpmetrics.HistogramDataPoint_Sum
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.HistogramDataPoint_Sum{}
} else {
ov = protoPoolHistogramDataPoint_Sum.Get().(*otlpmetrics.HistogramDataPoint_Sum)
}
ov.Sum = math.Float64frombits(num)
orig.Sum_ = ov
case 6:
if wireType != proto.WireTypeLen {
return fmt.Errorf("proto: wrong wireType = %d for field BucketCounts", wireType)
@ -544,9 +604,14 @@ func UnmarshalProtoOrigHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint,
if err != nil {
return err
}
ofv := &otlpmetrics.HistogramDataPoint_Min{}
ofv.Min = math.Float64frombits(num)
orig.Min_ = ofv
var ov *otlpmetrics.HistogramDataPoint_Min
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.HistogramDataPoint_Min{}
} else {
ov = protoPoolHistogramDataPoint_Min.Get().(*otlpmetrics.HistogramDataPoint_Min)
}
ov.Min = math.Float64frombits(num)
orig.Min_ = ov
case 12:
if wireType != proto.WireTypeI64 {
@ -557,9 +622,14 @@ func UnmarshalProtoOrigHistogramDataPoint(orig *otlpmetrics.HistogramDataPoint,
if err != nil {
return err
}
ofv := &otlpmetrics.HistogramDataPoint_Max{}
ofv.Max = math.Float64frombits(num)
orig.Max_ = ofv
var ov *otlpmetrics.HistogramDataPoint_Max
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.HistogramDataPoint_Max{}
} else {
ov = protoPoolHistogramDataPoint_Max.Get().(*otlpmetrics.HistogramDataPoint_Max)
}
ov.Max = math.Float64frombits(num)
orig.Max_ = ov
default:
pos, err = proto.ConsumeUnknown(buf, pos, wireType)
if err != nil {

View File

@ -32,11 +32,13 @@ func NewInstrumentationScope(orig *otlpcommon.InstrumentationScope, state *State
return InstrumentationScope{orig: orig, state: state}
}
var protoPoolInstrumentationScope = sync.Pool{
New: func() any {
return &otlpcommon.InstrumentationScope{}
},
}
var (
protoPoolInstrumentationScope = sync.Pool{
New: func() any {
return &otlpcommon.InstrumentationScope{}
},
}
)
func NewOrigInstrumentationScope() *otlpcommon.InstrumentationScope {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolKeyValue = sync.Pool{
New: func() any {
return &otlpcommon.KeyValue{}
},
}
var (
protoPoolKeyValue = sync.Pool{
New: func() any {
return &otlpcommon.KeyValue{}
},
}
)
func NewOrigKeyValue() *otlpcommon.KeyValue {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolKeyValueList = sync.Pool{
New: func() any {
return &otlpcommon.KeyValueList{}
},
}
var (
protoPoolKeyValueList = sync.Pool{
New: func() any {
return &otlpcommon.KeyValueList{}
},
}
)
func NewOrigKeyValueList() *otlpcommon.KeyValueList {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolLine = sync.Pool{
New: func() any {
return &otlpprofiles.Line{}
},
}
var (
protoPoolLine = sync.Pool{
New: func() any {
return &otlpprofiles.Line{}
},
}
)
func NewOrigLine() *otlpprofiles.Line {
if !UseProtoPooling.IsEnabled() {

View File

@ -16,11 +16,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolLink = sync.Pool{
New: func() any {
return &otlpprofiles.Link{}
},
}
var (
protoPoolLink = sync.Pool{
New: func() any {
return &otlpprofiles.Link{}
},
}
)
func NewOrigLink() *otlpprofiles.Link {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,18 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolLocation = sync.Pool{
New: func() any {
return &otlpprofiles.Location{}
},
}
var (
protoPoolLocation = sync.Pool{
New: func() any {
return &otlpprofiles.Location{}
},
}
protoPoolLocation_MappingIndex = sync.Pool{
New: func() any {
return &otlpprofiles.Location_MappingIndex{}
},
}
)
func NewOrigLocation() *otlpprofiles.Location {
if !UseProtoPooling.IsEnabled() {
@ -38,6 +45,13 @@ func DeleteOrigLocation(orig *otlpprofiles.Location, nullable bool) {
return
}
switch ov := orig.MappingIndex_.(type) {
case *otlpprofiles.Location_MappingIndex:
if UseProtoPooling.IsEnabled() {
protoPoolLocation_MappingIndex.Put(ov)
}
}
for i := range orig.Line {
DeleteOrigLine(orig.Line[i], true)
}
@ -123,9 +137,14 @@ func UnmarshalJSONOrigLocation(orig *otlpprofiles.Location, iter *json.Iterator)
switch f {
case "mappingIndex", "mapping_index":
{
ofm := &otlpprofiles.Location_MappingIndex{}
ofm.MappingIndex = iter.ReadInt32()
orig.MappingIndex_ = ofm
var ov *otlpprofiles.Location_MappingIndex
if !UseProtoPooling.IsEnabled() {
ov = &otlpprofiles.Location_MappingIndex{}
} else {
ov = protoPoolLocation_MappingIndex.Get().(*otlpprofiles.Location_MappingIndex)
}
ov.MappingIndex = iter.ReadInt32()
orig.MappingIndex_ = ov
}
case "address":
@ -245,9 +264,14 @@ func UnmarshalProtoOrigLocation(orig *otlpprofiles.Location, buf []byte) error {
if err != nil {
return err
}
ofv := &otlpprofiles.Location_MappingIndex{}
ofv.MappingIndex = int32(num)
orig.MappingIndex_ = ofv
var ov *otlpprofiles.Location_MappingIndex
if !UseProtoPooling.IsEnabled() {
ov = &otlpprofiles.Location_MappingIndex{}
} else {
ov = protoPoolLocation_MappingIndex.Get().(*otlpprofiles.Location_MappingIndex)
}
ov.MappingIndex = int32(num)
orig.MappingIndex_ = ov
case 2:
if wireType != proto.WireTypeVarint {

View File

@ -18,11 +18,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolLogRecord = sync.Pool{
New: func() any {
return &otlplogs.LogRecord{}
},
}
var (
protoPoolLogRecord = sync.Pool{
New: func() any {
return &otlplogs.LogRecord{}
},
}
)
func NewOrigLogRecord() *otlplogs.LogRecord {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolMapping = sync.Pool{
New: func() any {
return &otlpprofiles.Mapping{}
},
}
var (
protoPoolMapping = sync.Pool{
New: func() any {
return &otlpprofiles.Mapping{}
},
}
)
func NewOrigMapping() *otlpprofiles.Mapping {
if !UseProtoPooling.IsEnabled() {

View File

@ -16,11 +16,43 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolMetric = sync.Pool{
New: func() any {
return &otlpmetrics.Metric{}
},
}
var (
protoPoolMetric = sync.Pool{
New: func() any {
return &otlpmetrics.Metric{}
},
}
protoPoolMetric_Gauge = sync.Pool{
New: func() any {
return &otlpmetrics.Metric_Gauge{}
},
}
protoPoolMetric_Sum = sync.Pool{
New: func() any {
return &otlpmetrics.Metric_Sum{}
},
}
protoPoolMetric_Histogram = sync.Pool{
New: func() any {
return &otlpmetrics.Metric_Histogram{}
},
}
protoPoolMetric_ExponentialHistogram = sync.Pool{
New: func() any {
return &otlpmetrics.Metric_ExponentialHistogram{}
},
}
protoPoolMetric_Summary = sync.Pool{
New: func() any {
return &otlpmetrics.Metric_Summary{}
},
}
)
func NewOrigMetric() *otlpmetrics.Metric {
if !UseProtoPooling.IsEnabled() {
@ -41,14 +73,29 @@ func DeleteOrigMetric(orig *otlpmetrics.Metric, nullable bool) {
switch ov := orig.Data.(type) {
case *otlpmetrics.Metric_Gauge:
if UseProtoPooling.IsEnabled() {
protoPoolMetric_Gauge.Put(ov)
}
DeleteOrigGauge(ov.Gauge, true)
case *otlpmetrics.Metric_Sum:
if UseProtoPooling.IsEnabled() {
protoPoolMetric_Sum.Put(ov)
}
DeleteOrigSum(ov.Sum, true)
case *otlpmetrics.Metric_Histogram:
if UseProtoPooling.IsEnabled() {
protoPoolMetric_Histogram.Put(ov)
}
DeleteOrigHistogram(ov.Histogram, true)
case *otlpmetrics.Metric_ExponentialHistogram:
if UseProtoPooling.IsEnabled() {
protoPoolMetric_ExponentialHistogram.Put(ov)
}
DeleteOrigExponentialHistogram(ov.ExponentialHistogram, true)
case *otlpmetrics.Metric_Summary:
if UseProtoPooling.IsEnabled() {
protoPoolMetric_Summary.Put(ov)
}
DeleteOrigSummary(ov.Summary, true)
}
@ -183,42 +230,67 @@ func UnmarshalJSONOrigMetric(orig *otlpmetrics.Metric, iter *json.Iterator) {
case "gauge":
{
ofm := &otlpmetrics.Metric_Gauge{}
ofm.Gauge = NewOrigGauge()
UnmarshalJSONOrigGauge(ofm.Gauge, iter)
orig.Data = ofm
var ov *otlpmetrics.Metric_Gauge
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Gauge{}
} else {
ov = protoPoolMetric_Gauge.Get().(*otlpmetrics.Metric_Gauge)
}
ov.Gauge = NewOrigGauge()
UnmarshalJSONOrigGauge(ov.Gauge, iter)
orig.Data = ov
}
case "sum":
{
ofm := &otlpmetrics.Metric_Sum{}
ofm.Sum = NewOrigSum()
UnmarshalJSONOrigSum(ofm.Sum, iter)
orig.Data = ofm
var ov *otlpmetrics.Metric_Sum
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Sum{}
} else {
ov = protoPoolMetric_Sum.Get().(*otlpmetrics.Metric_Sum)
}
ov.Sum = NewOrigSum()
UnmarshalJSONOrigSum(ov.Sum, iter)
orig.Data = ov
}
case "histogram":
{
ofm := &otlpmetrics.Metric_Histogram{}
ofm.Histogram = NewOrigHistogram()
UnmarshalJSONOrigHistogram(ofm.Histogram, iter)
orig.Data = ofm
var ov *otlpmetrics.Metric_Histogram
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Histogram{}
} else {
ov = protoPoolMetric_Histogram.Get().(*otlpmetrics.Metric_Histogram)
}
ov.Histogram = NewOrigHistogram()
UnmarshalJSONOrigHistogram(ov.Histogram, iter)
orig.Data = ov
}
case "exponentialHistogram", "exponential_histogram":
{
ofm := &otlpmetrics.Metric_ExponentialHistogram{}
ofm.ExponentialHistogram = NewOrigExponentialHistogram()
UnmarshalJSONOrigExponentialHistogram(ofm.ExponentialHistogram, iter)
orig.Data = ofm
var ov *otlpmetrics.Metric_ExponentialHistogram
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_ExponentialHistogram{}
} else {
ov = protoPoolMetric_ExponentialHistogram.Get().(*otlpmetrics.Metric_ExponentialHistogram)
}
ov.ExponentialHistogram = NewOrigExponentialHistogram()
UnmarshalJSONOrigExponentialHistogram(ov.ExponentialHistogram, iter)
orig.Data = ov
}
case "summary":
{
ofm := &otlpmetrics.Metric_Summary{}
ofm.Summary = NewOrigSummary()
UnmarshalJSONOrigSummary(ofm.Summary, iter)
orig.Data = ofm
var ov *otlpmetrics.Metric_Summary
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Summary{}
} else {
ov = protoPoolMetric_Summary.Get().(*otlpmetrics.Metric_Summary)
}
ov.Summary = NewOrigSummary()
UnmarshalJSONOrigSummary(ov.Summary, iter)
orig.Data = ov
}
case "metadata":
@ -414,13 +486,18 @@ func UnmarshalProtoOrigMetric(orig *otlpmetrics.Metric, buf []byte) error {
return err
}
startPos := pos - length
ofv := &otlpmetrics.Metric_Gauge{}
ofv.Gauge = NewOrigGauge()
err = UnmarshalProtoOrigGauge(ofv.Gauge, buf[startPos:pos])
var ov *otlpmetrics.Metric_Gauge
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Gauge{}
} else {
ov = protoPoolMetric_Gauge.Get().(*otlpmetrics.Metric_Gauge)
}
ov.Gauge = NewOrigGauge()
err = UnmarshalProtoOrigGauge(ov.Gauge, buf[startPos:pos])
if err != nil {
return err
}
orig.Data = ofv
orig.Data = ov
case 7:
if wireType != proto.WireTypeLen {
@ -432,13 +509,18 @@ func UnmarshalProtoOrigMetric(orig *otlpmetrics.Metric, buf []byte) error {
return err
}
startPos := pos - length
ofv := &otlpmetrics.Metric_Sum{}
ofv.Sum = NewOrigSum()
err = UnmarshalProtoOrigSum(ofv.Sum, buf[startPos:pos])
var ov *otlpmetrics.Metric_Sum
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Sum{}
} else {
ov = protoPoolMetric_Sum.Get().(*otlpmetrics.Metric_Sum)
}
ov.Sum = NewOrigSum()
err = UnmarshalProtoOrigSum(ov.Sum, buf[startPos:pos])
if err != nil {
return err
}
orig.Data = ofv
orig.Data = ov
case 9:
if wireType != proto.WireTypeLen {
@ -450,13 +532,18 @@ func UnmarshalProtoOrigMetric(orig *otlpmetrics.Metric, buf []byte) error {
return err
}
startPos := pos - length
ofv := &otlpmetrics.Metric_Histogram{}
ofv.Histogram = NewOrigHistogram()
err = UnmarshalProtoOrigHistogram(ofv.Histogram, buf[startPos:pos])
var ov *otlpmetrics.Metric_Histogram
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Histogram{}
} else {
ov = protoPoolMetric_Histogram.Get().(*otlpmetrics.Metric_Histogram)
}
ov.Histogram = NewOrigHistogram()
err = UnmarshalProtoOrigHistogram(ov.Histogram, buf[startPos:pos])
if err != nil {
return err
}
orig.Data = ofv
orig.Data = ov
case 10:
if wireType != proto.WireTypeLen {
@ -468,13 +555,18 @@ func UnmarshalProtoOrigMetric(orig *otlpmetrics.Metric, buf []byte) error {
return err
}
startPos := pos - length
ofv := &otlpmetrics.Metric_ExponentialHistogram{}
ofv.ExponentialHistogram = NewOrigExponentialHistogram()
err = UnmarshalProtoOrigExponentialHistogram(ofv.ExponentialHistogram, buf[startPos:pos])
var ov *otlpmetrics.Metric_ExponentialHistogram
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_ExponentialHistogram{}
} else {
ov = protoPoolMetric_ExponentialHistogram.Get().(*otlpmetrics.Metric_ExponentialHistogram)
}
ov.ExponentialHistogram = NewOrigExponentialHistogram()
err = UnmarshalProtoOrigExponentialHistogram(ov.ExponentialHistogram, buf[startPos:pos])
if err != nil {
return err
}
orig.Data = ofv
orig.Data = ov
case 11:
if wireType != proto.WireTypeLen {
@ -486,13 +578,18 @@ func UnmarshalProtoOrigMetric(orig *otlpmetrics.Metric, buf []byte) error {
return err
}
startPos := pos - length
ofv := &otlpmetrics.Metric_Summary{}
ofv.Summary = NewOrigSummary()
err = UnmarshalProtoOrigSummary(ofv.Summary, buf[startPos:pos])
var ov *otlpmetrics.Metric_Summary
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.Metric_Summary{}
} else {
ov = protoPoolMetric_Summary.Get().(*otlpmetrics.Metric_Summary)
}
ov.Summary = NewOrigSummary()
err = UnmarshalProtoOrigSummary(ov.Summary, buf[startPos:pos])
if err != nil {
return err
}
orig.Data = ofv
orig.Data = ov
case 12:
if wireType != proto.WireTypeLen {

View File

@ -18,11 +18,25 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolNumberDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.NumberDataPoint{}
},
}
var (
protoPoolNumberDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.NumberDataPoint{}
},
}
protoPoolNumberDataPoint_AsDouble = sync.Pool{
New: func() any {
return &otlpmetrics.NumberDataPoint_AsDouble{}
},
}
protoPoolNumberDataPoint_AsInt = sync.Pool{
New: func() any {
return &otlpmetrics.NumberDataPoint_AsInt{}
},
}
)
func NewOrigNumberDataPoint() *otlpmetrics.NumberDataPoint {
if !UseProtoPooling.IsEnabled() {
@ -44,6 +58,17 @@ func DeleteOrigNumberDataPoint(orig *otlpmetrics.NumberDataPoint, nullable bool)
for i := range orig.Attributes {
DeleteOrigKeyValue(&orig.Attributes[i], false)
}
switch ov := orig.Value.(type) {
case *otlpmetrics.NumberDataPoint_AsDouble:
if UseProtoPooling.IsEnabled() {
protoPoolNumberDataPoint_AsDouble.Put(ov)
}
case *otlpmetrics.NumberDataPoint_AsInt:
if UseProtoPooling.IsEnabled() {
protoPoolNumberDataPoint_AsInt.Put(ov)
}
}
for i := range orig.Exemplars {
DeleteOrigExemplar(&orig.Exemplars[i], false)
}
@ -146,16 +171,26 @@ func UnmarshalJSONOrigNumberDataPoint(orig *otlpmetrics.NumberDataPoint, iter *j
case "asDouble", "as_double":
{
ofm := &otlpmetrics.NumberDataPoint_AsDouble{}
ofm.AsDouble = iter.ReadFloat64()
orig.Value = ofm
var ov *otlpmetrics.NumberDataPoint_AsDouble
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.NumberDataPoint_AsDouble{}
} else {
ov = protoPoolNumberDataPoint_AsDouble.Get().(*otlpmetrics.NumberDataPoint_AsDouble)
}
ov.AsDouble = iter.ReadFloat64()
orig.Value = ov
}
case "asInt", "as_int":
{
ofm := &otlpmetrics.NumberDataPoint_AsInt{}
ofm.AsInt = iter.ReadInt64()
orig.Value = ofm
var ov *otlpmetrics.NumberDataPoint_AsInt
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.NumberDataPoint_AsInt{}
} else {
ov = protoPoolNumberDataPoint_AsInt.Get().(*otlpmetrics.NumberDataPoint_AsInt)
}
ov.AsInt = iter.ReadInt64()
orig.Value = ov
}
case "exemplars":
@ -318,9 +353,14 @@ func UnmarshalProtoOrigNumberDataPoint(orig *otlpmetrics.NumberDataPoint, buf []
if err != nil {
return err
}
ofv := &otlpmetrics.NumberDataPoint_AsDouble{}
ofv.AsDouble = math.Float64frombits(num)
orig.Value = ofv
var ov *otlpmetrics.NumberDataPoint_AsDouble
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.NumberDataPoint_AsDouble{}
} else {
ov = protoPoolNumberDataPoint_AsDouble.Get().(*otlpmetrics.NumberDataPoint_AsDouble)
}
ov.AsDouble = math.Float64frombits(num)
orig.Value = ov
case 6:
if wireType != proto.WireTypeI64 {
@ -331,9 +371,14 @@ func UnmarshalProtoOrigNumberDataPoint(orig *otlpmetrics.NumberDataPoint, buf []
if err != nil {
return err
}
ofv := &otlpmetrics.NumberDataPoint_AsInt{}
ofv.AsInt = int64(num)
orig.Value = ofv
var ov *otlpmetrics.NumberDataPoint_AsInt
if !UseProtoPooling.IsEnabled() {
ov = &otlpmetrics.NumberDataPoint_AsInt{}
} else {
ov = protoPoolNumberDataPoint_AsInt.Get().(*otlpmetrics.NumberDataPoint_AsInt)
}
ov.AsInt = int64(num)
orig.Value = ov
case 5:
if wireType != proto.WireTypeLen {

View File

@ -16,11 +16,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolProfile = sync.Pool{
New: func() any {
return &otlpprofiles.Profile{}
},
}
var (
protoPoolProfile = sync.Pool{
New: func() any {
return &otlpprofiles.Profile{}
},
}
)
func NewOrigProfile() *otlpprofiles.Profile {
if !UseProtoPooling.IsEnabled() {

View File

@ -16,11 +16,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolProfilesDictionary = sync.Pool{
New: func() any {
return &otlpprofiles.ProfilesDictionary{}
},
}
var (
protoPoolProfilesDictionary = sync.Pool{
New: func() any {
return &otlpprofiles.ProfilesDictionary{}
},
}
)
func NewOrigProfilesDictionary() *otlpprofiles.ProfilesDictionary {
if !UseProtoPooling.IsEnabled() {

View File

@ -33,11 +33,13 @@ func NewResource(orig *otlpresource.Resource, state *State) Resource {
return Resource{orig: orig, state: state}
}
var protoPoolResource = sync.Pool{
New: func() any {
return &otlpresource.Resource{}
},
}
var (
protoPoolResource = sync.Pool{
New: func() any {
return &otlpresource.Resource{}
},
}
)
func NewOrigResource() *otlpresource.Resource {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolResourceLogs = sync.Pool{
New: func() any {
return &otlplogs.ResourceLogs{}
},
}
var (
protoPoolResourceLogs = sync.Pool{
New: func() any {
return &otlplogs.ResourceLogs{}
},
}
)
func NewOrigResourceLogs() *otlplogs.ResourceLogs {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolResourceMetrics = sync.Pool{
New: func() any {
return &otlpmetrics.ResourceMetrics{}
},
}
var (
protoPoolResourceMetrics = sync.Pool{
New: func() any {
return &otlpmetrics.ResourceMetrics{}
},
}
)
func NewOrigResourceMetrics() *otlpmetrics.ResourceMetrics {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolResourceProfiles = sync.Pool{
New: func() any {
return &otlpprofiles.ResourceProfiles{}
},
}
var (
protoPoolResourceProfiles = sync.Pool{
New: func() any {
return &otlpprofiles.ResourceProfiles{}
},
}
)
func NewOrigResourceProfiles() *otlpprofiles.ResourceProfiles {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolResourceSpans = sync.Pool{
New: func() any {
return &otlptrace.ResourceSpans{}
},
}
var (
protoPoolResourceSpans = sync.Pool{
New: func() any {
return &otlptrace.ResourceSpans{}
},
}
)
func NewOrigResourceSpans() *otlptrace.ResourceSpans {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,18 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSample = sync.Pool{
New: func() any {
return &otlpprofiles.Sample{}
},
}
var (
protoPoolSample = sync.Pool{
New: func() any {
return &otlpprofiles.Sample{}
},
}
protoPoolSample_LinkIndex = sync.Pool{
New: func() any {
return &otlpprofiles.Sample_LinkIndex{}
},
}
)
func NewOrigSample() *otlpprofiles.Sample {
if !UseProtoPooling.IsEnabled() {
@ -38,6 +45,14 @@ func DeleteOrigSample(orig *otlpprofiles.Sample, nullable bool) {
return
}
switch ov := orig.LinkIndex_.(type) {
case *otlpprofiles.Sample_LinkIndex:
if UseProtoPooling.IsEnabled() {
protoPoolSample_LinkIndex.Put(ov)
}
}
orig.Reset()
if nullable {
protoPoolSample.Put(orig)
@ -145,9 +160,14 @@ func UnmarshalJSONOrigSample(orig *otlpprofiles.Sample, iter *json.Iterator) {
case "linkIndex", "link_index":
{
ofm := &otlpprofiles.Sample_LinkIndex{}
ofm.LinkIndex = iter.ReadInt32()
orig.LinkIndex_ = ofm
var ov *otlpprofiles.Sample_LinkIndex
if !UseProtoPooling.IsEnabled() {
ov = &otlpprofiles.Sample_LinkIndex{}
} else {
ov = protoPoolSample_LinkIndex.Get().(*otlpprofiles.Sample_LinkIndex)
}
ov.LinkIndex = iter.ReadInt32()
orig.LinkIndex_ = ov
}
case "timestampsUnixNano", "timestamps_unix_nano":
@ -341,9 +361,14 @@ func UnmarshalProtoOrigSample(orig *otlpprofiles.Sample, buf []byte) error {
if err != nil {
return err
}
ofv := &otlpprofiles.Sample_LinkIndex{}
ofv.LinkIndex = int32(num)
orig.LinkIndex_ = ofv
var ov *otlpprofiles.Sample_LinkIndex
if !UseProtoPooling.IsEnabled() {
ov = &otlpprofiles.Sample_LinkIndex{}
} else {
ov = protoPoolSample_LinkIndex.Get().(*otlpprofiles.Sample_LinkIndex)
}
ov.LinkIndex = int32(num)
orig.LinkIndex_ = ov
case 6:
if wireType != proto.WireTypeLen {
return fmt.Errorf("proto: wrong wireType = %d for field TimestampsUnixNano", wireType)

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolScopeLogs = sync.Pool{
New: func() any {
return &otlplogs.ScopeLogs{}
},
}
var (
protoPoolScopeLogs = sync.Pool{
New: func() any {
return &otlplogs.ScopeLogs{}
},
}
)
func NewOrigScopeLogs() *otlplogs.ScopeLogs {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolScopeMetrics = sync.Pool{
New: func() any {
return &otlpmetrics.ScopeMetrics{}
},
}
var (
protoPoolScopeMetrics = sync.Pool{
New: func() any {
return &otlpmetrics.ScopeMetrics{}
},
}
)
func NewOrigScopeMetrics() *otlpmetrics.ScopeMetrics {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolScopeProfiles = sync.Pool{
New: func() any {
return &otlpprofiles.ScopeProfiles{}
},
}
var (
protoPoolScopeProfiles = sync.Pool{
New: func() any {
return &otlpprofiles.ScopeProfiles{}
},
}
)
func NewOrigScopeProfiles() *otlpprofiles.ScopeProfiles {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolScopeSpans = sync.Pool{
New: func() any {
return &otlptrace.ScopeSpans{}
},
}
var (
protoPoolScopeSpans = sync.Pool{
New: func() any {
return &otlptrace.ScopeSpans{}
},
}
)
func NewOrigScopeSpans() *otlptrace.ScopeSpans {
if !UseProtoPooling.IsEnabled() {

View File

@ -18,11 +18,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSpan = sync.Pool{
New: func() any {
return &otlptrace.Span{}
},
}
var (
protoPoolSpan = sync.Pool{
New: func() any {
return &otlptrace.Span{}
},
}
)
func NewOrigSpan() *otlptrace.Span {
if !UseProtoPooling.IsEnabled() {

View File

@ -17,11 +17,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSpan_Event = sync.Pool{
New: func() any {
return &otlptrace.Span_Event{}
},
}
var (
protoPoolSpan_Event = sync.Pool{
New: func() any {
return &otlptrace.Span_Event{}
},
}
)
func NewOrigSpan_Event() *otlptrace.Span_Event {
if !UseProtoPooling.IsEnabled() {

View File

@ -18,11 +18,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSpan_Link = sync.Pool{
New: func() any {
return &otlptrace.Span_Link{}
},
}
var (
protoPoolSpan_Link = sync.Pool{
New: func() any {
return &otlptrace.Span_Link{}
},
}
)
func NewOrigSpan_Link() *otlptrace.Span_Link {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolStatus = sync.Pool{
New: func() any {
return &otlptrace.Status{}
},
}
var (
protoPoolStatus = sync.Pool{
New: func() any {
return &otlptrace.Status{}
},
}
)
func NewOrigStatus() *otlptrace.Status {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSum = sync.Pool{
New: func() any {
return &otlpmetrics.Sum{}
},
}
var (
protoPoolSum = sync.Pool{
New: func() any {
return &otlpmetrics.Sum{}
},
}
)
func NewOrigSum() *otlpmetrics.Sum {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSummary = sync.Pool{
New: func() any {
return &otlpmetrics.Summary{}
},
}
var (
protoPoolSummary = sync.Pool{
New: func() any {
return &otlpmetrics.Summary{}
},
}
)
func NewOrigSummary() *otlpmetrics.Summary {
if !UseProtoPooling.IsEnabled() {

View File

@ -18,11 +18,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSummaryDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.SummaryDataPoint{}
},
}
var (
protoPoolSummaryDataPoint = sync.Pool{
New: func() any {
return &otlpmetrics.SummaryDataPoint{}
},
}
)
func NewOrigSummaryDataPoint() *otlpmetrics.SummaryDataPoint {
if !UseProtoPooling.IsEnabled() {

View File

@ -17,11 +17,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolSummaryDataPoint_ValueAtQuantile = sync.Pool{
New: func() any {
return &otlpmetrics.SummaryDataPoint_ValueAtQuantile{}
},
}
var (
protoPoolSummaryDataPoint_ValueAtQuantile = sync.Pool{
New: func() any {
return &otlpmetrics.SummaryDataPoint_ValueAtQuantile{}
},
}
)
func NewOrigSummaryDataPoint_ValueAtQuantile() *otlpmetrics.SummaryDataPoint_ValueAtQuantile {
if !UseProtoPooling.IsEnabled() {

View File

@ -15,11 +15,13 @@ import (
"go.opentelemetry.io/collector/pdata/internal/proto"
)
var protoPoolValueType = sync.Pool{
New: func() any {
return &otlpprofiles.ValueType{}
},
}
var (
protoPoolValueType = sync.Pool{
New: func() any {
return &otlpprofiles.ValueType{}
},
}
)
func NewOrigValueType() *otlpprofiles.ValueType {
if !UseProtoPooling.IsEnabled() {

View File

@ -68,7 +68,7 @@ func TestReadKvlistValueInvalidArrayValue(t *testing.T) {
func TestCopyOrigAnyValueAllTypes(t *testing.T) {
for name, src := range allAnyValues() {
for _, pooling := range []bool{true, false} {
t.Run(name+"pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
t.Run(name+"/pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
prevPooling := UseProtoPooling.IsEnabled()
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
defer func() {
@ -87,7 +87,7 @@ func TestCopyOrigAnyValueAllTypes(t *testing.T) {
func TestMarshalAndUnmarshalJSONOrigAnyValue(t *testing.T) {
for name, src := range allAnyValues() {
for _, pooling := range []bool{true, false} {
t.Run(name+"pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
t.Run(name+"/pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
prevPooling := UseProtoPooling.IsEnabled()
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
defer func() {
@ -131,7 +131,7 @@ func TestMarshalAndUnmarshalProtoOrigAnyValueFailing(t *testing.T) {
func TestMarshalAndUnmarshalProtoAnyValue(t *testing.T) {
for name, src := range allAnyValues() {
for _, pooling := range []bool{true, false} {
t.Run(name+"pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
t.Run(name+"/pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
prevPooling := UseProtoPooling.IsEnabled()
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
defer func() {