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

exporter/*: eliminate use of .Append() #3861

Merged
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
15 changes: 10 additions & 5 deletions exporter/awscloudwatchlogsexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,16 @@ func TestAttrValue(t *testing.T) {
builder: func() pdata.AttributeValue {
arrAttr := pdata.NewAttributeValueArray()
arr := arrAttr.ArrayVal()
arr.Append(pdata.NewAttributeValueDouble(1.2))
arr.Append(pdata.NewAttributeValueDouble(1.6))
arr.Append(pdata.NewAttributeValueBool(true))
arr.Append(pdata.NewAttributeValueString("hello"))
arr.Append(pdata.NewAttributeValueNull())
for _, av := range []pdata.AttributeValue{
pdata.NewAttributeValueDouble(1.2),
pdata.NewAttributeValueDouble(1.6),
pdata.NewAttributeValueBool(true),
pdata.NewAttributeValueString("hello"),
pdata.NewAttributeValueNull(),
} {
tgt := arr.AppendEmpty()
av.CopyTo(tgt)
}
return arrAttr
},
want: []interface{}{1.2, 1.6, true, "hello", nil},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ func encodeSpanEvents(t *testing.T, language string, events ...pdata.SpanEvent)
span.SetTraceID(pdata.NewTraceID(traceID))
span.SetSpanID(pdata.NewSpanID(transactionID))
for _, event := range events {
span.Events().Append(event)
tgt := span.Events().AppendEmpty()
event.CopyTo(tgt)
}

var w fastjson.Writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ func TestValue_FromAttribute(t *testing.T) {
"non-empty array": {
in: func() pdata.AttributeValue {
v := pdata.NewAttributeValueArray()
arr := v.ArrayVal()
arr.Append(pdata.NewAttributeValueInt(1))
tgt := v.ArrayVal().AppendEmpty()
pdata.NewAttributeValueInt(1).CopyTo(tgt)
return v
}(),
want: ArrValue(IntValue(1)),
Expand Down
3 changes: 2 additions & 1 deletion exporter/humioexporter/traces_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (e *humioTracesExporter) tracesToHumioEvents(td pdata.Traces) ([]*HumioStru
if len(droppedTraces) > 0 {
dropped := pdata.NewTraces()
for _, t := range droppedTraces {
dropped.ResourceSpans().Append(t)
tgt := dropped.ResourceSpans().AppendEmpty()
t.CopyTo(tgt)
}

return results, consumererror.NewTraces(
Expand Down
6 changes: 4 additions & 2 deletions exporter/loadbalancingexporter/log_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ func TestLogBatchWithTwoTraces(t *testing.T) {
first := simpleLogs()
second := simpleLogWithID(pdata.NewTraceID([16]byte{2, 3, 4, 5}))
batch := pdata.NewLogs()
batch.ResourceLogs().Append(first.ResourceLogs().At(0))
batch.ResourceLogs().Append(second.ResourceLogs().At(0))
firstTgt := batch.ResourceLogs().AppendEmpty()
first.ResourceLogs().At(0).CopyTo(firstTgt)
secondTgt := batch.ResourceLogs().AppendEmpty()
second.ResourceLogs().At(0).CopyTo(secondTgt)

// test
err = p.ConsumeLogs(context.Background(), batch)
Expand Down
3 changes: 2 additions & 1 deletion exporter/newrelicexporter/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ func TestTransformSpan(t *testing.T) {
event.SetName("this is the event name")
event.SetTimestamp(pdata.TimestampFromTime(now))
event.SetDroppedAttributesCount(1)
s.Events().Append(event)
tgt := s.Events().AppendEmpty()
event.CopyTo(tgt)
return s
},
want: telemetry.Span{
Expand Down
3 changes: 2 additions & 1 deletion exporter/sentryexporter/sentry_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ func TestPushTraceData(t *testing.T) {
td: func() pdata.Traces {
traces := pdata.NewTraces()
resourceSpans := pdata.NewResourceSpans()
traces.ResourceSpans().Append(resourceSpans)
tgt := traces.ResourceSpans().AppendEmpty()
resourceSpans.CopyTo(tgt)
return traces
}(),
called: false,
Expand Down
3 changes: 2 additions & 1 deletion exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ func TestConsumeMetricsWithAccessTokenPassthrough(t *testing.T) {
accessTokenPassthrough: false,
metrics: func() pdata.Metrics {
forFirstToken := validMetricsWithToken(true, fromLabels[0])
forFirstToken.ResourceMetrics().Append(validMetricsWithToken(true, fromLabels[1]).ResourceMetrics().At(0))
tgt := forFirstToken.ResourceMetrics().AppendEmpty()
validMetricsWithToken(true, fromLabels[1]).ResourceMetrics().At(0).CopyTo(tgt)
return forFirstToken
}(),
pushedTokens: []string{fromHeaders},
Expand Down
3 changes: 2 additions & 1 deletion exporter/sumologicexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ func (se *sumologicexporter) pushLogsData(ctx context.Context, ld pdata.Logs) er
logs := ills.AppendEmpty().Logs()

for _, log := range droppedRecords {
logs.Append(log)
tgt := logs.AppendEmpty()
log.CopyTo(tgt)
}

return consumererror.NewLogs(consumererror.Combine(errs), droppedLogs)
Expand Down
9 changes: 6 additions & 3 deletions exporter/sumologicexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func LogRecordsToLogs(records []pdata.LogRecord) pdata.Logs {
logs := pdata.NewLogs()
logsSlice := logs.ResourceLogs().AppendEmpty().InstrumentationLibraryLogs().AppendEmpty().Logs()
for _, record := range records {
logsSlice.Append(record)
tgt := logsSlice.AppendEmpty()
record.CopyTo(tgt)
}

return logs
Expand Down Expand Up @@ -283,7 +284,8 @@ func TestPushFailedBatch(t *testing.T) {
log := logs.ResourceLogs().At(0)

for i := 0; i < maxBufferSize; i++ {
logs.ResourceLogs().Append(log)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it me, or is the removal of Append going to complicate the API for the consumers? One call is now two calls (AppendEmpty + CopyTo).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed to this to not change too much in components, but normally consumers should call AppendEmpty then fill the result instead of returning a metric.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand. Previously, a consumer would call:

			logs.Append(log)

Now, they need to do this:

			tgt := logs.AppendEmpty()
			log.CopyTo(tgt)

This does complicate the caller, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually just in this case, Append was not correctly used. Because Append does not do a Copy of the log, so all the entries would point to the same log internal (a.k.a if you change one of the entry it changes all).

But in general the previous use-case was:

log := generateLog()
logs.Append(log)

Now customers will do:

log := fillLog(logs.AppendEmpty())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this one was also used incorrectly then?

From:

				s.Events().Append(event)

To:

				tgt := s.Events().AppendEmpty()
				event.CopyTo(tgt)

If so, the change looks good to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was, but to limit the amount of changes we went the simple path.

tgt := logs.ResourceLogs().AppendEmpty()
log.CopyTo(tgt)
}

err := test.exp.pushLogsData(context.Background(), logs)
Expand Down Expand Up @@ -476,7 +478,8 @@ func TestPushMetricsFailedBatch(t *testing.T) {
metric := metrics.ResourceMetrics().At(0)

for i := 0; i < maxBufferSize; i++ {
metrics.ResourceMetrics().Append(metric)
tgt := metrics.ResourceMetrics().AppendEmpty()
metric.CopyTo(tgt)
}

err := test.exp.pushMetricsData(context.Background(), metrics)
Expand Down
6 changes: 4 additions & 2 deletions exporter/sumologicexporter/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ func exampleMultitypeLogs() []pdata.LogRecord {
intVal := pdata.NewAttributeValueNull()
intVal.SetIntVal(13)

attArr.Append(strVal)
attArr.Append(intVal)
strTgt := attArr.AppendEmpty()
strVal.CopyTo(strTgt)
intTgt := attArr.AppendEmpty()
intVal.CopyTo(intTgt)

attVal.CopyTo(buffer[1].Body())
buffer[1].Attributes().InsertString("key1", "value1")
Expand Down