Skip to content

Commit 2af0cce

Browse files
committed
Deprecate CheckReceiverMetrics functions
1 parent a3c7d95 commit 2af0cce

File tree

3 files changed

+86
-13
lines changed

3 files changed

+86
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: componenttest
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate CheckReceiverMetrics in componenenttest
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12120]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: Use `metadatatest.AssertMetrics` instead of `obsreporttest.CheckReceiverMetrics`
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

component/componenttest/obsreporttest.go

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (tts *TestTelemetry) CheckReceiverLogs(protocol string, acceptedLogRecords,
8181
return checkReceiverLogs(tts.reader, tts.id, protocol, acceptedLogRecords, droppedLogRecords)
8282
}
8383

84+
// Deprecated: [v0.118.0] use metadatatest.AssertMetrics instead.
8485
// CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values.
8586
func (tts *TestTelemetry) CheckReceiverMetrics(protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
8687
return checkReceiverMetrics(tts.reader, tts.id, protocol, acceptedMetricPoints, droppedMetricPoints)

receiver/receiverhelper/obsreport_test.go

+60-13
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ import (
1212
"github.com/stretchr/testify/require"
1313
"go.opentelemetry.io/otel/attribute"
1414
"go.opentelemetry.io/otel/codes"
15+
"go.opentelemetry.io/otel/sdk/metric/metricdata"
16+
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
1517

1618
"go.opentelemetry.io/collector/component"
1719
"go.opentelemetry.io/collector/component/componenttest"
1820
"go.opentelemetry.io/collector/receiver"
1921
"go.opentelemetry.io/collector/receiver/receiverhelper/internal"
22+
"go.opentelemetry.io/collector/receiver/receiverhelper/internal/metadatatest"
2023
)
2124

2225
const (
23-
transport = "fakeTransport"
24-
format = "fakeFormat"
26+
receiverKey = "receiver"
27+
transportKey = "transport"
28+
transport = "fakeTransport"
29+
format = "fakeFormat"
2530
)
2631

2732
var (
@@ -131,8 +136,9 @@ func TestReceiveLogsOp(t *testing.T) {
131136
}
132137

133138
func TestReceiveMetricsOp(t *testing.T) {
134-
testTelemetry(t, receiverID, func(t *testing.T, tt componenttest.TestTelemetry) {
135-
parentCtx, parentSpan := tt.TelemetrySettings().TracerProvider.Tracer("test").Start(context.Background(), t.Name())
139+
testMetadataTelemetry(t, func(t *testing.T, tt metadatatest.Telemetry) {
140+
tel := tt.NewTelemetrySettings()
141+
parentCtx, parentSpan := tel.TracerProvider.Tracer("test").Start(context.Background(), t.Name())
136142
defer parentSpan.End()
137143

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

@@ -175,7 +181,7 @@ func TestReceiveMetricsOp(t *testing.T) {
175181
}
176182
}
177183

178-
require.NoError(t, tt.CheckReceiverMetrics(transport, int64(acceptedMetricPoints), int64(refusedMetricPoints)))
184+
assertMetrics(t, tt, receiverID, transport, int64(acceptedMetricPoints), int64(refusedMetricPoints))
179185
})
180186
}
181187

@@ -255,24 +261,20 @@ func TestCheckReceiverTracesViews(t *testing.T) {
255261
}
256262

257263
func TestCheckReceiverMetricsViews(t *testing.T) {
258-
tt, err := componenttest.SetupTelemetry(receiverID)
259-
require.NoError(t, err)
264+
tt := metadatatest.SetupTelemetry()
260265
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })
261266

262267
rec, err := NewObsReport(ObsReportSettings{
263268
ReceiverID: receiverID,
264269
Transport: transport,
265-
ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()},
270+
ReceiverCreateSettings: receiver.Settings{ID: receiverID, TelemetrySettings: tt.NewTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()},
266271
})
267272
require.NoError(t, err)
268273
ctx := rec.StartMetricsOp(context.Background())
269274
require.NotNil(t, ctx)
270275
rec.EndMetricsOp(ctx, format, 7, nil)
271276

272-
require.NoError(t, tt.CheckReceiverMetrics(transport, 7, 0))
273-
require.Error(t, tt.CheckReceiverMetrics(transport, 7, 7))
274-
require.Error(t, tt.CheckReceiverMetrics(transport, 0, 0))
275-
assert.Error(t, tt.CheckReceiverMetrics(transport, 0, 7))
277+
assertMetrics(t, tt, receiverID, transport, 7, 0)
276278
}
277279

278280
func TestCheckReceiverLogsViews(t *testing.T) {
@@ -303,3 +305,48 @@ func testTelemetry(t *testing.T, id component.ID, testFunc func(t *testing.T, tt
303305

304306
testFunc(t, tt)
305307
}
308+
309+
func testMetadataTelemetry(t *testing.T, testFunc func(t *testing.T, tt metadatatest.Telemetry)) {
310+
tt := metadatatest.SetupTelemetry()
311+
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })
312+
testFunc(t, tt)
313+
}
314+
315+
func assertMetrics(t *testing.T, tt metadatatest.Telemetry, receiver component.ID, transport string, expectedAccepted int64, expectedRefused int64) {
316+
tt.AssertMetrics(t, []metricdata.Metrics{
317+
{
318+
Name: "otelcol_receiver_accepted_metric_points",
319+
Description: "Number of metric points successfully pushed into the pipeline. [alpha]",
320+
Unit: "{datapoints}",
321+
Data: metricdata.Sum[int64]{
322+
Temporality: metricdata.CumulativeTemporality,
323+
IsMonotonic: true,
324+
DataPoints: []metricdata.DataPoint[int64]{
325+
{
326+
Attributes: attribute.NewSet(
327+
attribute.String(receiverKey, receiver.String()),
328+
attribute.String(transportKey, transport)),
329+
Value: expectedAccepted,
330+
},
331+
},
332+
},
333+
},
334+
{
335+
Name: "otelcol_receiver_refused_metric_points",
336+
Description: "Number of metric points that could not be pushed into the pipeline. [alpha]",
337+
Unit: "{datapoints}",
338+
Data: metricdata.Sum[int64]{
339+
Temporality: metricdata.CumulativeTemporality,
340+
IsMonotonic: true,
341+
DataPoints: []metricdata.DataPoint[int64]{
342+
{
343+
Attributes: attribute.NewSet(
344+
attribute.String(receiverKey, receiver.String()),
345+
attribute.String(transportKey, transport)),
346+
Value: expectedRefused,
347+
},
348+
},
349+
},
350+
},
351+
}, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreExemplars())
352+
}

0 commit comments

Comments
 (0)