Skip to content

Commit

Permalink
[chore] use pdata/testdata instead of coreinternal (#32265)
Browse files Browse the repository at this point in the history
This will allow us to remove duplicated code in the near future.

---------

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten authored Apr 9, 2024
1 parent 6229c6a commit 9124bc8
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 52 deletions.
1 change: 1 addition & 0 deletions exporter/alibabacloudlogserviceexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
go.opentelemetry.io/collector/confmap v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/exporter v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata v1.4.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata/testdata v0.0.0-20240408153657-fc289290613a
go.opentelemetry.io/collector/semconv v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/exporter/exportertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
"go.opentelemetry.io/collector/pdata/testdata"
)

func TestNewMetricsExporter(t *testing.T) {
Expand All @@ -24,7 +23,7 @@ func TestNewMetricsExporter(t *testing.T) {
require.NotNil(t, got)

// This will put trace data to send buffer and return success.
err = got.ConsumeMetrics(context.Background(), testdata.GenerateMetricsOneMetric())
err = got.ConsumeMetrics(context.Background(), testdata.GenerateMetrics(1))
assert.NoError(t, err)
}

Expand Down
1 change: 1 addition & 0 deletions exporter/kafkaexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
go.opentelemetry.io/collector/consumer v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/exporter v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata v1.4.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata/testdata v0.0.0-20240408153657-fc289290613a
go.opentelemetry.io/collector/semconv v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
Expand Down
20 changes: 10 additions & 10 deletions exporter/kafkaexporter/kafka_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/testdata"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka"
)

Expand Down Expand Up @@ -145,7 +145,7 @@ func TestTracesPusher(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, p.Close(context.Background()))
})
err := p.tracesPusher(context.Background(), testdata.GenerateTracesTwoSpansSameResource())
err := p.tracesPusher(context.Background(), testdata.GenerateTraces(2))
require.NoError(t, err)
}

Expand All @@ -163,7 +163,7 @@ func TestTracesPusher_err(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, p.Close(context.Background()))
})
td := testdata.GenerateTracesTwoSpansSameResource()
td := testdata.GenerateTraces(2)
err := p.tracesPusher(context.Background(), td)
assert.EqualError(t, err, expErr.Error())
}
Expand All @@ -174,7 +174,7 @@ func TestTracesPusher_marshal_error(t *testing.T) {
marshaler: &tracesErrorMarshaler{err: expErr},
logger: zap.NewNop(),
}
td := testdata.GenerateTracesTwoSpansSameResource()
td := testdata.GenerateTraces(2)
err := p.tracesPusher(context.Background(), td)
require.Error(t, err)
assert.Contains(t, err.Error(), expErr.Error())
Expand All @@ -192,7 +192,7 @@ func TestMetricsDataPusher(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, p.Close(context.Background()))
})
err := p.metricsDataPusher(context.Background(), testdata.GenerateMetricsTwoMetrics())
err := p.metricsDataPusher(context.Background(), testdata.GenerateMetrics(2))
require.NoError(t, err)
}

Expand All @@ -210,7 +210,7 @@ func TestMetricsDataPusher_err(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, p.Close(context.Background()))
})
md := testdata.GenerateMetricsTwoMetrics()
md := testdata.GenerateMetrics(2)
err := p.metricsDataPusher(context.Background(), md)
assert.EqualError(t, err, expErr.Error())
}
Expand All @@ -221,7 +221,7 @@ func TestMetricsDataPusher_marshal_error(t *testing.T) {
marshaler: &metricsErrorMarshaler{err: expErr},
logger: zap.NewNop(),
}
md := testdata.GenerateMetricsTwoMetrics()
md := testdata.GenerateMetrics(2)
err := p.metricsDataPusher(context.Background(), md)
require.Error(t, err)
assert.Contains(t, err.Error(), expErr.Error())
Expand All @@ -239,7 +239,7 @@ func TestLogsDataPusher(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, p.Close(context.Background()))
})
err := p.logsDataPusher(context.Background(), testdata.GenerateLogsOneLogRecord())
err := p.logsDataPusher(context.Background(), testdata.GenerateLogs(1))
require.NoError(t, err)
}

