Skip to content

Commit

Permalink
Fix based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigran Najaryan committed Jun 20, 2019
1 parent 1a51c94 commit 8a7c055
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/occollector/app/builder/receivers_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (rb *ReceiversBuilder) attachReceiverToPipelines(
if err == factories.ErrDataTypeIsNotSupported {
return fmt.Errorf(
"receiver %s does not support %s but some pipelines that "+
"want to process %s are attached to the receiever",
"want to process %s are attached to the receiver",
config.Name(),
dataType.GetString(),
dataType.GetString())
Expand Down
34 changes: 17 additions & 17 deletions cmd/occollector/app/builder/receivers_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,23 @@ func testReceivers(
}
}

func TestReceiversBuilder_Error(t *testing.T) {
//config, err := configv2.LoadConfigFile(t, "testdata/pipelines_builder.yaml")
//require.Nil(t, err)
//
//// Corrupt the pipeline, change data type to metrics. We have to forcedly do it here
//// since there is no way to have such config loaded by LoadConfigFile, it would not
//// pass validation. We are doing this to test failure mode of PipelinesBuilder.
//pipeline := config.Pipelines["traces"]
//pipeline.InputType = configmodels.MetricsDataType
//
//exporters, err := NewExportersBuilder(zap.NewNop(), config).Build()
//
//// This should fail because "attributes" processor defined in the config does
//// not support metrics data type.
//_, err = NewPipelinesBuilder(zap.NewNop(), config, exporters).Build()
//
//assert.NotNil(t, err)
func TestReceiversBuilder_DataTypeError(t *testing.T) {
config, err := configv2.LoadConfigFile(t, "testdata/pipelines_builder.yaml")
require.Nil(t, err)

// Make examplereceiver to "unsupport" trace data type.
receiver := config.Receivers["examplereceiver"]
receiver.(*configv2.ExampleReceiver).FailTraceCreation = true

// Build the pipeline
allExporters, err := NewExportersBuilder(zap.NewNop(), config).Build()
pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), config, allExporters).Build()
receivers, err := NewReceiversBuilder(zap.NewNop(), config, pipelineProcessors).Build()

// This should fail because "examplereceiver" is attached to "traces" pipeline
// which is a configuration error.
assert.NotNil(t, err)
assert.Nil(t, receivers)
}

func TestReceiversBuilder_StartAll(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/configmodels/configmodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ type ReceiverSettings struct {
Endpoint string `mapstructure:"endpoint"`
}

// Name gets the exporter name.
// Name gets the receiver name.
func (rs *ReceiverSettings) Name() string {
return rs.NameVal
}

// SetName sets the exporter name.
// SetName sets the receiver name.
func (rs *ReceiverSettings) SetName(name string) {
rs.NameVal = name
}
Expand Down
14 changes: 12 additions & 2 deletions internal/configv2/example_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import (
type ExampleReceiver struct {
configmodels.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
ExtraSetting string `mapstructure:"extra"`

// FailTraceCreation causes CreateTraceReceiver to fail. Useful for testing.
FailTraceCreation bool `mapstructure:"-"`

// FailMetricsCreation causes CreateTraceReceiver to fail. Useful for testing.
FailMetricsCreation bool `mapstructure:"-"`
}

// ExampleReceiverFactory is factory for ExampleReceiver.
Expand Down Expand Up @@ -64,7 +70,9 @@ func (f *ExampleReceiverFactory) CreateTraceReceiver(
cfg configmodels.Receiver,
nextConsumer consumer.TraceConsumer,
) (receiver.TraceReceiver, error) {
// Not used for this test, just return nil
if cfg.(*ExampleReceiver).FailTraceCreation {
return nil, factories.ErrDataTypeIsNotSupported
}
return &ExampleReceiverProducer{TraceConsumer: nextConsumer}, nil
}

Expand All @@ -73,7 +81,9 @@ func (f *ExampleReceiverFactory) CreateMetricsReceiver(
cfg configmodels.Receiver,
nextConsumer consumer.MetricsConsumer,
) (receiver.MetricsReceiver, error) {
// Not used for this test, just return nil
if cfg.(*ExampleReceiver).FailMetricsCreation {
return nil, factories.ErrDataTypeIsNotSupported
}
return &ExampleReceiverProducer{MetricsConsumer: nextConsumer}, nil
}

Expand Down

0 comments on commit 8a7c055

Please sign in to comment.