forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move processor builders into internal service (open-telemetry#10782)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This moves the processor builder out of the `processor` package, and into `service/internal/builders`. There's no real reason for this struct to be public (folks shouldn't call it), and making it private will allow us to add profiling support to it. <!-- Issue number if applicable --> #### Link to tracking issue open-telemetry#10375 (review)
- Loading branch information
Showing
16 changed files
with
394 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: deprecation | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
component: processor | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Deprecate processor.Builder, and move it into an internal package of the service module | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [10782] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [api] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package builders // import "go.opentelemetry.io/collector/service/internal/builders" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/processor" | ||
"go.opentelemetry.io/collector/processor/processortest" | ||
) | ||
|
||
// Processor is an interface that allows using implementations of the builder | ||
// from different packages. | ||
type Processor interface { | ||
CreateTraces(context.Context, processor.Settings, consumer.Traces) (processor.Traces, error) | ||
CreateMetrics(context.Context, processor.Settings, consumer.Metrics) (processor.Metrics, error) | ||
CreateLogs(context.Context, processor.Settings, consumer.Logs) (processor.Logs, error) | ||
Factory(component.Type) component.Factory | ||
} | ||
|
||
// ProcessorBuilder processor is a helper struct that given a set of Configs | ||
// and Factories helps with creating processors. | ||
type ProcessorBuilder struct { | ||
cfgs map[component.ID]component.Config | ||
factories map[component.Type]processor.Factory | ||
} | ||
|
||
// NewProcessor creates a new ProcessorBuilder to help with creating components form a set of configs and factories. | ||
func NewProcessor(cfgs map[component.ID]component.Config, factories map[component.Type]processor.Factory) *ProcessorBuilder { | ||
return &ProcessorBuilder{cfgs: cfgs, factories: factories} | ||
} | ||
|
||
// CreateTraces creates a Traces processor based on the settings and config. | ||
func (b *ProcessorBuilder) CreateTraces(ctx context.Context, set processor.Settings, next consumer.Traces) (processor.Traces, error) { | ||
if next == nil { | ||
return nil, errNilNextConsumer | ||
} | ||
cfg, existsCfg := b.cfgs[set.ID] | ||
if !existsCfg { | ||
return nil, fmt.Errorf("processor %q is not configured", set.ID) | ||
} | ||
|
||
f, existsFactory := b.factories[set.ID.Type()] | ||
if !existsFactory { | ||
return nil, fmt.Errorf("processor factory not available for: %q", set.ID) | ||
} | ||
|
||
logStabilityLevel(set.Logger, f.TracesProcessorStability()) | ||
return f.CreateTracesProcessor(ctx, set, cfg, next) | ||
} | ||
|
||
// CreateMetrics creates a Metrics processor based on the settings and config. | ||
func (b *ProcessorBuilder) CreateMetrics(ctx context.Context, set processor.Settings, next consumer.Metrics) (processor.Metrics, error) { | ||
if next == nil { | ||
return nil, errNilNextConsumer | ||
} | ||
cfg, existsCfg := b.cfgs[set.ID] | ||
if !existsCfg { | ||
return nil, fmt.Errorf("processor %q is not configured", set.ID) | ||
} | ||
|
||
f, existsFactory := b.factories[set.ID.Type()] | ||
if !existsFactory { | ||
return nil, fmt.Errorf("processor factory not available for: %q", set.ID) | ||
} | ||
|
||
logStabilityLevel(set.Logger, f.MetricsProcessorStability()) | ||
return f.CreateMetricsProcessor(ctx, set, cfg, next) | ||
} | ||
|
||
// CreateLogs creates a Logs processor based on the settings and config. | ||
func (b *ProcessorBuilder) CreateLogs(ctx context.Context, set processor.Settings, next consumer.Logs) (processor.Logs, error) { | ||
if next == nil { | ||
return nil, errNilNextConsumer | ||
} | ||
cfg, existsCfg := b.cfgs[set.ID] | ||
if !existsCfg { | ||
return nil, fmt.Errorf("processor %q is not configured", set.ID) | ||
} | ||
|
||
f, existsFactory := b.factories[set.ID.Type()] | ||
if !existsFactory { | ||
return nil, fmt.Errorf("processor factory not available for: %q", set.ID) | ||
} | ||
|
||
logStabilityLevel(set.Logger, f.LogsProcessorStability()) | ||
return f.CreateLogsProcessor(ctx, set, cfg, next) | ||
} | ||
|
||
func (b *ProcessorBuilder) Factory(componentType component.Type) component.Factory { | ||
return b.factories[componentType] | ||
} | ||
|
||
// NewNopProcessorConfigsAndFactories returns a configuration and factories that allows building a new nop processor. | ||
func NewNopProcessorConfigsAndFactories() (map[component.ID]component.Config, map[component.Type]processor.Factory) { | ||
nopFactory := processortest.NewNopFactory() | ||
configs := map[component.ID]component.Config{ | ||
component.NewID(nopType): nopFactory.CreateDefaultConfig(), | ||
} | ||
factories := map[component.Type]processor.Factory{ | ||
nopType: nopFactory, | ||
} | ||
|
||
return configs, factories | ||
} |
Oops, something went wrong.