Skip to content

Commit

Permalink
Deprecate obsreporttest.Check* in favor of TestTelemetry.Check (#6678)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Dec 5, 2022
1 parent c049580 commit e7edb00
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 83 deletions.
11 changes: 11 additions & 0 deletions .chloggen/deprecatechecks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: obsreporttest

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate obsreporttest.Check* in favor of TestTelemetry.Check

# One or more tracking issues or pull requests related to the change
issues: [6678]
4 changes: 2 additions & 2 deletions exporter/exporterhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ func checkRecordedMetricsForLogsExporter(t *testing.T, tt obsreporttest.TestTele

// TODO: When the new metrics correctly count partial dropped fix this.
if wantError != nil {
require.NoError(t, obsreporttest.CheckExporterLogs(tt, fakeLogsExporterName, 0, int64(numBatches*ld.LogRecordCount())))
require.NoError(t, tt.CheckExporterLogs(0, int64(numBatches*ld.LogRecordCount())))
} else {
require.NoError(t, obsreporttest.CheckExporterLogs(tt, fakeLogsExporterName, int64(numBatches*ld.LogRecordCount()), 0))
require.NoError(t, tt.CheckExporterLogs(int64(numBatches*ld.LogRecordCount()), 0))
}
}

Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ func checkRecordedMetricsForMetricsExporter(t *testing.T, tt obsreporttest.TestT
// TODO: When the new metrics correctly count partial dropped fix this.
numPoints := int64(numBatches * md.MetricCount() * 2) /* 2 points per metric*/
if wantError != nil {
require.NoError(t, obsreporttest.CheckExporterMetrics(tt, fakeMetricsExporterName, 0, numPoints))
require.NoError(t, tt.CheckExporterMetrics(0, numPoints))
} else {
require.NoError(t, obsreporttest.CheckExporterMetrics(tt, fakeMetricsExporterName, numPoints, 0))
require.NoError(t, tt.CheckExporterMetrics(numPoints, 0))
}
}

Expand Down
4 changes: 2 additions & 2 deletions exporter/exporterhelper/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ func checkRecordedMetricsForTracesExporter(t *testing.T, tt obsreporttest.TestTe

// TODO: When the new metrics correctly count partial dropped fix this.
if wantError != nil {
require.NoError(t, obsreporttest.CheckExporterTraces(tt, fakeTracesExporterName, 0, int64(numBatches*td.SpanCount())))
require.NoError(t, tt.CheckExporterTraces(0, int64(numBatches*td.SpanCount())))
} else {
require.NoError(t, obsreporttest.CheckExporterTraces(tt, fakeTracesExporterName, int64(numBatches*td.SpanCount()), 0))
require.NoError(t, tt.CheckExporterTraces(int64(numBatches*td.SpanCount()), 0))
}
}

Expand Down
18 changes: 9 additions & 9 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestReceiveTraceDataOp(t *testing.T) {
t.Fatalf("unexpected param: %v", params[i])
}
}
require.NoError(t, obsreporttest.CheckReceiverTraces(tt, receiver, transport, int64(acceptedSpans), int64(refusedSpans)))
require.NoError(t, tt.CheckReceiverTraces(transport, int64(acceptedSpans), int64(refusedSpans)))
})
}

Expand Down Expand Up @@ -165,7 +165,7 @@ func TestReceiveLogsOp(t *testing.T) {
t.Fatalf("unexpected param: %v", params[i])
}
}
require.NoError(t, obsreporttest.CheckReceiverLogs(tt, receiver, transport, int64(acceptedLogRecords), int64(refusedLogRecords)))
require.NoError(t, tt.CheckReceiverLogs(transport, int64(acceptedLogRecords), int64(refusedLogRecords)))
})
}

Expand Down Expand Up @@ -214,7 +214,7 @@ func TestReceiveMetricsOp(t *testing.T) {
}
}

require.NoError(t, obsreporttest.CheckReceiverMetrics(tt, receiver, transport, int64(acceptedMetricPoints), int64(refusedMetricPoints)))
require.NoError(t, tt.CheckReceiverMetrics(transport, int64(acceptedMetricPoints), int64(refusedMetricPoints)))
})
}

Expand Down Expand Up @@ -321,7 +321,7 @@ func TestExportTraceDataOp(t *testing.T) {
}
}

