Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate NopExporter, add NopConsumer #1972

Merged
merged 2 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions consumer/consumertest/nop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package consumertest

import (
"context"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/pdata"
)

var (
nopInstance = &nopConsumer{}
)

type nopConsumer struct{}

func (nc *nopConsumer) ConsumeTraces(context.Context, pdata.Traces) error {
return nil
}

func (nc *nopConsumer) ConsumeMetrics(context.Context, pdata.Metrics) error {
return nil
}

func (nc *nopConsumer) ConsumeLogs(context.Context, pdata.Logs) error {
return nil
}

// NewTracesNop creates an TraceConsumer that just drops the received data.
func NewTracesNop() consumer.TraceConsumer {
return nopInstance
}

// NewMetricsNop creates an MetricsConsumer that just drops the received data.
func NewMetricsNop() consumer.MetricsConsumer {
return nopInstance
}

// NewLogsNop creates an LogsConsumer that just drops the received data.
func NewLogsNop() consumer.LogsConsumer {
return nopInstance
}
42 changes: 42 additions & 0 deletions consumer/consumertest/nop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package consumertest

import (
"context"
"testing"

"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/consumer/pdata"
)

func TestNewNopTraces(t *testing.T) {
nt := NewTracesNop()
require.NotNil(t, nt)
require.NoError(t, nt.ConsumeTraces(context.Background(), pdata.NewTraces()))
}

func TestNewNopMetrics(t *testing.T) {
nm := NewMetricsNop()
require.NotNil(t, nm)
require.NoError(t, nm.ConsumeMetrics(context.Background(), pdata.NewMetrics()))
}

func TestNopLogsConsumer(t *testing.T) {
nl := NewLogsNop()
require.NotNil(t, nl)
require.NoError(t, nl.ConsumeLogs(context.Background(), pdata.NewLogs()))
}
14 changes: 10 additions & 4 deletions exporter/exporterhelper/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/consumer/pdata"
)

const typeStr = "test"
Expand All @@ -35,9 +35,15 @@ var (
TypeVal: typeStr,
NameVal: typeStr,
}
nopTracesExporter = exportertest.NewNopTraceExporter()
nopMetricsExporter = exportertest.NewNopMetricsExporter()
nopLogsExporter = exportertest.NewNopLogsExporter()
nopTracesExporter, _ = NewTraceExporter(defaultCfg, func(ctx context.Context, td pdata.Traces) (droppedSpans int, err error) {
return 0, nil
})
nopMetricsExporter, _ = NewMetricsExporter(defaultCfg, func(ctx context.Context, md pdata.Metrics) (droppedTimeSeries int, err error) {
return 0, nil
})
nopLogsExporter, _ = NewLogsExporter(defaultCfg, func(ctx context.Context, md pdata.Logs) (droppedTimeSeries int, err error) {
return 0, nil
})
)

func TestNewFactory(t *testing.T) {
Expand Down
35 changes: 10 additions & 25 deletions exporter/exportertest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,22 @@ import (
"go.opentelemetry.io/collector/consumer/pdata"
)

const (
nopTraceExporterName = "nop_trace"
nopMetricsExporterName = "nop_metrics"
nopLogsExporterName = "nop_log"
)

type nopExporter struct {
name string
retError error
}
type nopExporter struct{}

func (ne *nopExporter) Start(context.Context, component.Host) error {
return nil
}

func (ne *nopExporter) ConsumeTraces(context.Context, pdata.Traces) error {
return ne.retError
return nil
}

func (ne *nopExporter) ConsumeMetrics(context.Context, pdata.Metrics) error {
return ne.retError
return nil
}

func (ne *nopExporter) ConsumeLogs(context.Context, pdata.Logs) error {
return ne.retError
return nil
}

// Shutdown stops the exporter and is invoked during shutdown.
Expand All @@ -54,25 +45,19 @@ func (ne *nopExporter) Shutdown(context.Context) error {
}

// NewNopTraceExporter creates an TraceExporter that just drops the received data.
// Deprecated: Use consumertest.NewNopTraces.
func NewNopTraceExporter() component.TraceExporter {
ne := &nopExporter{
name: nopTraceExporterName,
}
return ne
return &nopExporter{}
}

// NewNopMetricsExporter creates an MetricsExporter that just drops the received data.
// Deprecated: Use consumertest.NewNopMetrics.
func NewNopMetricsExporter() component.MetricsExporter {
ne := &nopExporter{
name: nopMetricsExporterName,
}
return ne
return &nopExporter{}
}

// NewNopLogsExporter creates an LogsExporter that just drops the received data.
// Deprecated: Use consumertest.NewNopLogs.
func NewNopLogsExporter() component.LogsExporter {
ne := &nopExporter{
name: nopLogsExporterName,
}
return ne
return &nopExporter{}
}
1 change: 1 addition & 0 deletions exporter/exportertest/nop_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package exportertest

import (
Expand Down
14 changes: 7 additions & 7 deletions processor/attributesprocessor/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/processor/filterconfig"
"go.opentelemetry.io/collector/internal/processor/filterset"
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) {
{Key: "attribute1", Action: processorhelper.DELETE},
}

tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{Logger: zap.NewNop()}, oCfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{Logger: zap.NewNop()}, oCfg, consumertest.NewTracesNop())
require.Nil(t, err)
require.NotNil(t, tp)
for i := range testCases {
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestAttributes_FilterSpans(t *testing.T) {
},
Config: *createConfig(filterset.Strict),
}
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -278,7 +278,7 @@ func TestAttributes_FilterSpansByNameStrict(t *testing.T) {
SpanNames: []string{"dont_apply"},
Config: *createConfig(filterset.Strict),
}
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -346,7 +346,7 @@ func TestAttributes_FilterSpansByNameRegexp(t *testing.T) {
SpanNames: []string{".*dont_apply$"},
Config: *createConfig(filterset.Regexp),
}
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -405,7 +405,7 @@ func TestAttributes_Hash(t *testing.T) {
{Key: "user.authenticated", Action: processorhelper.HASH},
}

tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
require.Nil(t, err)
require.NotNil(t, tp)

Expand Down Expand Up @@ -449,7 +449,7 @@ func BenchmarkAttributes_FilterSpansByName(b *testing.B) {
oCfg.Include = &filterconfig.MatchProperties{
SpanNames: []string{"^apply.*"},
}
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
require.Nil(b, err)
require.NotNil(b, tp)

Expand Down
10 changes: 5 additions & 5 deletions processor/attributesprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/processor/processorhelper"
)

Expand All @@ -49,7 +49,7 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
func TestFactoryCreateTraceProcessor_EmptyActions(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
ap, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
ap, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
assert.Error(t, err)
assert.Nil(t, ap)
}
Expand All @@ -62,7 +62,7 @@ func TestFactoryCreateTraceProcessor_InvalidActions(t *testing.T) {
oCfg.Actions = []processorhelper.ActionKeyValue{
{Key: "", Value: 123, Action: processorhelper.UPSERT},
}
ap, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
ap, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
assert.Error(t, err)
assert.Nil(t, ap)
}
Expand All @@ -75,7 +75,7 @@ func TestFactoryCreateTraceProcessor(t *testing.T) {
{Key: "a key", Action: processorhelper.DELETE},
}

tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err := factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
assert.NotNil(t, tp)
assert.NoError(t, err)

Expand All @@ -86,7 +86,7 @@ func TestFactoryCreateTraceProcessor(t *testing.T) {
oCfg.Actions = []processorhelper.ActionKeyValue{
{Action: processorhelper.DELETE},
}
tp, err = factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, exportertest.NewNopTraceExporter())
tp, err = factory.CreateTraceProcessor(context.Background(), component.ProcessorCreateParams{}, cfg, consumertest.NewTracesNop())
assert.Nil(t, tp)
assert.Error(t, err)
}
Expand Down
7 changes: 4 additions & 3 deletions processor/cloningfanoutconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data/testdata"
)

func TestTraceProcessorCloningNotMultiplexing(t *testing.T) {
nop := exportertest.NewNopTraceExporter()
nop := consumertest.NewTracesNop()
tfc := NewTracesCloningFanOutConnector([]consumer.TraceConsumer{nop})
assert.Same(t, nop, tfc)
}
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestTraceProcessorCloningMultiplexing(t *testing.T) {
}

func TestMetricsProcessorCloningNotMultiplexing(t *testing.T) {
nop := exportertest.NewNopMetricsExporter()
nop := consumertest.NewMetricsNop()
mfc := NewMetricsFanOutConnector([]consumer.MetricsConsumer{nop})
assert.Same(t, nop, mfc)
}
Expand Down Expand Up @@ -112,7 +113,7 @@ func TestMetricsProcessorCloningMultiplexing(t *testing.T) {
}

func TestLogsProcessorCloningNotMultiplexing(t *testing.T) {
nop := exportertest.NewNopLogsExporter()
nop := consumertest.NewLogsNop()
lfc := NewLogsCloningFanOutConnector([]consumer.LogsConsumer{nop})
assert.Same(t, nop, lfc)
}
Expand Down
7 changes: 4 additions & 3 deletions processor/fanoutconnector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/internal/data/testdata"
)

func TestTracesProcessorNotMultiplexing(t *testing.T) {
nop := exportertest.NewNopTraceExporter()
nop := consumertest.NewTracesNop()
tfc := NewTracesFanOutConnector([]consumer.TraceConsumer{nop})
assert.Same(t, nop, tfc)
}
Expand Down Expand Up @@ -86,7 +87,7 @@ func TestTraceProcessorWhenOneErrors(t *testing.T) {
}

func TestMetricsProcessorNotMultiplexing(t *testing.T) {
nop := exportertest.NewNopMetricsExporter()
nop := consumertest.NewMetricsNop()
mfc := NewMetricsFanOutConnector([]consumer.MetricsConsumer{nop})
assert.Same(t, nop, mfc)
}
Expand Down Expand Up @@ -145,7 +146,7 @@ func TestMetricsProcessorWhenOneErrors(t *testing.T) {
}

func TestLogsProcessorNotMultiplexing(t *testing.T) {
nop := exportertest.NewNopLogsExporter()
nop := consumertest.NewLogsNop()
lfc := NewLogsFanOutConnector([]consumer.LogsConsumer{nop})
assert.Same(t, nop, lfc)
}
Expand Down
Loading