Skip to content

Commit

Permalink
Move code from observability package to obsreport (#1277)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jul 7, 2020
1 parent b0aa7c7 commit e3fa0c1
Show file tree
Hide file tree
Showing 22 changed files with 461 additions and 474 deletions.
11 changes: 5 additions & 6 deletions exporter/exporterhelper/logshelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import (
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/internal/data"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/observability"
"go.opentelemetry.io/collector/observability/observabilitytest"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/obsreport/obsreporttest"
)

const (
Expand Down Expand Up @@ -153,20 +152,20 @@ func newPushLogsData(droppedTimeSeries int, retError error) PushLogsData {
}

func checkRecordedMetricsForLogsExporter(t *testing.T, me component.LogExporter, wantError error, droppedTimeSeries int) {
doneFn := observabilitytest.SetupRecordedMetricsTest()
doneFn := obsreporttest.SetupRecordedMetricsTest()
defer doneFn()

ld := testdata.GenerateLogDataTwoLogsSameResource()
ctx := observability.ContextWithReceiverName(context.Background(), fakeLogsReceiverName)
ctx := obsreport.LegacyContextWithReceiverName(context.Background(), fakeLogsReceiverName)
const numBatches = 7
for i := 0; i < numBatches; i++ {
require.Equal(t, wantError, me.ConsumeLogs(ctx, ld))
}

err := observabilitytest.CheckValueViewExporterReceivedLogRecords(fakeLogsReceiverName, fakeLogsExporterName, numBatches*ld.LogRecordCount())
err := obsreporttest.CheckValueViewExporterReceivedLogRecords(fakeLogsReceiverName, fakeLogsExporterName, numBatches*ld.LogRecordCount())
require.Nilf(t, err, "CheckValueViewExporterTimeSeries: Want nil Got %v", err)

err = observabilitytest.CheckValueViewExporterDroppedLogRecords(fakeLogsReceiverName, fakeLogsExporterName, numBatches*droppedTimeSeries)
err = obsreporttest.CheckValueViewExporterDroppedLogRecords(fakeLogsReceiverName, fakeLogsExporterName, numBatches*droppedTimeSeries)
require.Nilf(t, err, "CheckValueViewExporterTimeSeries: Want nil Got %v", err)
}

Expand Down
19 changes: 9 additions & 10 deletions exporter/exporterhelper/metricshelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import (
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/observability"
"go.opentelemetry.io/collector/observability/observabilitytest"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/obsreport/obsreporttest"
)

const (
Expand Down Expand Up @@ -257,20 +256,20 @@ func newPushMetricsData(droppedTimeSeries int, retError error) PushMetricsData {
}

func checkRecordedMetricsForMetricsExporter(t *testing.T, me component.MetricsExporter, wantError error, droppedTimeSeries int) {
doneFn := observabilitytest.SetupRecordedMetricsTest()
doneFn := obsreporttest.SetupRecordedMetricsTest()
defer doneFn()

md := testdata.GenerateMetricDataTwoMetrics()
ctx := observability.ContextWithReceiverName(context.Background(), fakeMetricsReceiverName)
ctx := obsreport.LegacyContextWithReceiverName(context.Background(), fakeMetricsReceiverName)
const numBatches = 7
for i := 0; i < numBatches; i++ {
require.Equal(t, wantError, me.ConsumeMetrics(ctx, pdatautil.MetricsFromInternalMetrics(md)))
}

err := observabilitytest.CheckValueViewExporterReceivedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*md.MetricCount())
err := obsreporttest.CheckValueViewExporterReceivedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*md.MetricCount())
require.Nilf(t, err, "CheckValueViewExporterTimeSeries: Want nil Got %v", err)

err = observabilitytest.CheckValueViewExporterDroppedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*droppedTimeSeries)
err = obsreporttest.CheckValueViewExporterDroppedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*droppedTimeSeries)
require.Nilf(t, err, "CheckValueViewExporterTimeSeries: Want nil Got %v", err)
}

Expand Down Expand Up @@ -324,7 +323,7 @@ func newPushMetricsDataOld(droppedTimeSeries int, retError error) PushMetricsDat
}

func checkRecordedMetricsForMetricsExporterOld(t *testing.T, me component.MetricsExporterOld, wantError error, droppedTimeSeries int) {
doneFn := observabilitytest.SetupRecordedMetricsTest()
doneFn := obsreporttest.SetupRecordedMetricsTest()
defer doneFn()
metrics := []*metricspb.Metric{
{
Expand All @@ -335,16 +334,16 @@ func checkRecordedMetricsForMetricsExporterOld(t *testing.T, me component.Metric
},
}
md := consumerdata.MetricsData{Metrics: metrics}
ctx := observability.ContextWithReceiverName(context.Background(), fakeMetricsReceiverName)
ctx := obsreport.LegacyContextWithReceiverName(context.Background(), fakeMetricsReceiverName)
const numBatches = 7
for i := 0; i < numBatches; i++ {
require.Equal(t, wantError, me.ConsumeMetricsData(ctx, md))
}

err := observabilitytest.CheckValueViewExporterReceivedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*NumTimeSeries(md))
err := obsreporttest.CheckValueViewExporterReceivedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*NumTimeSeries(md))
require.Nilf(t, err, "CheckValueViewExporterTimeSeries: Want nil Got %v", err)