require.NoError(t, obsreporttest.CheckExporterTraces(tt, exporter, int64(sentSpans), int64(failedToSendSpans)))
require.NoError(t, tt.CheckExporterTraces(int64(sentSpans), int64(failedToSendSpans)))

})
}
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestExportMetricsOp(t *testing.T) {
}
}

require.NoError(t, obsreporttest.CheckExporterMetrics(tt, exporter, int64(sentMetricPoints), int64(failedToSendMetricPoints)))
require.NoError(t, tt.CheckExporterMetrics(int64(sentMetricPoints), int64(failedToSendMetricPoints)))
})
}

Expand Down Expand Up @@ -420,7 +420,7 @@ func TestExportLogsOp(t *testing.T) {
}
}

require.NoError(t, obsreporttest.CheckExporterLogs(tt, exporter, int64(sentLogRecords), int64(failedToSendLogRecords)))
require.NoError(t, tt.CheckExporterLogs(int64(sentLogRecords), int64(failedToSendLogRecords)))
})
}

Expand Down Expand Up @@ -495,7 +495,7 @@ func testProcessorTraceData(t *testing.T, tt obsreporttest.TestTelemetry, regist
obsrep.TracesRefused(context.Background(), refusedSpans)
obsrep.TracesDropped(context.Background(), droppedSpans)

require.NoError(t, obsreporttest.CheckProcessorTraces(tt, processor, acceptedSpans, refusedSpans, droppedSpans))
require.NoError(t, tt.CheckProcessorTraces(acceptedSpans, refusedSpans, droppedSpans))
}

func TestProcessorMetricsData(t *testing.T) {
Expand All @@ -516,7 +516,7 @@ func testProcessorMetricsData(t *testing.T, tt obsreporttest.TestTelemetry, regi
obsrep.MetricsRefused(context.Background(), refusedPoints)
obsrep.MetricsDropped(context.Background(), droppedPoints)

require.NoError(t, obsreporttest.CheckProcessorMetrics(tt, processor, acceptedPoints, refusedPoints, droppedPoints))
require.NoError(t, tt.CheckProcessorMetrics(acceptedPoints, refusedPoints, droppedPoints))
}

func TestBuildProcessorCustomMetricName(t *testing.T) {
Expand Down Expand Up @@ -559,5 +559,5 @@ func testProcessorLogRecords(t *testing.T, tt obsreporttest.TestTelemetry, regis
obsrep.LogsRefused(context.Background(), refusedRecords)
obsrep.LogsDropped(context.Background(), droppedRecords)

require.NoError(t, obsreporttest.CheckProcessorLogs(tt, processor, acceptedRecords, refusedRecords, droppedRecords))
require.NoError(t, tt.CheckProcessorLogs(acceptedRecords, refusedRecords, droppedRecords))
}
81 changes: 63 additions & 18 deletions obsreport/obsreporttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,60 @@ func (tts *TestTelemetry) ToReceiverCreateSettings() component.ReceiverCreateSet
return set
}

// CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckExporterTraces(sentSpans, sendFailedSpans int64) error {
return tts.otelPrometheusChecker.checkExporterTraces(tts.id, sentSpans, sendFailedSpans)
}

// CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckExporterMetrics(sentMetricsPoints, sendFailedMetricsPoints int64) error {
return tts.otelPrometheusChecker.checkExporterMetrics(tts.id, sentMetricsPoints, sendFailedMetricsPoints)
}

// CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckExporterLogs(sentLogRecords, sendFailedLogRecords int64) error {
return tts.otelPrometheusChecker.checkExporterLogs(tts.id, sentLogRecords, sendFailedLogRecords)
}

// CheckProcessorTraces checks that for the current exported values for trace exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckProcessorTraces(acceptedSpans, refusedSpans, droppedSpans int64) error {
return tts.otelPrometheusChecker.checkProcessorTraces(tts.id, acceptedSpans, refusedSpans, droppedSpans)
}

// CheckProcessorMetrics checks that for the current exported values for metrics exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckProcessorMetrics(acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error {
return tts.otelPrometheusChecker.checkProcessorMetrics(tts.id, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints)
}

