Skip to content

Commit

Permalink
SetupRecordedMetricsTest returns TelemetrySettings (#4093)
Browse files Browse the repository at this point in the history
* return TelemetrySettings from SetupRecordedMetricsTest

* fix lint

* add ToExporterCreateSettings/ToReceiverCreateSetting

* replace return func with Shutdown

* pass context to shutdown
  • Loading branch information
alrex authored Sep 29, 2021
1 parent a51bf5a commit 896335f
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 116 deletions.
10 changes: 5 additions & 5 deletions exporter/exporterhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ func TestLogsExporter_WithRecordLogs_ReturnError(t *testing.T) {
}

func TestLogsExporter_WithRecordEnqueueFailedMetrics(t *testing.T) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

rCfg := DefaultRetrySettings()
qCfg := DefaultQueueSettings()
qCfg.NumConsumers = 1
qCfg.QueueSize = 2
wantErr := errors.New("some-error")
te, err := NewLogsExporter(&fakeLogsExporterConfig, componenttest.NewNopExporterCreateSettings(), newPushLogsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
te, err := NewLogsExporter(&fakeLogsExporterConfig, set.ToExporterCreateSettings(), newPushLogsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)
require.NotNil(t, te)

Expand Down Expand Up @@ -205,9 +205,9 @@ func newPushLogsData(retError error) consumerhelper.ConsumeLogsFunc {
}

func checkRecordedMetricsForLogsExporter(t *testing.T, le component.LogsExporter, wantError error) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

ld := testdata.GenerateLogsTwoLogRecordsSameResource()
const numBatches = 7
Expand Down
10 changes: 5 additions & 5 deletions exporter/exporterhelper/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ func TestMetricsExporter_WithRecordMetrics_ReturnError(t *testing.T) {
}

func TestMetricsExporter_WithRecordEnqueueFailedMetrics(t *testing.T) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

rCfg := DefaultRetrySettings()
qCfg := DefaultQueueSettings()
qCfg.NumConsumers = 1
qCfg.QueueSize = 2
wantErr := errors.New("some-error")
te, err := NewMetricsExporter(&fakeMetricsExporterConfig, componenttest.NewNopExporterCreateSettings(), newPushMetricsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
te, err := NewMetricsExporter(&fakeMetricsExporterConfig, set.ToExporterCreateSettings(), newPushMetricsData(wantErr), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)
require.NotNil(t, te)

Expand Down Expand Up @@ -206,9 +206,9 @@ func newPushMetricsData(retError error) consumerhelper.ConsumeMetricsFunc {
}

func checkRecordedMetricsForMetricsExporter(t *testing.T, me component.MetricsExporter, wantError error) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

md := testdata.GenerateMetricsTwoMetrics()
const numBatches = 7
Expand Down
8 changes: 4 additions & 4 deletions exporter/exporterhelper/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ import (
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"

"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/obsreport/obsreporttest"
)

func TestExportEnqueueFailure(t *testing.T) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

exporter := config.NewComponentID("fakeExporter")

obsrep := newObsExporter(obsreport.ExporterSettings{
Level: configtelemetry.LevelNormal,
ExporterID: exporter,
ExporterCreateSettings: componenttest.NewNopExporterCreateSettings()})
ExporterCreateSettings: set.ToExporterCreateSettings(),
})

logRecords := 7
obsrep.recordLogsEnqueueFailure(context.Background(), logRecords)
Expand Down
6 changes: 3 additions & 3 deletions exporter/exporterhelper/queued_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ func TestQueuedRetry_DropOnFull(t *testing.T) {
}

func TestQueuedRetryHappyPath(t *testing.T) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

qCfg := DefaultQueueSettings()
rCfg := DefaultRetrySettings()
be := newBaseExporter(&defaultExporterCfg, componenttest.NewNopExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
be := newBaseExporter(&defaultExporterCfg, set.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
ocs := newObservabilityConsumerSender(be.qrSender.consumerSender)
be.qrSender.consumerSender = ocs
require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost()))
Expand Down
10 changes: 5 additions & 5 deletions exporter/exporterhelper/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ func TestTracesExporter_WithRecordMetrics_ReturnError(t *testing.T) {
}

func TestTracesExporter_WithRecordEnqueueFailedMetrics(t *testing.T) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

rCfg := DefaultRetrySettings()
qCfg := DefaultQueueSettings()
qCfg.NumConsumers = 1
qCfg.QueueSize = 2
wantErr := errors.New("some-error")
te, err := NewTracesExporter(&fakeTracesExporterConfig, componenttest.NewNopExporterCreateSettings(), newTraceDataPusher(wantErr), WithRetry(rCfg), WithQueue(qCfg))
te, err := NewTracesExporter(&fakeTracesExporterConfig, set.ToExporterCreateSettings(), newTraceDataPusher(wantErr), WithRetry(rCfg), WithQueue(qCfg))
require.NoError(t, err)
require.NotNil(t, te)

Expand Down Expand Up @@ -206,9 +206,9 @@ func newTraceDataPusher(retError error) consumerhelper.ConsumeTracesFunc {
}

func checkRecordedMetricsForTracesExporter(t *testing.T, te component.TracesExporter, wantError error) {
doneFn, err := obsreporttest.SetupRecordedMetricsTest()
set, err := obsreporttest.SetupRecordedMetricsTest()
require.NoError(t, err)
defer doneFn()
defer set.Shutdown(context.Background())

td := testdata.GenerateTracesTwoSpansSameResource()
const numBatches = 7
Expand Down
Loading

0 comments on commit 896335f

Please sign in to comment.