Expand All @@ -257,7 +257,7 @@ func TestLogsDataPusher_err(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, p.Close(context.Background()))
})
ld := testdata.GenerateLogsOneLogRecord()
ld := testdata.GenerateLogs(1)
err := p.logsDataPusher(context.Background(), ld)
assert.EqualError(t, err, expErr.Error())
}
Expand All @@ -268,7 +268,7 @@ func TestLogsDataPusher_marshal_error(t *testing.T) {
marshaler: &logsErrorMarshaler{err: expErr},
logger: zap.NewNop(),
}
ld := testdata.GenerateLogsOneLogRecord()
ld := testdata.GenerateLogs(1)
err := p.logsDataPusher(context.Background(), ld)
require.Error(t, err)
assert.Contains(t, err.Error(), expErr.Error())
Expand Down
2 changes: 1 addition & 1 deletion exporter/logicmonitorexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/logicmonitor/lm-data-sdk-go v1.3.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.97.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.97.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.97.1-0.20240409140257-792fac1b62d4
Expand All @@ -15,6 +14,7 @@ require (
go.opentelemetry.io/collector/consumer v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/exporter v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata v1.4.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata/testdata v0.0.0-20240408153657-fc289290613a
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/goleak v1.3.0
Expand Down
9 changes: 4 additions & 5 deletions exporter/logicmonitorexporter/internal/traces/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
"github.com/logicmonitor/lm-data-sdk-go/utils"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/pdata/testdata"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
)

