From 56332a0b5ebc3317c90e81a463522bcd890bd844 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 8 Mar 2021 11:26:10 -0800 Subject: [PATCH] Simplify builders for components, remove unnecessary builders Signed-off-by: Bogdan Drutu --- service/builder/exporters_builder.go | 22 ++++++--------- service/builder/exporters_builder_test.go | 10 +++---- service/builder/extensions_builder.go | 18 +++++------- service/builder/pipelines_builder.go | 28 ++++++++----------- service/builder/pipelines_builder_test.go | 16 +++++------ service/builder/receivers_builder.go | 23 ++++++--------- service/builder/receivers_builder_test.go | 34 +++++++++++------------ service/service.go | 8 +++--- 8 files changed, 71 insertions(+), 88 deletions(-) diff --git a/service/builder/exporters_builder.go b/service/builder/exporters_builder.go index 33d227ef763..11932130dc9 100644 --- a/service/builder/exporters_builder.go +++ b/service/builder/exporters_builder.go @@ -140,32 +140,28 @@ type dataTypeRequirements map[configmodels.DataType]dataTypeRequirement // Data type requirements for all exporters. type exportersRequiredDataTypes map[configmodels.Exporter]dataTypeRequirements -// ExportersBuilder builds exporters from config. -type ExportersBuilder struct { +// exportersBuilder builds exporters from config. +type exportersBuilder struct { logger *zap.Logger appInfo component.ApplicationStartInfo config *configmodels.Config factories map[configmodels.Type]component.ExporterFactory } -// NewExportersBuilder creates a new ExportersBuilder. Call BuildExporters() on the returned value. -func NewExportersBuilder( +// BuildExporters builds Exporters from config. +func BuildExporters( logger *zap.Logger, appInfo component.ApplicationStartInfo, config *configmodels.Config, factories map[configmodels.Type]component.ExporterFactory, -) *ExportersBuilder { - return &ExportersBuilder{logger.With(zap.String(kindLogKey, kindLogsExporter)), appInfo, config, factories} -} - -// BuildExporters exporters from config. -func (eb *ExportersBuilder) Build() (Exporters, error) { - exporters := make(Exporters) +) (Exporters, error) { + eb := &exportersBuilder{logger.With(zap.String(kindLogKey, kindLogsExporter)), appInfo, config, factories} // We need to calculate required input data types for each exporter so that we know // which data type must be started for each exporter. exporterInputDataTypes := eb.calcExportersRequiredDataTypes() + exporters := make(Exporters) // BuildExporters exporters based on configuration and required input data types. for _, cfg := range eb.config.Exporters { componentLogger := eb.logger.With(zap.String(typeLogKey, string(cfg.Type())), zap.String(nameLogKey, cfg.Name())) @@ -180,7 +176,7 @@ func (eb *ExportersBuilder) Build() (Exporters, error) { return exporters, nil } -func (eb *ExportersBuilder) calcExportersRequiredDataTypes() exportersRequiredDataTypes { +func (eb *exportersBuilder) calcExportersRequiredDataTypes() exportersRequiredDataTypes { // Go over all pipelines. The data type of the pipeline defines what data type // each exporter is expected to receive. Collect all required types for each @@ -213,7 +209,7 @@ func (eb *ExportersBuilder) calcExportersRequiredDataTypes() exportersRequiredDa return result } -func (eb *ExportersBuilder) buildExporter( +func (eb *exportersBuilder) buildExporter( ctx context.Context, logger *zap.Logger, appInfo component.ApplicationStartInfo, diff --git a/service/builder/exporters_builder_test.go b/service/builder/exporters_builder_test.go index cc422330d47..a338593827a 100644 --- a/service/builder/exporters_builder_test.go +++ b/service/builder/exporters_builder_test.go @@ -61,7 +61,7 @@ func TestExportersBuilder_Build(t *testing.T) { }, } - exporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + exporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) require.NotNil(t, exporters) @@ -90,7 +90,7 @@ func TestExportersBuilder_Build(t *testing.T) { // This should result in creating an exporter that has none of consumption // functions set. delete(cfg.Service.Pipelines, "trace") - exporters, err = NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + exporters, err = BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NotNil(t, exporters) assert.NoError(t, err) @@ -131,7 +131,7 @@ func TestExportersBuilder_BuildLogs(t *testing.T) { }, } - exporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + exporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) require.NotNil(t, exporters) @@ -156,7 +156,7 @@ func TestExportersBuilder_BuildLogs(t *testing.T) { // This should result in creating an exporter that has none of consumption // functions set. delete(cfg.Service.Pipelines, "logs") - exporters, err = NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + exporters, err = BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NotNil(t, exporters) assert.Nil(t, err) @@ -260,7 +260,7 @@ func TestExportersBuilder_ErrorOnNilExporter(t *testing.T) { }, } - exporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, fm).Build() + exporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, fm) assert.Error(t, err) assert.Zero(t, len(exporters)) }) diff --git a/service/builder/extensions_builder.go b/service/builder/extensions_builder.go index cfbdc2486c2..d4331091035 100644 --- a/service/builder/extensions_builder.go +++ b/service/builder/extensions_builder.go @@ -110,28 +110,24 @@ func (exts Extensions) ToMap() map[configmodels.NamedEntity]component.Extension return result } -// ExportersBuilder builds exporters from config. -type ExtensionsBuilder struct { +// exportersBuilder builds exporters from config. +type extensionsBuilder struct { logger *zap.Logger appInfo component.ApplicationStartInfo config *configmodels.Config factories map[configmodels.Type]component.ExtensionFactory } -// NewExportersBuilder creates a new ExportersBuilder. Call BuildExporters() on the returned value. -func NewExtensionsBuilder( +// BuildExtensions builds Extensions from config. +func BuildExtensions( logger *zap.Logger, appInfo component.ApplicationStartInfo, config *configmodels.Config, factories map[configmodels.Type]component.ExtensionFactory, -) *ExtensionsBuilder { - return &ExtensionsBuilder{logger.With(zap.String(kindLogKey, kindLogExtension)), appInfo, config, factories} -} +) (Extensions, error) { + eb := &extensionsBuilder{logger.With(zap.String(kindLogKey, kindLogExtension)), appInfo, config, factories} -// Build extensions from config. -func (eb *ExtensionsBuilder) Build() (Extensions, error) { extensions := make(Extensions) - for _, extName := range eb.config.Service.Extensions { extCfg, exists := eb.config.Extensions[extName] if !exists { @@ -150,7 +146,7 @@ func (eb *ExtensionsBuilder) Build() (Extensions, error) { return extensions, nil } -func (eb *ExtensionsBuilder) buildExtension(logger *zap.Logger, appInfo component.ApplicationStartInfo, cfg configmodels.Extension) (*builtExtension, error) { +func (eb *extensionsBuilder) buildExtension(logger *zap.Logger, appInfo component.ApplicationStartInfo, cfg configmodels.Extension) (*builtExtension, error) { factory := eb.factories[cfg.Type()] if factory == nil { return nil, fmt.Errorf("extension factory for type %q is not configured", cfg.Type()) diff --git a/service/builder/pipelines_builder.go b/service/builder/pipelines_builder.go index 45ed409df3b..6ee6c1a23d9 100644 --- a/service/builder/pipelines_builder.go +++ b/service/builder/pipelines_builder.go @@ -78,8 +78,8 @@ func (bps BuiltPipelines) ShutdownProcessors(ctx context.Context) error { return consumererror.CombineErrors(errs) } -// PipelinesBuilder builds pipelines from config. -type PipelinesBuilder struct { +// pipelinesBuilder builds Pipelines from config. +type pipelinesBuilder struct { logger *zap.Logger appInfo component.ApplicationStartInfo config *configmodels.Config @@ -87,22 +87,18 @@ type PipelinesBuilder struct { factories map[configmodels.Type]component.ProcessorFactory } -// NewPipelinesBuilder creates a new PipelinesBuilder. Requires exporters to be already -// built via ExportersBuilder. Call BuildProcessors() on the returned value. -func NewPipelinesBuilder( +// BuildPipelines builds pipeline processors from config. Requires exporters to be already +// built via BuildExporters. +func BuildPipelines( logger *zap.Logger, appInfo component.ApplicationStartInfo, config *configmodels.Config, exporters Exporters, factories map[configmodels.Type]component.ProcessorFactory, -) *PipelinesBuilder { - return &PipelinesBuilder{logger, appInfo, config, exporters, factories} -} +) (BuiltPipelines, error) { + pb := &pipelinesBuilder{logger, appInfo, config, exporters, factories} -// BuildProcessors pipeline processors from config. -func (pb *PipelinesBuilder) Build() (BuiltPipelines, error) { pipelineProcessors := make(BuiltPipelines) - for _, pipeline := range pb.config.Service.Pipelines { firstProcessor, err := pb.buildPipeline(context.Background(), pipeline) if err != nil { @@ -117,7 +113,7 @@ func (pb *PipelinesBuilder) Build() (BuiltPipelines, error) { // Builds a pipeline of processors. Returns the first processor in the pipeline. // The last processor in the pipeline will be plugged to fan out the data into exporters // that are configured for this pipeline. -func (pb *PipelinesBuilder) buildPipeline(ctx context.Context, pipelineCfg *configmodels.Pipeline) (*builtPipeline, error) { +func (pb *pipelinesBuilder) buildPipeline(ctx context.Context, pipelineCfg *configmodels.Pipeline) (*builtPipeline, error) { // BuildProcessors the pipeline backwards. @@ -219,7 +215,7 @@ func (pb *PipelinesBuilder) buildPipeline(ctx context.Context, pipelineCfg *conf } // Converts the list of exporter names to a list of corresponding builtExporters. -func (pb *PipelinesBuilder) getBuiltExportersByNames(exporterNames []string) []*builtExporter { +func (pb *pipelinesBuilder) getBuiltExportersByNames(exporterNames []string) []*builtExporter { var result []*builtExporter for _, name := range exporterNames { exporter := pb.exporters[pb.config.Exporters[name]] @@ -229,7 +225,7 @@ func (pb *PipelinesBuilder) getBuiltExportersByNames(exporterNames []string) []* return result } -func (pb *PipelinesBuilder) buildFanoutExportersTraceConsumer(exporterNames []string) consumer.TracesConsumer { +func (pb *pipelinesBuilder) buildFanoutExportersTraceConsumer(exporterNames []string) consumer.TracesConsumer { builtExporters := pb.getBuiltExportersByNames(exporterNames) var exporters []consumer.TracesConsumer @@ -241,7 +237,7 @@ func (pb *PipelinesBuilder) buildFanoutExportersTraceConsumer(exporterNames []st return processor.NewTracesFanOutConnector(exporters) } -func (pb *PipelinesBuilder) buildFanoutExportersMetricsConsumer(exporterNames []string) consumer.MetricsConsumer { +func (pb *pipelinesBuilder) buildFanoutExportersMetricsConsumer(exporterNames []string) consumer.MetricsConsumer { builtExporters := pb.getBuiltExportersByNames(exporterNames) var exporters []consumer.MetricsConsumer @@ -253,7 +249,7 @@ func (pb *PipelinesBuilder) buildFanoutExportersMetricsConsumer(exporterNames [] return processor.NewMetricsFanOutConnector(exporters) } -func (pb *PipelinesBuilder) buildFanoutExportersLogConsumer(exporterNames []string) consumer.LogsConsumer { +func (pb *pipelinesBuilder) buildFanoutExportersLogConsumer(exporterNames []string) consumer.LogsConsumer { builtExporters := pb.getBuiltExportersByNames(exporterNames) exporters := make([]consumer.LogsConsumer, len(builtExporters)) diff --git a/service/builder/pipelines_builder_test.go b/service/builder/pipelines_builder_test.go index 3c043f0ea6a..a7c9138acc7 100644 --- a/service/builder/pipelines_builder_test.go +++ b/service/builder/pipelines_builder_test.go @@ -133,7 +133,7 @@ func TestPipelinesBuilder_BuildVarious(t *testing.T) { cfg := createExampleConfig(dataType) // BuildProcessors the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) if test.shouldFail { assert.Error(t, err) return @@ -141,7 +141,7 @@ func TestPipelinesBuilder_BuildVarious(t *testing.T) { require.NoError(t, err) require.EqualValues(t, 1, len(allExporters)) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) require.NotNil(t, pipelineProcessors) @@ -205,9 +205,9 @@ func testPipeline(t *testing.T, pipelineName string, exporterNames []string) { require.Nil(t, err) // BuildProcessors the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) require.NotNil(t, pipelineProcessors) @@ -266,7 +266,7 @@ func TestProcessorsBuilder_ErrorOnUnsupportedProcessor(t *testing.T) { cfg, err := configtest.LoadConfigFile(t, "testdata/bad_processor_factory.yaml", factories) require.Nil(t, err) - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) // First test only trace receivers by removing the metrics pipeline. @@ -276,7 +276,7 @@ func TestProcessorsBuilder_ErrorOnUnsupportedProcessor(t *testing.T) { delete(cfg.Service.Pipelines, "logs") require.Equal(t, 1, len(cfg.Service.Pipelines)) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.Error(t, err) assert.Zero(t, len(pipelineProcessors)) @@ -285,7 +285,7 @@ func TestProcessorsBuilder_ErrorOnUnsupportedProcessor(t *testing.T) { cfg.Service.Pipelines["metrics"] = metricsPipeline require.Equal(t, 1, len(cfg.Service.Pipelines)) - pipelineProcessors, err = NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err = BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.Error(t, err) assert.Zero(t, len(pipelineProcessors)) @@ -294,7 +294,7 @@ func TestProcessorsBuilder_ErrorOnUnsupportedProcessor(t *testing.T) { cfg.Service.Pipelines["logs"] = logsPipeline require.Equal(t, 1, len(cfg.Service.Pipelines)) - pipelineProcessors, err = NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err = BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.Error(t, err) assert.Zero(t, len(pipelineProcessors)) } diff --git a/service/builder/receivers_builder.go b/service/builder/receivers_builder.go index 3989b0b815e..0463fdb0c4e 100644 --- a/service/builder/receivers_builder.go +++ b/service/builder/receivers_builder.go @@ -77,8 +77,8 @@ func (rcvs Receivers) StartAll(ctx context.Context, host component.Host) error { return nil } -// ReceiversBuilder builds receivers from config. -type ReceiversBuilder struct { +// receiversBuilder builds receivers from config. +type receiversBuilder struct { logger *zap.Logger appInfo component.ApplicationStartInfo config *configmodels.Config @@ -86,22 +86,17 @@ type ReceiversBuilder struct { factories map[configmodels.Type]component.ReceiverFactory } -// NewReceiversBuilder creates a new ReceiversBuilder. Call BuildProcessors() on the returned value. -func NewReceiversBuilder( +// BuildReceivers builds Receivers from config. +func BuildReceivers( logger *zap.Logger, appInfo component.ApplicationStartInfo, config *configmodels.Config, builtPipelines BuiltPipelines, factories map[configmodels.Type]component.ReceiverFactory, -) *ReceiversBuilder { - return &ReceiversBuilder{logger.With(zap.String(kindLogKey, kindLogsReceiver)), appInfo, config, builtPipelines, factories} -} +) (Receivers, error) { + rb := &receiversBuilder{logger.With(zap.String(kindLogKey, kindLogsReceiver)), appInfo, config, builtPipelines, factories} -// BuildProcessors receivers from config. -func (rb *ReceiversBuilder) Build() (Receivers, error) { receivers := make(Receivers) - - // BuildProcessors receivers based on configuration. for _, cfg := range rb.config.Receivers { logger := rb.logger.With(zap.String(typeLogKey, string(cfg.Type())), zap.String(nameLogKey, cfg.Name())) rcv, err := rb.buildReceiver(context.Background(), logger, rb.appInfo, cfg) @@ -130,7 +125,7 @@ func hasReceiver(pipeline *configmodels.Pipeline, receiverName string) bool { type attachedPipelines map[configmodels.DataType][]*builtPipeline -func (rb *ReceiversBuilder) findPipelinesToAttach(config configmodels.Receiver) (attachedPipelines, error) { +func (rb *receiversBuilder) findPipelinesToAttach(config configmodels.Receiver) (attachedPipelines, error) { // A receiver may be attached to multiple pipelines. Pipelines may consume different // data types. We need to compile the list of pipelines of each type that must be // attached to this receiver according to configuration. @@ -163,7 +158,7 @@ func (rb *ReceiversBuilder) findPipelinesToAttach(config configmodels.Receiver) return pipelinesToAttach, nil } -func (rb *ReceiversBuilder) attachReceiverToPipelines( +func (rb *receiversBuilder) attachReceiverToPipelines( ctx context.Context, logger *zap.Logger, appInfo component.ApplicationStartInfo, @@ -237,7 +232,7 @@ func (rb *ReceiversBuilder) attachReceiverToPipelines( return nil } -func (rb *ReceiversBuilder) buildReceiver(ctx context.Context, logger *zap.Logger, appInfo component.ApplicationStartInfo, config configmodels.Receiver) (*builtReceiver, error) { +func (rb *receiversBuilder) buildReceiver(ctx context.Context, logger *zap.Logger, appInfo component.ApplicationStartInfo, config configmodels.Receiver) (*builtReceiver, error) { // First find pipelines that must be attached to this receiver. pipelinesToAttach, err := rb.findPipelinesToAttach(config) diff --git a/service/builder/receivers_builder_test.go b/service/builder/receivers_builder_test.go index 602a74ddbc9..57b59599002 100644 --- a/service/builder/receivers_builder_test.go +++ b/service/builder/receivers_builder_test.go @@ -99,11 +99,11 @@ func testReceivers( require.Nil(t, err) // Build the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) - receivers, err := NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err := BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) assert.NoError(t, err) require.NotNil(t, receivers) @@ -199,16 +199,16 @@ func TestReceiversBuilder_BuildCustom(t *testing.T) { cfg := createExampleConfig(dataType) // Build the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) if test.shouldFail { assert.Error(t, err) return } assert.NoError(t, err) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) - receivers, err := NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err := BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) assert.NoError(t, err) require.NotNil(t, receivers) @@ -271,11 +271,11 @@ func TestReceiversBuilder_DataTypeError(t *testing.T) { receiver.(*componenttest.ExampleReceiver).FailTraceCreation = true // Build the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) - receivers, err := NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err := BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) // This should fail because "examplereceiver" is attached to "traces" pipeline // which is a configuration error. @@ -331,9 +331,9 @@ func TestReceiversBuilder_ErrorOnNilReceiver(t *testing.T) { require.Nil(t, err) // Build the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) // First test only trace receivers by removing the metrics pipeline. @@ -343,7 +343,7 @@ func TestReceiversBuilder_ErrorOnNilReceiver(t *testing.T) { delete(cfg.Service.Pipelines, "logs") require.Equal(t, 1, len(cfg.Service.Pipelines)) - receivers, err := NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err := BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) assert.Error(t, err) assert.Zero(t, len(receivers)) @@ -352,7 +352,7 @@ func TestReceiversBuilder_ErrorOnNilReceiver(t *testing.T) { cfg.Service.Pipelines["metrics"] = metricsPipeline require.Equal(t, 1, len(cfg.Service.Pipelines)) - receivers, err = NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err = BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) assert.Error(t, err) assert.Zero(t, len(receivers)) @@ -361,7 +361,7 @@ func TestReceiversBuilder_ErrorOnNilReceiver(t *testing.T) { cfg.Service.Pipelines["logs"] = logsPipeline require.Equal(t, 1, len(cfg.Service.Pipelines)) - receivers, err = NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err = BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) assert.Error(t, err) assert.Zero(t, len(receivers)) } @@ -374,11 +374,11 @@ func TestReceiversBuilder_Unused(t *testing.T) { assert.NoError(t, err) // Build the pipeline - allExporters, err := NewExportersBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters).Build() + allExporters, err := BuildExporters(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, factories.Exporters) assert.NoError(t, err) - pipelineProcessors, err := NewPipelinesBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors).Build() + pipelineProcessors, err := BuildPipelines(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, allExporters, factories.Processors) assert.NoError(t, err) - receivers, err := NewReceiversBuilder(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers).Build() + receivers, err := BuildReceivers(zap.NewNop(), component.DefaultApplicationStartInfo(), cfg, pipelineProcessors, factories.Receivers) assert.NoError(t, err) assert.NotNil(t, receivers) diff --git a/service/service.go b/service/service.go index 06320f54b1f..196116c51fc 100644 --- a/service/service.go +++ b/service/service.go @@ -317,7 +317,7 @@ func (app *Application) setupConfigurationComponents(ctx context.Context, factor func (app *Application) setupExtensions(ctx context.Context) error { var err error - app.builtExtensions, err = builder.NewExtensionsBuilder(app.logger, app.info, app.config, app.factories.Extensions).Build() + app.builtExtensions, err = builder.BuildExtensions(app.logger, app.info, app.config, app.factories.Extensions) if err != nil { return fmt.Errorf("cannot build builtExtensions: %w", err) } @@ -331,7 +331,7 @@ func (app *Application) setupPipelines(ctx context.Context) error { // First create exporters. var err error - app.builtExporters, err = builder.NewExportersBuilder(app.logger, app.info, app.config, app.factories.Exporters).Build() + app.builtExporters, err = builder.BuildExporters(app.logger, app.info, app.config, app.factories.Exporters) if err != nil { return fmt.Errorf("cannot build builtExporters: %w", err) } @@ -344,7 +344,7 @@ func (app *Application) setupPipelines(ctx context.Context) error { // Create pipelines and their processors and plug exporters to the // end of the pipelines. - app.builtPipelines, err = builder.NewPipelinesBuilder(app.logger, app.info, app.config, app.builtExporters, app.factories.Processors).Build() + app.builtPipelines, err = builder.BuildPipelines(app.logger, app.info, app.config, app.builtExporters, app.factories.Processors) if err != nil { return fmt.Errorf("cannot build pipelines: %w", err) } @@ -356,7 +356,7 @@ func (app *Application) setupPipelines(ctx context.Context) error { } // Create receivers and plug them into the start of the pipelines. - app.builtReceivers, err = builder.NewReceiversBuilder(app.logger, app.info, app.config, app.builtPipelines, app.factories.Receivers).Build() + app.builtReceivers, err = builder.BuildReceivers(app.logger, app.info, app.config, app.builtPipelines, app.factories.Receivers) if err != nil { return fmt.Errorf("cannot build receivers: %w", err) }