Skip to content

Commit

Permalink
[component/componenttest] Deprecate CheckReceiverTraces functions (#…
Browse files Browse the repository at this point in the history
…12227)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Deprecate `CheckReceiverTraces` functions

<!-- Issue number if applicable -->
#### Link to tracking issue
Part of #12185 

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Updated

<!--Describe the documentation added.-->
#### Documentation
Added

<!--Please delete paragraphs that you did not use before submitting.-->
  • Loading branch information
sincejune authored Feb 5, 2025
1 parent cb3000d commit 196bbf4
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 17 deletions.
25 changes: 25 additions & 0 deletions .chloggen/deprecate-checkreceivertraces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# 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: component/componenttest

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

# One or more tracking issues or pull requests related to the change
issues: [12185]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: Use the `metadatatest.AssertEqualMetric` series of functions instead of `obsreporttest.CheckReceiverTraces`

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
1 change: 1 addition & 0 deletions component/componenttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (tts *TestTelemetry) CheckExporterMetricGauge(metric string, val int64, ext
return checkIntGauge(tts.Telemetry, metric, val, attrs)
}

// Deprecated: [v0.120.0] use the metadatatest.AssertEqualMetric series of functions instead.
// CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values.
func (tts *TestTelemetry) CheckReceiverTraces(protocol string, acceptedSpans, droppedSpans int64) error {
return checkReceiver(tts.Telemetry, tts.id, "spans", protocol, acceptedSpans, droppedSpans)
Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ require (
go.opentelemetry.io/collector/receiver v0.119.0
go.opentelemetry.io/collector/receiver/receivertest v0.119.0
go.opentelemetry.io/collector/receiver/xreceiver v0.119.0
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/sdk/metric v1.34.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f
Expand Down Expand Up @@ -65,10 +67,8 @@ require (
go.opentelemetry.io/collector/pipeline v0.119.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.34.0 // indirect
Expand Down
51 changes: 49 additions & 2 deletions receiver/otlpreceiver/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/klauspost/compress/zstd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -592,7 +595,7 @@ func TestOTLPReceiverGRPCTracesIngestTest(t *testing.T) {

require.Len(t, sink.AllTraces(), expectedReceivedBatches)

require.NoError(t, tt.CheckReceiverTraces("grpc", int64(expectedReceivedBatches), int64(expectedIngestionBlockedRPCs)))
assertReceiverTraces(t, tt, otlpReceiverID, "grpc", int64(expectedReceivedBatches), int64(expectedIngestionBlockedRPCs))
}

// TestOTLPReceiverHTTPTracesIngestTest checks that the HTTP trace receiver
Expand Down Expand Up @@ -680,7 +683,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) {

require.Len(t, sink.AllTraces(), expectedReceivedBatches)

require.NoError(t, tt.CheckReceiverTraces("http", int64(expectedReceivedBatches), int64(expectedIngestionBlockedRPCs)))
assertReceiverTraces(t, tt, otlpReceiverID, "http", int64(expectedReceivedBatches), int64(expectedIngestionBlockedRPCs))
}

func TestGRPCInvalidTLSCredentials(t *testing.T) {
Expand Down Expand Up @@ -1231,3 +1234,47 @@ func (esc *errOrSinkConsumer) checkData(t *testing.T, data any, dataLen int) {
}
}
}

func assertReceiverTraces(t *testing.T, tt componenttest.TestTelemetry, id component.ID, transport string, accepted, refused int64) {
got, err := tt.GetMetric("otelcol_receiver_accepted_spans")
require.NoError(t, err)
metricdatatest.AssertEqual(t,
metricdata.Metrics{
Name: "otelcol_receiver_accepted_spans",
Description: "Number of spans successfully pushed into the pipeline. [alpha]",
Unit: "{spans}",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String("receiver", id.String()),
attribute.String("transport", transport)),
Value: accepted,
},
},
},
}, got, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())

got, err = tt.GetMetric("otelcol_receiver_refused_spans")
require.NoError(t, err)
metricdatatest.AssertEqual(t,
metricdata.Metrics{
Name: "otelcol_receiver_refused_spans",
Description: "Number of spans that could not be pushed into the pipeline. [alpha]",
Unit: "{spans}",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String("receiver", id.String()),
attribute.String("transport", transport)),
Value: refused,
},
},
},
}, got, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
}
58 changes: 45 additions & 13 deletions receiver/receiverhelper/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,25 @@ func TestReceiveTraceDataOp(t *testing.T) {
t.Fatalf("unexpected param: %v", params[i])
}
}
require.NoError(t, tt.CheckReceiverTraces(transport, int64(acceptedSpans), int64(refusedSpans)))

metadatatest.AssertEqualReceiverAcceptedSpans(t, tt.Telemetry,
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(acceptedSpans),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
metadatatest.AssertEqualReceiverRefusedSpans(t, tt.Telemetry,
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(refusedSpans),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
})
}

Expand Down Expand Up @@ -133,17 +151,17 @@ func TestReceiveLogsOp(t *testing.T) {
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String("receiver", receiverID.String()),
attribute.String("transport", transport)),
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(acceptedLogRecords),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
metadatatest.AssertEqualReceiverRefusedLogRecords(t, tt.Telemetry,
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String("receiver", receiverID.String()),
attribute.String("transport", transport)),
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(refusedLogRecords),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
Expand Down Expand Up @@ -268,10 +286,24 @@ func TestCheckReceiverTracesViews(t *testing.T) {
require.NotNil(t, ctx)
rec.EndTracesOp(ctx, format, 7, nil)

require.NoError(t, tt.CheckReceiverTraces(transport, 7, 0))
require.Error(t, tt.CheckReceiverTraces(transport, 7, 7))
require.Error(t, tt.CheckReceiverTraces(transport, 0, 0))
assert.Error(t, tt.CheckReceiverTraces(transport, 0, 7))
metadatatest.AssertEqualReceiverAcceptedSpans(t, tt.Telemetry,
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(7),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
metadatatest.AssertEqualReceiverRefusedSpans(t, tt.Telemetry,
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(0),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
}

func TestCheckReceiverMetricsViews(t *testing.T) {
Expand Down Expand Up @@ -314,17 +346,17 @@ func TestCheckReceiverLogsViews(t *testing.T) {
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String("receiver", receiverID.String()),
attribute.String("transport", transport)),
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(7),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
metadatatest.AssertEqualReceiverRefusedLogRecords(t, tt.Telemetry,
[]metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String("receiver", receiverID.String()),
attribute.String("transport", transport)),
attribute.String(internal.ReceiverKey, receiverID.String()),
attribute.String(internal.TransportKey, transport)),
Value: int64(0),
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
Expand Down

0 comments on commit 196bbf4

Please sign in to comment.