err = observabilitytest.CheckValueViewExporterDroppedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*droppedTimeSeries)
err = obsreporttest.CheckValueViewExporterDroppedTimeSeries(fakeMetricsReceiverName, fakeMetricsExporterName, numBatches*droppedTimeSeries)
require.Nilf(t, err, "CheckValueViewExporterTimeSeries: Want nil Got %v", err)
}

Expand Down
19 changes: 9 additions & 10 deletions exporter/exporterhelper/tracehelper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import (
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/observability"
"go.opentelemetry.io/collector/observability/observabilitytest"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/obsreport/obsreporttest"
)

const (
Expand Down Expand Up @@ -162,21 +161,21 @@ func newTraceDataPusherOld(droppedSpans int, retError error) traceDataPusherOld
}

func checkRecordedMetricsForTraceExporterOld(t *testing.T, te component.TraceExporterOld, wantError error, droppedSpans int) {
doneFn := observabilitytest.SetupRecordedMetricsTest()
doneFn := obsreporttest.SetupRecordedMetricsTest()
defer doneFn()

spans := make([]*tracepb.Span, 2)
td := consumerdata.TraceData{Spans: spans}
ctx := observability.ContextWithReceiverName(context.Background(), fakeTraceReceiverName)
ctx := obsreport.LegacyContextWithReceiverName(context.Background(), fakeTraceReceiverName)
const numBatches = 7
for i := 0; i < numBatches; i++ {
require.Equal(t, wantError, te.ConsumeTraceData(ctx, td))
}

err := observabilitytest.CheckValueViewExporterReceivedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*len(spans))
err := obsreporttest.CheckValueViewExporterReceivedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*len(spans))
require.Nilf(t, err, "CheckValueViewExporterReceivedSpans: Want nil Got %v", err)

err = observabilitytest.CheckValueViewExporterDroppedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*droppedSpans)
err = obsreporttest.CheckValueViewExporterDroppedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*droppedSpans)
require.Nilf(t, err, "CheckValueViewExporterDroppedSpans: Want nil Got %v", err)
}

Expand Down Expand Up @@ -349,7 +348,7 @@ func newTraceDataPusher(droppedSpans int, retError error) traceDataPusher {
}

func checkRecordedMetricsForTraceExporter(t *testing.T, te component.TraceExporter, wantError error, droppedSpans int) {
doneFn := observabilitytest.SetupRecordedMetricsTest()
doneFn := obsreporttest.SetupRecordedMetricsTest()
defer doneFn()

const spansLen = 2
Expand All @@ -358,16 +357,16 @@ func checkRecordedMetricsForTraceExporter(t *testing.T, te component.TraceExport
rs.Resize(1)
rs.At(0).InstrumentationLibrarySpans().Resize(1)
rs.At(0).InstrumentationLibrarySpans().At(0).Spans().Resize(spansLen)
ctx := observability.ContextWithReceiverName(context.Background(), fakeTraceReceiverName)
ctx := obsreport.LegacyContextWithReceiverName(context.Background(), fakeTraceReceiverName)
const numBatches = 7
for i := 0; i < numBatches; i++ {
require.Equal(t, wantError, te.ConsumeTraces(ctx, td))
}

err := observabilitytest.CheckValueViewExporterReceivedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*spansLen)
err := obsreporttest.CheckValueViewExporterReceivedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*spansLen)
require.Nilf(t, err, "CheckValueViewExporterReceivedSpans: Want nil Got %v", err)

err = observabilitytest.CheckValueViewExporterDroppedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*droppedSpans)
err = obsreporttest.CheckValueViewExporterDroppedSpans(fakeTraceReceiverName, fakeTraceExporterName, numBatches*droppedSpans)
require.Nilf(t, err, "CheckValueViewExporterDroppedSpans: Want nil Got %v", err)
}

Expand Down
6 changes: 3 additions & 3 deletions exporter/otlpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
otlptracecol "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/collector/trace/v1"
otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/observability"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/testutil"
)

Expand Down Expand Up @@ -68,7 +68,7 @@ func otlpTraceReceiverOnGRPCServer(ln net.Listener) *mockTraceReceiver {
rcv := &mockTraceReceiver{}

// Now run it as a gRPC server
rcv.srv = observability.GRPCServerWithObservabilityEnabled()
rcv.srv = obsreport.GRPCServerWithObservabilityEnabled()
otlptracecol.RegisterTraceServiceServer(rcv.srv, rcv)
go func() {
_ = rcv.srv.Serve(ln)
Expand Down Expand Up @@ -99,7 +99,7 @@ func otlpLogsReceiverOnGRPCServer(ln net.Listener) *mockLogsReceiver {
rcv := &mockLogsReceiver{}

// Now run it as a gRPC server
rcv.srv = observability.GRPCServerWithObservabilityEnabled()
rcv.srv = obsreport.GRPCServerWithObservabilityEnabled()
otlplogs.RegisterLogServiceServer(rcv.srv, rcv)
go func() {
_ = rcv.srv.Serve(ln)
Expand Down
76 changes: 0 additions & 76 deletions observability/observability_test.go

This file was deleted.

Loading

0 comments on commit e3fa0c1

Please sign in to comment.