Skip to content

Commit

Permalink
Remove pairwise connector types.
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Dec 7, 2022
1 parent 98f5a16 commit 6fcecdf
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 326 deletions.
114 changes: 76 additions & 38 deletions component/componenttest/nop_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,72 +59,110 @@ func NewNopConnectorFactory() component.ConnectorFactory {
)
}

func createTracesToTracesConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Traces) (component.TracesToTracesConnector, error) {
return nopConnectorInstance, nil
func createTracesToTracesConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Traces) (component.TracesConnector, error) {
c := newNopConnector()
c.consumeTraces = c.consumeTracesToTraces
return c, nil
}
func createTracesToMetricsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Metrics) (component.TracesToMetricsConnector, error) {
return nopConnectorInstance, nil
func createTracesToMetricsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Metrics) (component.TracesConnector, error) {
c := newNopConnector()
c.consumeTraces = c.consumeTracesToMetrics
return c, nil
}
func createTracesToLogsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Logs) (component.TracesToLogsConnector, error) {
return nopConnectorInstance, nil
func createTracesToLogsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Logs) (component.TracesConnector, error) {
c := newNopConnector()
c.consumeTraces = c.consumeTracesToLogs
return c, nil
}

func createMetricsToTracesConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Traces) (component.MetricsToTracesConnector, error) {
return nopConnectorInstance, nil
func createMetricsToTracesConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Traces) (component.MetricsConnector, error) {
c := newNopConnector()
c.consumeMetrics = c.consumeMetricsToTraces
return c, nil
}
func createMetricsToMetricsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Metrics) (component.MetricsToMetricsConnector, error) {
return nopConnectorInstance, nil
func createMetricsToMetricsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Metrics) (component.MetricsConnector, error) {
c := newNopConnector()
c.consumeMetrics = c.consumeMetricsToMetrics
return c, nil
}
func createMetricsToLogsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Logs) (component.MetricsToLogsConnector, error) {
return nopConnectorInstance, nil
func createMetricsToLogsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Logs) (component.MetricsConnector, error) {
c := newNopConnector()
c.consumeMetrics = c.consumeMetricsToLogs
return c, nil
}

func createLogsToTracesConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Traces) (component.LogsToTracesConnector, error) {
return nopConnectorInstance, nil
func createLogsToTracesConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Traces) (component.LogsConnector, error) {
c := newNopConnector()
c.consumeLogs = c.consumeLogsToTraces
return c, nil
}
func createLogsToMetricsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Metrics) (component.LogsToMetricsConnector, error) {
return nopConnectorInstance, nil
func createLogsToMetricsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Metrics) (component.LogsConnector, error) {
c := newNopConnector()
c.consumeLogs = c.consumeLogsToMetrics
return c, nil
}
func createLogsToLogsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Logs) (component.LogsToLogsConnector, error) {
return nopConnectorInstance, nil
func createLogsToLogsConnector(context.Context, component.ConnectorCreateSettings, component.Config, consumer.Logs) (component.LogsConnector, error) {
c := newNopConnector()
c.consumeLogs = c.consumeLogsToLogs
return c, nil
}

var nopConnectorInstance = &nopConnector{
Consumer: consumertest.NewNop(),
func newNopConnector() *nopConnector {
return &nopConnector{
Consumer: consumertest.NewNop(),
}
}

// nopConnector stores consumed traces and metrics for testing purposes.
type nopConnector struct {
nopComponent
consumertest.Consumer
consumeTraces consumer.ConsumeTracesFunc
consumeMetrics consumer.ConsumeMetricsFunc
consumeLogs consumer.ConsumeLogsFunc
}

// ConsumeTraces delegates to the appropriate ConsumeTracesToX method
func (c *nopConnector) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
return c.consumeTraces(ctx, td)
}

// ConsumeMetrics delegates to the appropriate ConsumeMetricsToX method
func (c *nopConnector) ConsumeMetrics(ctx context.Context, td pmetric.Metrics) error {
return c.consumeMetrics(ctx, td)
}

// ConsumeLogs delegates to the appropriate ConsumeLogsToX method
func (c *nopConnector) ConsumeLogs(ctx context.Context, td plog.Logs) error {
return c.consumeLogs(ctx, td)
}

func (c *nopConnector) ConsumeTracesToTraces(ctx context.Context, td ptrace.Traces) error {
return nil
func (c *nopConnector) consumeTracesToTraces(ctx context.Context, td ptrace.Traces) error {
return c.Consumer.ConsumeTraces(ctx, td)
}
func (c *nopConnector) ConsumeTracesToMetrics(ctx context.Context, td ptrace.Traces) error {
return nil
func (c *nopConnector) consumeTracesToMetrics(ctx context.Context, td ptrace.Traces) error {
return c.Consumer.ConsumeMetrics(ctx, pmetric.NewMetrics())
}
func (c *nopConnector) ConsumeTracesToLogs(ctx context.Context, td ptrace.Traces) error {
return nil
func (c *nopConnector) consumeTracesToLogs(ctx context.Context, td ptrace.Traces) error {
return c.Consumer.ConsumeLogs(ctx, plog.NewLogs())
}

func (c *nopConnector) ConsumeMetricsToTraces(ctx context.Context, md pmetric.Metrics) error {
return nil
func (c *nopConnector) consumeMetricsToTraces(ctx context.Context, md pmetric.Metrics) error {
return c.Consumer.ConsumeTraces(ctx, ptrace.NewTraces())
}
func (c *nopConnector) ConsumeMetricsToMetrics(ctx context.Context, md pmetric.Metrics) error {
return nil
func (c *nopConnector) consumeMetricsToMetrics(ctx context.Context, md pmetric.Metrics) error {
return c.Consumer.ConsumeMetrics(ctx, md)
}
func (c *nopConnector) ConsumeMetricsToLogs(ctx context.Context, md pmetric.Metrics) error {
return nil
func (c *nopConnector) consumeMetricsToLogs(ctx context.Context, md pmetric.Metrics) error {
return c.Consumer.ConsumeLogs(ctx, plog.NewLogs())
}

func (c *nopConnector) ConsumeLogsToTraces(ctx context.Context, ld plog.Logs) error {
return nil
func (c *nopConnector) consumeLogsToTraces(ctx context.Context, ld plog.Logs) error {
return c.Consumer.ConsumeTraces(ctx, ptrace.NewTraces())
}
func (c *nopConnector) ConsumeLogsToMetrics(ctx context.Context, ld plog.Logs) error {
return nil
func (c *nopConnector) consumeLogsToMetrics(ctx context.Context, ld plog.Logs) error {
return c.Consumer.ConsumeMetrics(ctx, pmetric.NewMetrics())
}
func (c *nopConnector) ConsumeLogsToLogs(ctx context.Context, ld plog.Logs) error {
return nil
func (c *nopConnector) consumeLogsToLogs(ctx context.Context, ld plog.Logs) error {
return c.Consumer.ConsumeLogs(ctx, ld)
}
18 changes: 9 additions & 9 deletions component/componenttest/nop_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,54 +39,54 @@ func TestNewNopConnectorFactory(t *testing.T) {
tracesToTraces, err := factory.CreateTracesToTracesConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, tracesToTraces.Start(context.Background(), NewNopHost()))
assert.NoError(t, tracesToTraces.ConsumeTracesToTraces(context.Background(), ptrace.NewTraces()))
assert.NoError(t, tracesToTraces.ConsumeTraces(context.Background(), ptrace.NewTraces()))
assert.NoError(t, tracesToTraces.Shutdown(context.Background()))

tracesToMetrics, err := factory.CreateTracesToMetricsConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, tracesToMetrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, tracesToMetrics.ConsumeTracesToMetrics(context.Background(), ptrace.NewTraces()))
assert.NoError(t, tracesToMetrics.ConsumeTraces(context.Background(), ptrace.NewTraces()))
assert.NoError(t, tracesToMetrics.Shutdown(context.Background()))

tracesToLogs, err := factory.CreateTracesToLogsConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, tracesToLogs.Start(context.Background(), NewNopHost()))
assert.NoError(t, tracesToLogs.ConsumeTracesToLogs(context.Background(), ptrace.NewTraces()))
assert.NoError(t, tracesToLogs.ConsumeTraces(context.Background(), ptrace.NewTraces()))
assert.NoError(t, tracesToLogs.Shutdown(context.Background()))

metricsToTraces, err := factory.CreateMetricsToTracesConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, metricsToTraces.Start(context.Background(), NewNopHost()))
assert.NoError(t, metricsToTraces.ConsumeMetricsToTraces(context.Background(), pmetric.NewMetrics()))
assert.NoError(t, metricsToTraces.ConsumeMetrics(context.Background(), pmetric.NewMetrics()))
assert.NoError(t, metricsToTraces.Shutdown(context.Background()))

metricsToMetrics, err := factory.CreateMetricsToMetricsConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, metricsToMetrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, metricsToMetrics.ConsumeMetricsToMetrics(context.Background(), pmetric.NewMetrics()))
assert.NoError(t, metricsToMetrics.ConsumeMetrics(context.Background(), pmetric.NewMetrics()))
assert.NoError(t, metricsToMetrics.Shutdown(context.Background()))

metricsToLogs, err := factory.CreateMetricsToLogsConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, metricsToLogs.Start(context.Background(), NewNopHost()))
assert.NoError(t, metricsToLogs.ConsumeMetricsToLogs(context.Background(), pmetric.NewMetrics()))
assert.NoError(t, metricsToLogs.ConsumeMetrics(context.Background(), pmetric.NewMetrics()))
assert.NoError(t, metricsToLogs.Shutdown(context.Background()))

logsToTraces, err := factory.CreateLogsToTracesConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, logsToTraces.Start(context.Background(), NewNopHost()))
assert.NoError(t, logsToTraces.ConsumeLogsToTraces(context.Background(), plog.NewLogs()))
assert.NoError(t, logsToTraces.ConsumeLogs(context.Background(), plog.NewLogs()))
assert.NoError(t, logsToTraces.Shutdown(context.Background()))

logsToMetrics, err := factory.CreateLogsToMetricsConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, logsToMetrics.Start(context.Background(), NewNopHost()))
assert.NoError(t, logsToMetrics.ConsumeLogsToMetrics(context.Background(), plog.NewLogs()))
assert.NoError(t, logsToMetrics.ConsumeLogs(context.Background(), plog.NewLogs()))
assert.NoError(t, logsToMetrics.Shutdown(context.Background()))

logsToLogs, err := factory.CreateLogsToLogsConnector(context.Background(), NewNopConnectorCreateSettings(), cfg, consumertest.NewNop())
require.NoError(t, err)
assert.NoError(t, logsToLogs.Start(context.Background(), NewNopHost()))
assert.NoError(t, logsToLogs.ConsumeLogsToLogs(context.Background(), plog.NewLogs()))
assert.NoError(t, logsToLogs.ConsumeLogs(context.Background(), plog.NewLogs()))
assert.NoError(t, logsToLogs.Shutdown(context.Background()))
}
Loading

0 comments on commit 6fcecdf

Please sign in to comment.