// CheckProcessorLogs checks that for the current exported values for logs exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckProcessorLogs(acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error {
return tts.otelPrometheusChecker.checkProcessorLogs(tts.id, acceptedLogRecords, refusedLogRecords, droppedLogRecords)
}

// CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckReceiverTraces(protocol string, acceptedSpans, droppedSpans int64) error {
return tts.otelPrometheusChecker.checkReceiverTraces(tts.id, protocol, acceptedSpans, droppedSpans)
}

// CheckReceiverLogs checks that for the current exported values for logs receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckReceiverLogs(protocol string, acceptedLogRecords, droppedLogRecords int64) error {
return tts.otelPrometheusChecker.checkReceiverLogs(tts.id, protocol, acceptedLogRecords, droppedLogRecords)
}

// CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
func (tts *TestTelemetry) CheckReceiverMetrics(protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
return tts.otelPrometheusChecker.checkReceiverMetrics(tts.id, protocol, acceptedMetricPoints, droppedMetricPoints)
}

// Shutdown unregisters any views and shuts down the SpanRecorder
func (tts *TestTelemetry) Shutdown(ctx context.Context) error {
view.Unregister(tts.views...)
Expand Down Expand Up @@ -144,56 +198,47 @@ func SetupTelemetryWithID(id component.ID) (TestTelemetry, error) {
return settings, nil
}

// CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckExporterTraces.
func CheckExporterTraces(tts TestTelemetry, exporter component.ID, sentSpans, sendFailedSpans int64) error {
return tts.otelPrometheusChecker.checkExporterTraces(exporter, sentSpans, sendFailedSpans)
}

// CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckExporterMetrics.
func CheckExporterMetrics(tts TestTelemetry, exporter component.ID, sentMetricsPoints, sendFailedMetricsPoints int64) error {
return tts.otelPrometheusChecker.checkExporterMetrics(exporter, sentMetricsPoints, sendFailedMetricsPoints)
}

// CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckExporterLogs.
func CheckExporterLogs(tts TestTelemetry, exporter component.ID, sentLogRecords, sendFailedLogRecords int64) error {
return tts.otelPrometheusChecker.checkExporterLogs(exporter, sentLogRecords, sendFailedLogRecords)
}

// CheckProcessorTraces checks that for the current exported values for trace exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckProcessorTraces.
func CheckProcessorTraces(tts TestTelemetry, processor component.ID, acceptedSpans, refusedSpans, droppedSpans int64) error {
return tts.otelPrometheusChecker.checkProcessorTraces(processor, acceptedSpans, refusedSpans, droppedSpans)
}

// CheckProcessorMetrics checks that for the current exported values for metrics exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckProcessorMetrics.
func CheckProcessorMetrics(tts TestTelemetry, processor component.ID, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error {
return tts.otelPrometheusChecker.checkProcessorMetrics(processor, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints)
}

// CheckProcessorLogs checks that for the current exported values for logs exporter metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckProcessorLogs.
func CheckProcessorLogs(tts TestTelemetry, processor component.ID, acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error {
return tts.otelPrometheusChecker.checkProcessorLogs(processor, acceptedLogRecords, refusedLogRecords, droppedLogRecords)
}

// CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckReceiverTraces.
func CheckReceiverTraces(tts TestTelemetry, receiver component.ID, protocol string, acceptedSpans, droppedSpans int64) error {
return tts.otelPrometheusChecker.checkReceiverTraces(receiver, protocol, acceptedSpans, droppedSpans)
}

// CheckReceiverLogs checks that for the current exported values for logs receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckReceiverLogs.
func CheckReceiverLogs(tts TestTelemetry, receiver component.ID, protocol string, acceptedLogRecords, droppedLogRecords int64) error {
return tts.otelPrometheusChecker.checkReceiverLogs(receiver, protocol, acceptedLogRecords, droppedLogRecords)
}

// CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values.
// When this function is called it is required to also call SetupTelemetry as first thing.
// Deprecated: [v0.67.0] use TestTelemetry.CheckReceiverMetrics.
func CheckReceiverMetrics(tts TestTelemetry, receiver component.ID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
return tts.otelPrometheusChecker.checkReceiverMetrics(receiver, protocol, acceptedMetricPoints, droppedMetricPoints)
}
Expand Down
Loading

0 comments on commit e7edb00

Please sign in to comment.