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

Build receivers based on new configuration #25

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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ALL_SRC := $(shell find . -name '*.go' \
# ALL_PKGS is used with 'go cover'
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))

GOTEST_OPT?=-v -race -timeout 30s
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
tigrannajaryan marked this conversation as resolved.
Show resolved Hide resolved
GOTEST_OPT?= -race -timeout 30s
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
GOTEST=go test
GOFMT=gofmt
Expand Down
14 changes: 7 additions & 7 deletions cmd/occollector/app/builder/exporters_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (eb *ExportersBuilder) buildExporter(
// Could not create because this exporter does not support this data type.
return nil, typeMismatchErr(config, requirement.requiredBy, configmodels.TracesDataType)
}
return nil, fmt.Errorf("error creating %q exporter: %v", config.Name(), err)
return nil, fmt.Errorf("error creating %s exporter: %v", config.Name(), err)
}

exporter.tc = tc
Expand All @@ -189,13 +189,15 @@ func (eb *ExportersBuilder) buildExporter(
// Could not create because this exporter does not support this data type.
return nil, typeMismatchErr(config, requirement.requiredBy, configmodels.MetricsDataType)
}
return nil, fmt.Errorf("error creating %q exporter: %v", config.Name(), err)
return nil, fmt.Errorf("error creating %s exporter: %v", config.Name(), err)
}

exporter.mc = mc
exporter.stop = combineStopFunc(exporter.stop, stopFunc)
}

eb.logger.Info("Exporter is enabled.", zap.String("exporter", config.Name()))

return exporter, nil
}

Expand All @@ -204,10 +206,8 @@ func typeMismatchErr(
requiredByPipeline *configmodels.Pipeline,
dataType configmodels.DataType,
) error {
return fmt.Errorf(
"pipeline %q produces %q to exporter %s which does not support %q "+
"telemetry data. exporter will be detached from pipeline",
requiredByPipeline.Name, dataType.GetDataTypeStr(),
config.Name(), dataType.GetDataTypeStr(),
return fmt.Errorf("%s is a %s pipeline but has a %s which does not support %s",
requiredByPipeline.Name, dataType.GetString(),
config.Name(), dataType.GetString(),
)
}
28 changes: 15 additions & 13 deletions cmd/occollector/app/builder/pipelines_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func NewPipelinesBuilder(
}

// Build pipeline processors from config.
func (eb *PipelinesBuilder) Build() (PipelineProcessors, error) {
func (pb *PipelinesBuilder) Build() (PipelineProcessors, error) {
pipelineProcessors := make(PipelineProcessors)

for _, pipeline := range eb.config.Pipelines {
firstProcessor, err := eb.buildPipeline(pipeline)
for _, pipeline := range pb.config.Pipelines {
firstProcessor, err := pb.buildPipeline(pipeline)
if err != nil {
return nil, err
}
Expand All @@ -71,7 +71,7 @@ func (eb *PipelinesBuilder) Build() (PipelineProcessors, 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 (eb *PipelinesBuilder) buildPipeline(
func (pb *PipelinesBuilder) buildPipeline(
pipelineCfg *configmodels.Pipeline,
) (*builtProcessor, error) {

Expand All @@ -83,9 +83,9 @@ func (eb *PipelinesBuilder) buildPipeline(

switch pipelineCfg.InputType {
case configmodels.TracesDataType:
tc = eb.buildFanoutExportersTraceConsumer(pipelineCfg.Exporters)
tc = pb.buildFanoutExportersTraceConsumer(pipelineCfg.Exporters)
case configmodels.MetricsDataType:
mc = eb.buildFanoutExportersMetricsConsumer(pipelineCfg.Exporters)
mc = pb.buildFanoutExportersMetricsConsumer(pipelineCfg.Exporters)
}

// Now build the processors backwards, starting from the last one.
Expand All @@ -94,7 +94,7 @@ func (eb *PipelinesBuilder) buildPipeline(
// in the pipeline and so on.
for i := len(pipelineCfg.Processors) - 1; i >= 0; i-- {
procName := pipelineCfg.Processors[i]
procCfg := eb.config.Processors[procName]
procCfg := pb.config.Processors[procName]

factory := factories.GetProcessorFactory(procCfg.Type())

Expand All @@ -115,22 +115,24 @@ func (eb *PipelinesBuilder) buildPipeline(
}
}

pb.logger.Info("Pipeline is enabled.", zap.String("pipelines", pipelineCfg.Name))

return &builtProcessor{tc, mc}, nil
}

// Converts the list of exporter names to a list of corresponding builtExporters.
func (eb *PipelinesBuilder) getBuiltExportersByNames(exporterNames []string) []*builtExporter {
func (pb *PipelinesBuilder) getBuiltExportersByNames(exporterNames []string) []*builtExporter {
var result []*builtExporter
for _, name := range exporterNames {
exporter := eb.exporters[eb.config.Exporters[name]]
exporter := pb.exporters[pb.config.Exporters[name]]
result = append(result, exporter)
}

return result
}

func (eb *PipelinesBuilder) buildFanoutExportersTraceConsumer(exporterNames []string) consumer.TraceConsumer {
builtExporters := eb.getBuiltExportersByNames(exporterNames)
func (pb *PipelinesBuilder) buildFanoutExportersTraceConsumer(exporterNames []string) consumer.TraceConsumer {
builtExporters := pb.getBuiltExportersByNames(exporterNames)

// Optimize for the case when there is only one exporter, no need to create junction point.
if len(builtExporters) == 1 {
Expand All @@ -146,8 +148,8 @@ func (eb *PipelinesBuilder) buildFanoutExportersTraceConsumer(exporterNames []st
return multiconsumer.NewTraceProcessor(exporters)
}

func (eb *PipelinesBuilder) buildFanoutExportersMetricsConsumer(exporterNames []string) consumer.MetricsConsumer {
builtExporters := eb.getBuiltExportersByNames(exporterNames)
func (pb *PipelinesBuilder) buildFanoutExportersMetricsConsumer(exporterNames []string) consumer.MetricsConsumer {
builtExporters := pb.getBuiltExportersByNames(exporterNames)

// Optimize for the case when there is only one exporter, no need to create junction point.
if len(builtExporters) == 1 {
Expand Down
Loading