Skip to content

Commit

Permalink
[chore] Replace usage of metadatatest.SetupTelemetry with new compone…
Browse files Browse the repository at this point in the history
…ntest

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jan 31, 2025
1 parent 0c69e17 commit 011cfb3
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 341 deletions.
21 changes: 7 additions & 14 deletions connector/servicegraphconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ func TestValidateOwnTelemetry(t *testing.T) {
}

mockMetricsExporter := newMockMetricsExporter()
set := metadatatest.SetupTelemetry()
p, err := newConnector(set.NewTelemetrySettings(), cfg, mockMetricsExporter)
tel := componenttest.NewTelemetry()
p, err := newConnector(tel.NewTelemetrySettings(), cfg, mockMetricsExporter)
require.NoError(t, err)
assert.NoError(t, p.Start(context.Background(), componenttest.NewNopHost()))

Expand All @@ -594,18 +594,11 @@ func TestValidateOwnTelemetry(t *testing.T) {

// Shutdown the connector
assert.NoError(t, p.Shutdown(context.Background()))
set.AssertMetrics(t, []metricdata.Metrics{
{
Name: "otelcol_connector_servicegraph_total_edges",
Description: "Total number of unique edges",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{Value: 2},
},
},
metadatatest.AssertEqualConnectorServicegraphTotalEdges(t, tel, metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{Value: 2},
},
}, metricdatatest.IgnoreTimestamp())
require.NoError(t, set.Shutdown(context.Background()))
Expand Down
10 changes: 4 additions & 6 deletions exporter/loadbalancingexporter/telemetry_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ package loadbalancingexporter // import "github.com/open-telemetry/opentelemetry
import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exportertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter/internal/metadatatest"
)

func getTelemetryAssets(t require.TestingT) (exporter.Settings, *metadata.TelemetryBuilder) {
s := metadatatest.SetupTelemetry()
st := s.NewSettings()
ts := st.TelemetrySettings
tb, err := metadata.NewTelemetryBuilder(ts)
s := exportertest.NewNopSettings()
tb, err := metadata.NewTelemetryBuilder(s.TelemetrySettings)
require.NoError(t, err)
return st, tb
return s, tb
}
28 changes: 8 additions & 20 deletions processor/filterprocessor/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
Expand Down Expand Up @@ -768,35 +769,22 @@ func TestFilterLogProcessorWithOTTL(t *testing.T) {
}

func TestFilterLogProcessorTelemetry(t *testing.T) {
tel := metadatatest.SetupTelemetry()
processor, err := newFilterLogsProcessor(tel.NewSettings(), &Config{
tel := componenttest.NewTelemetry()
t.Cleanup(func() { require.NoError(t, tel.Shutdown(context.Background())) })
processor, err := newFilterLogsProcessor(metadatatest.NewSettings(tel), &Config{
Logs: LogFilters{LogConditions: []string{`IsMatch(body, "operationA")`}},
})
assert.NoError(t, err)

_, err = processor.processLogs(context.Background(), constructLogs())
assert.NoError(t, err)

want := []metricdata.Metrics{
metadatatest.AssertEqualProcessorFilterDatapointsFiltered(t, tel, []metricdata.DataPoint[int64]{
{
Name: "otelcol_processor_filter_logs.filtered",
Description: "Number of logs dropped by the filter processor",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: 2,
Attributes: attribute.NewSet(attribute.String("filter", "filter")),
},
},
},
Value: 2,
Attributes: attribute.NewSet(attribute.String("filter", "filter")),
},
}

tel.AssertMetrics(t, want, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreTimestamp())
require.NoError(t, tel.Shutdown(context.Background()))
}, metricdatatest.IgnoreTimestamp())
}

func constructLogs() plog.Logs {
Expand Down
28 changes: 7 additions & 21 deletions processor/filterprocessor/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -370,18 +371,15 @@ func TestFilterMetricProcessor(t *testing.T) {
}

func TestFilterMetricProcessorTelemetry(t *testing.T) {
tel := metadatatest.SetupTelemetry()
tel := componenttest.NewTelemetry()
cfg := &Config{
Metrics: MetricFilters{
MetricConditions: []string{
"name==\"metric1\"",
},
},
}
fmp, err := newFilterMetricProcessor(
tel.NewSettings(),
cfg,
)
fmp, err := newFilterMetricProcessor(metadatatest.NewSettings(tel), cfg)
assert.NotNil(t, fmp)
assert.NoError(t, err)

Expand All @@ -395,24 +393,12 @@ func TestFilterMetricProcessorTelemetry(t *testing.T) {
}))
assert.NoError(t, err)

want := []metricdata.Metrics{
metadatatest.AssertEqualProcessorFilterDatapointsFiltered(t, tel, []metricdata.DataPoint[int64]{
{
Name: "otelcol_processor_filter_datapoints.filtered",
Description: "Number of metric data points dropped by the filter processor",
Unit: "1",
Data: metricdata.Sum[int64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[int64]{
{
Value: 1,
Attributes: attribute.NewSet(attribute.String("filter", "filter")),
},
},
},
Value: 1,
Attributes: attribute.NewSet(attribute.String("filter", "filter")),
},
}
tel.AssertMetrics(t, want, metricdatatest.IgnoreTimestamp())
}, metricdatatest.IgnoreTimestamp())
require.NoError(t, tel.Shutdown(context.Background()))
}

Expand Down
14 changes: 10 additions & 4 deletions processor/filterprocessor/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
Expand Down Expand Up @@ -284,8 +285,9 @@ func TestFilterTraceProcessorWithOTTL(t *testing.T) {
}

func TestFilterTraceProcessorTelemetry(t *testing.T) {
tel := metadatatest.SetupTelemetry()
processor, err := newFilterSpansProcessor(tel.NewSettings(), &Config{
tel := componenttest.NewTelemetry()
t.Cleanup(func() { require.NoError(t, tel.Shutdown(context.Background())) })
processor, err := newFilterSpansProcessor(metadatatest.NewSettings(tel), &Config{
Traces: TraceFilters{
SpanConditions: []string{
`name == "operationA"`,
Expand Down Expand Up @@ -315,8 +317,12 @@ func TestFilterTraceProcessorTelemetry(t *testing.T) {
},
}

tel.AssertMetrics(t, want, metricdatatest.IgnoreTimestamp())
require.NoError(t, tel.Shutdown(context.Background()))
metadatatest.AssertEqualProcessorFilterSpansFiltered(t, tel, []metricdata.DataPoint[int64]{
{
Value: 2,
Attributes: attribute.NewSet(attribute.String("filter", "filter")),
},
}, metricdatatest.IgnoreTimestamp())
}

func constructTraces() ptrace.Traces {
Expand Down
Loading

0 comments on commit 011cfb3

Please sign in to comment.