Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add clonevt methods #87

Merged
merged 4 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions input/elasticapm/internal/modeldecoder/rumv3/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder/modeldecoderutil"
"github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder/nullable"
"github.com/elastic/apm-data/model/modelpb"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down Expand Up @@ -107,7 +106,7 @@ func DecodeNestedError(d decoder.Decoder, input *modeldecoder.Input, batch *mode
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
mapToErrorModel(&root.Error, event)
*batch = append(*batch, event)
return nil
Expand All @@ -126,12 +125,12 @@ func DecodeNestedTransaction(d decoder.Decoder, input *modeldecoder.Input, batch
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
transaction := proto.Clone(input.Base).(*modelpb.APMEvent)
transaction := input.Base.CloneVT()
mapToTransactionModel(&root.Transaction, transaction)
*batch = append(*batch, transaction)

for _, m := range root.Transaction.Metricsets {
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
event.Transaction = &modelpb.Transaction{
Name: transaction.Transaction.Name,
Type: transaction.Transaction.Type,
Expand All @@ -143,7 +142,7 @@ func DecodeNestedTransaction(d decoder.Decoder, input *modeldecoder.Input, batch

offset := len(*batch)
for _, s := range root.Transaction.Spans {
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
mapToSpanModel(&s, event)
event.Transaction = &modelpb.Transaction{Id: transaction.Transaction.Id}
event.Parent = &modelpb.Parent{
Expand Down
11 changes: 5 additions & 6 deletions input/elasticapm/internal/modeldecoder/v2/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder/nullable"
"github.com/elastic/apm-data/input/otlp"
"github.com/elastic/apm-data/model/modelpb"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"

Expand Down Expand Up @@ -179,7 +178,7 @@ func DecodeNestedError(d decoder.Decoder, input *modeldecoder.Input, batch *mode
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
mapToErrorModel(&root.Error, event)
*batch = append(*batch, event)
return err
Expand All @@ -198,7 +197,7 @@ func DecodeNestedMetricset(d decoder.Decoder, input *modeldecoder.Input, batch *
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
if mapToMetricsetModel(&root.Metricset, event) {
*batch = append(*batch, event)
}
Expand All @@ -218,7 +217,7 @@ func DecodeNestedSpan(d decoder.Decoder, input *modeldecoder.Input, batch *model
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
mapToSpanModel(&root.Span, event)
*batch = append(*batch, event)
return err
Expand All @@ -237,7 +236,7 @@ func DecodeNestedTransaction(d decoder.Decoder, input *modeldecoder.Input, batch
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
mapToTransactionModel(&root.Transaction, event)
*batch = append(*batch, event)
return err
Expand All @@ -260,7 +259,7 @@ func DecodeNestedLog(d decoder.Decoder, input *modeldecoder.Input, batch *modelp
if err := root.validate(); err != nil {
return modeldecoder.NewValidationErr(err)
}
event := proto.Clone(input.Base).(*modelpb.APMEvent)
event := input.Base.CloneVT()
mapToLogModel(&root.Log, event)
*batch = append(*batch, event)
return err
Expand Down
16 changes: 1 addition & 15 deletions input/elasticapm/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"go.elastic.co/apm/v2"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"

"github.com/elastic/apm-data/input"
"github.com/elastic/apm-data/input/elasticapm/internal/decoder"
Expand Down Expand Up @@ -196,7 +195,7 @@ func (p *Processor) readBatch(
}
// We copy the event for each iteration of the batch, as to avoid
// shallow copies of Labels and NumericLabels.
input := modeldecoder.Input{Base: copyEvent(baseEvent)}
input := modeldecoder.Input{Base: baseEvent}
switch eventType := p.identifyEventType(body); string(eventType) {
case errorEventType:
err = v2.DecodeNestedError(reader, &input, batch)
Expand Down Expand Up @@ -424,16 +423,3 @@ func (sr *streamReader) wrapError(err error) error {
}
return err
}

// copyEvent returns a shallow copy of the APMEvent with a deep copy of the
// labels and numeric labels.
func copyEvent(e *modelpb.APMEvent) *modelpb.APMEvent {
out := proto.Clone(e).(*modelpb.APMEvent)
if out.Labels != nil {
out.Labels = modelpb.Labels(out.Labels).Clone()
}
if out.NumericLabels != nil {
out.NumericLabels = modelpb.NumericLabels(out.NumericLabels).Clone()
}
return out
}
3 changes: 1 addition & 2 deletions input/otlp/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
semconv "go.opentelemetry.io/collector/semconv/v1.5.0"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/elastic/apm-data/model/modelpb"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (c *Consumer) convertLogRecord(
baseEvent *modelpb.APMEvent,
timeDelta time.Duration,
) *modelpb.APMEvent {
event := proto.Clone(baseEvent).(*modelpb.APMEvent)
event := baseEvent.CloneVT()
initEventLabels(event)
event.Timestamp = timestamppb.New(record.Timestamp().AsTime().Add(timeDelta))
event.Event = populateNil(event.Event)
Expand Down
3 changes: 1 addition & 2 deletions input/otlp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/elastic/apm-data/model/modelpb"
Expand Down Expand Up @@ -102,7 +101,7 @@ func (c *Consumer) convertScopeMetrics(
}
}
for key, ms := range ms {
event := proto.Clone(baseEvent).(*modelpb.APMEvent)
event := baseEvent.CloneVT()
event.Processor = modelpb.MetricsetProcessor()
event.Timestamp = timestamppb.New(key.timestamp.Add(timeDelta))
metrs := make([]*modelpb.MetricsetSample, 0, len(ms.samples))
Expand Down
6 changes: 3 additions & 3 deletions input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (c *Consumer) convertSpan(
name := otelSpan.Name()
spanID := hexSpanID(otelSpan.SpanID())
representativeCount := getRepresentativeCountFromTracestateHeader(otelSpan.TraceState().AsRaw())
event := proto.Clone(baseEvent).(*modelpb.APMEvent)
event := baseEvent.CloneVT()
initEventLabels(event)
event.Timestamp = timestamppb.New(startTime.Add(timeDelta))
if id := hexTraceID(otelSpan.TraceID()); id != "" {
Expand Down Expand Up @@ -193,7 +193,7 @@ func (c *Consumer) convertSpan(
*out = append(*out, event)

events := otelSpan.Events()
event = proto.Clone(event).(*modelpb.APMEvent)
event = event.CloneVT()
event.Labels = baseEvent.Labels // only copy common labels to span events
event.NumericLabels = baseEvent.NumericLabels // only copy common labels to span events
event.Event = nil // don't copy event.* to span events
Expand Down Expand Up @@ -872,7 +872,7 @@ func (c *Consumer) convertSpanEvent(
parent *modelpb.APMEvent, // either span or transaction
timeDelta time.Duration,
) *modelpb.APMEvent {
event := proto.Clone(parent).(*modelpb.APMEvent)
event := parent.CloneVT()
initEventLabels(event)
event.Transaction = nil // populate fields as required from parent
event.Span = nil // populate fields as required from parent
Expand Down
22 changes: 22 additions & 0 deletions model/modelpb/agent_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions model/modelpb/apmevent_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions model/modelpb/child_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions model/modelpb/client_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading