Skip to content

Commit

Permalink
Deprecate CheckReceiverMetrics functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sincejune committed Jan 18, 2025
1 parent a3c7d95 commit 5583680
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 13 deletions.
25 changes: 25 additions & 0 deletions .chloggen/deprecate-checkreceivermetrics.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: componenttest

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

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

# (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 `metadatatest.AssertMetrics` instead of `obsreporttest.CheckReceiverMetrics`

# 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 @@ -81,6 +81,7 @@ func (tts *TestTelemetry) CheckReceiverLogs(protocol string, acceptedLogRecords,
return checkReceiverLogs(tts.reader, tts.id, protocol, acceptedLogRecords, droppedLogRecords)
}

// Deprecated: [v0.118.0] use metadatatest.AssertMetrics instead.
// CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values.
func (tts *TestTelemetry) CheckReceiverMetrics(protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
return checkReceiverMetrics(tts.reader, tts.id, protocol, acceptedMetricPoints, droppedMetricPoints)
Expand Down
74 changes: 61 additions & 13 deletions receiver/receiverhelper/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receiverhelper/internal"
"go.opentelemetry.io/collector/receiver/receiverhelper/internal/metadatatest"
)

const (
transport = "fakeTransport"
format = "fakeFormat"
receiverKey = "receiver"
transportKey = "transport"
transport = "fakeTransport"
format = "fakeFormat"
)

var (
Expand Down Expand Up @@ -131,8 +136,9 @@ func TestReceiveLogsOp(t *testing.T) {
}

func TestReceiveMetricsOp(t *testing.T) {
testTelemetry(t, receiverID, func(t *testing.T, tt componenttest.TestTelemetry) {
parentCtx, parentSpan := tt.TelemetrySettings().TracerProvider.Tracer("test").Start(context.Background(), t.Name())
testMetadataTelemetry(t, func(t *testing.T, tt metadatatest.Telemetry) {
tel := tt.NewTelemetrySettings()
parentCtx, parentSpan := tel.TracerProvider.Tracer("test").Start(context.Background(), t.Name())
defer parentSpan.End()

params := []testParams{
Expand All @@ -143,7 +149,7 @@ func TestReceiveMetricsOp(t *testing.T) {
rec, err := newReceiver(ObsReportSettings{
ReceiverID: receiverID,
Transport: transport,
ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()},
ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tel, BuildInfo: component.NewDefaultBuildInfo()},
})
require.NoError(t, err)

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

require.NoError(t, tt.CheckReceiverMetrics(transport, int64(acceptedMetricPoints), int64(refusedMetricPoints)))
assertMetrics(t, tt, receiverID, transport, int64(acceptedMetricPoints), int64(refusedMetricPoints))
})
}

Expand Down Expand Up @@ -255,24 +261,20 @@ func TestCheckReceiverTracesViews(t *testing.T) {
}

func TestCheckReceiverMetricsViews(t *testing.T) {
tt, err := componenttest.SetupTelemetry(receiverID)
require.NoError(t, err)
tt := metadatatest.SetupTelemetry()
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

rec, err := NewObsReport(ObsReportSettings{
ReceiverID: receiverID,
Transport: transport,
ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()},
ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.NewTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()},
})
require.NoError(t, err)
ctx := rec.StartMetricsOp(context.Background())
require.NotNil(t, ctx)
rec.EndMetricsOp(ctx, format, 7, nil)

require.NoError(t, tt.CheckReceiverMetrics(transport, 7, 0))
require.Error(t, tt.CheckReceiverMetrics(transport, 7, 7))
require.Error(t, tt.CheckReceiverMetrics(transport, 0, 0))
assert.Error(t, tt.CheckReceiverMetrics(transport, 0, 7))
assertMetrics(t, tt, receiverID, transport, 7, 0)
}

func TestCheckReceiverLogsViews(t *testing.T) {
Expand Down Expand Up @@ -303,3 +305,49 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt

testFunc(t, tt)
}

func testMetadataTelemetry(t *testing.T, testFunc func(t *testing.T, tt metadatatest.Telemetry)) {
tt := metadatatest.SetupTelemetry()
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

testFunc(t, tt)
}

func assertMetrics(t *testing.T, tt metadatatest.Telemetry, receiver component.ID, transport string, expectedAccepted int64, expectedRefused int64) {
tt.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_receiver_accepted_metric_points",
Description: "Number of metric points successfully pushed into the pipeline. [alpha]",
Unit: "{datapoints}",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String(receiverKey, receiver.String()),
attribute.String(transportKey, transport)),
Value: expectedAccepted,
},
},
},
},
{
Name: "otelcol_receiver_refused_metric_points",
Description: "Number of metric points that could not be pushed into the pipeline. [alpha]",
Unit: "{datapoints}",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Attributes: attribute.NewSet(
attribute.String(receiverKey, receiver.String()),
attribute.String(transportKey, transport)),
Value: expectedRefused,
},
},
},
},
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
}

0 comments on commit 5583680

Please sign in to comment.