func TestSendTraces(t *testing.T) {
Expand All @@ -41,7 +40,7 @@ func TestSendTraces(t *testing.T) {
sender, err := NewSender(ctx, ts.URL, ts.Client(), authParams, zap.NewNop())
assert.NoError(t, err)

err = sender.SendTraces(ctx, testdata.GenerateTracesOneSpan())
err = sender.SendTraces(ctx, testdata.GenerateTraces(1))
cancel()
assert.NoError(t, err)
})
Expand All @@ -62,7 +61,7 @@ func TestSendTraces(t *testing.T) {
sender, err := NewSender(ctx, ts.URL, ts.Client(), authParams, zap.NewNop())
assert.NoError(t, err)

err = sender.SendTraces(ctx, testdata.GenerateTracesOneSpan())
err = sender.SendTraces(ctx, testdata.GenerateTraces(1))
cancel()
assert.Error(t, err)
assert.Equal(t, true, consumererror.IsPermanent(err))
Expand All @@ -84,7 +83,7 @@ func TestSendTraces(t *testing.T) {
sender, err := NewSender(ctx, ts.URL, ts.Client(), authParams, zap.NewNop())
assert.NoError(t, err)

err = sender.SendTraces(ctx, testdata.GenerateTracesOneSpan())
err = sender.SendTraces(ctx, testdata.GenerateTraces(1))
cancel()
assert.Error(t, err)
assert.Equal(t, false, consumererror.IsPermanent(err))
Expand Down
9 changes: 4 additions & 5 deletions exporter/logzioexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/testdata"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
)

const (
Expand Down Expand Up @@ -90,7 +89,7 @@ func fillLogNoTimestamp(log plog.LogRecord) {
}

func generateLogsOneEmptyTimestamp() plog.Logs {
ld := testdata.GenerateLogsOneEmptyLogRecord()
ld := testdata.GenerateLogs(1)
logs := ld.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords()
ld.ResourceLogs().At(0).ScopeLogs().At(0).Scope().SetName("logScopeName")
fillLogOne(logs.At(0))
Expand Down Expand Up @@ -195,7 +194,7 @@ func TestExportErrors(tester *testing.T) {
},
}
td := newTestTracesWithAttributes()
ld := testdata.GenerateLogsManyLogRecordsSameResource(10)
ld := testdata.GenerateLogs(10)
err := testTracesExporter(td, tester, cfg)
fmt.Println(err.Error())
require.Error(tester, err)
Expand Down Expand Up @@ -283,7 +282,7 @@ func TestPushLogsData(tester *testing.T) {
},
}
defer server.Close()
ld := testdata.GenerateLogsManyLogRecordsSameResource(2)
ld := testdata.GenerateLogs(2)
res := ld.ResourceLogs().At(0).Resource()
res.Attributes().PutStr(conventions.AttributeServiceName, testService)
res.Attributes().PutStr(conventions.AttributeHostName, testHost)
Expand Down
3 changes: 2 additions & 1 deletion exporter/logzioexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21
require (
github.com/hashicorp/go-hclog v1.6.3
github.com/jaegertracing/jaeger v1.55.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.97.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.97.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.97.1-0.20240409140257-792fac1b62d4
Expand All @@ -17,6 +16,7 @@ require (
go.opentelemetry.io/collector/consumer v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/exporter v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata v1.4.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata/testdata v0.0.0-20240408153657-fc289290613a
go.opentelemetry.io/collector/semconv v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
Expand Down Expand Up @@ -54,6 +54,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.97.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down
3 changes: 2 additions & 1 deletion exporter/opencensusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21
require (
github.com/census-instrumentation/opencensus-proto v0.4.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.97.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.97.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.97.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/opencensusreceiver v0.97.0
github.com/stretchr/testify v1.9.0
Expand All @@ -18,6 +17,7 @@ require (
go.opentelemetry.io/collector/consumer v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/exporter v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata v1.4.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata/testdata v0.0.0-20240408153657-fc289290613a
go.opentelemetry.io/collector/receiver v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
Expand Down Expand Up @@ -51,6 +51,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.2.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.97.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.97.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
Expand Down
14 changes: 7 additions & 7 deletions exporter/opencensusexporter/opencensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/testdata"
"go.opentelemetry.io/collector/receiver/receivertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/opencensusreceiver"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func TestSendTraces(t *testing.T) {
assert.NoError(t, exp.Shutdown(context.Background()))
})

td := testdata.GenerateTracesOneSpan()
td := testdata.GenerateTraces(1)
assert.NoError(t, exp.ConsumeTraces(context.Background(), td))
assert.Eventually(t, func() bool {
return len(sink.AllTraces()) == 1
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestSendTraces_NoBackend(t *testing.T) {
assert.NoError(t, exp.Shutdown(context.Background()))
})

td := testdata.GenerateTracesOneSpan()
td := testdata.GenerateTraces(1)
for i := 0; i < 10000; i++ {
assert.Error(t, exp.ConsumeTraces(context.Background(), td))
}
Expand All @@ -118,7 +118,7 @@ func TestSendTraces_AfterStop(t *testing.T) {
require.NoError(t, exp.Start(context.Background(), host))
assert.NoError(t, exp.Shutdown(context.Background()))

td := testdata.GenerateTracesOneSpan()
td := testdata.GenerateTraces(1)
assert.Error(t, exp.ConsumeTraces(context.Background(), td))
}

Expand Down Expand Up @@ -154,7 +154,7 @@ func TestSendMetrics(t *testing.T) {
assert.NoError(t, exp.Shutdown(context.Background()))
})

md := testdata.GenerateMetricsOneMetric()
md := testdata.GenerateMetrics(1)
assert.NoError(t, exp.ConsumeMetrics(context.Background(), md))
assert.Eventually(t, func() bool {
return len(sink.AllMetrics()) == 1
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestSendMetrics_NoBackend(t *testing.T) {
assert.NoError(t, exp.Shutdown(context.Background()))
})

md := testdata.GenerateMetricsOneMetric()
md := testdata.GenerateMetrics(1)
for i := 0; i < 10000; i++ {
assert.Error(t, exp.ConsumeMetrics(context.Background(), md))
}
Expand All @@ -215,6 +215,6 @@ func TestSendMetrics_AfterStop(t *testing.T) {
require.NoError(t, exp.Start(context.Background(), host))
assert.NoError(t, exp.Shutdown(context.Background()))

md := testdata.GenerateMetricsOneMetric()
md := testdata.GenerateMetrics(1)
assert.Error(t, exp.ConsumeMetrics(context.Background(), md))
}
1 change: 1 addition & 0 deletions receiver/kafkareceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
go.opentelemetry.io/collector/confmap v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/consumer v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata v1.4.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/pdata/testdata v0.0.0-20240408153657-fc289290613a
go.opentelemetry.io/collector/receiver v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/collector/semconv v0.97.1-0.20240409140257-792fac1b62d4
go.opentelemetry.io/otel/metric v1.24.0
Expand Down
5 changes: 2 additions & 3 deletions receiver/kafkareceiver/header_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/testdata"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.uber.org/zap/zaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
)

func TestHeaderExtractionTraces(t *testing.T) {
Expand Down Expand Up @@ -182,7 +181,7 @@ func TestHeaderExtractionMetrics(t *testing.T) {
assert.NoError(t, err)
wg.Done()
}()
ld := testdata.GenerateMetricsOneMetric()
ld := testdata.GenerateMetrics(1)
unmarshaler := &pmetric.ProtoMarshaler{}
bts, err := unmarshaler.MarshalMetrics(ld)
groupClaim.messageChan <- &sarama.ConsumerMessage{
Expand Down
6 changes: 3 additions & 3 deletions receiver/kafkareceiver/kafka_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/testdata"
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/testdata"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/textutils"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka"
)
Expand Down Expand Up @@ -544,7 +544,7 @@ func TestMetricsConsumerGroupHandler_error_nextConsumer(t *testing.T) {
wg.Done()
}()

ld := testdata.GenerateMetricsOneMetric()
ld := testdata.GenerateMetrics(1)
unmarshaler := &pmetric.ProtoMarshaler{}
bts, err := unmarshaler.MarshalMetrics(ld)
require.NoError(t, err)
Expand Down Expand Up @@ -811,7 +811,7 @@ func TestLogsConsumerGroupHandler_error_nextConsumer(t *testing.T) {
wg.Done()
}()

ld := testdata.GenerateLogsOneLogRecord()
ld := testdata.GenerateLogs(1)
unmarshaler := &plog.ProtoMarshaler{}
bts, err := unmarshaler.MarshalLogs(ld)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 9124bc8

Please sign in to comment.