Deprecate all types and funcs in config package
The main reason is to remove the circular dependency between the config (including sub-packages) and component. Here is the current state: * component depends on config * config/sub-package[grpc, http, etc.] depends on config & component Because of this "circular" dependency, we cannot split for example "config" into its own module, only if all the other config sub-packages are also split. Signed-off-by: Bogdan <bogdandrutu@gmail.com>
This commit is contained in:
parent
6b27644724
commit
d6ed8246b6
|
@ -0,0 +1,31 @@
|
|||
# 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: config
|
||||
|
||||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
|
||||
note: Deprecate all types and funcs in `config` package
|
||||
|
||||
# One or more tracking issues or pull requests related to the change
|
||||
issues: [6422]
|
||||
|
||||
# (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: |
|
||||
- config.ComponentID => component.ID
|
||||
- config.Type => component.Type
|
||||
- config.DataType => component.DataType
|
||||
- config.Receiver => component.ReceiverConfig
|
||||
- config.UnmarshalReceiver => component.UnmarshalReceiverConfig
|
||||
- config.[New]ReceiverSettings => component.[New]ReceiverConfigSettings
|
||||
- config.Processor => component.ProcessorConfig
|
||||
- config.UnmarshalProcessor => component.UnmarshalProcessorConfig
|
||||
- config.[New]ProcessorSettings => component.[New]ProcessorConfigSettings
|
||||
- config.Exporter => component.ExporterConfig
|
||||
- config.UnmarshalExporter => component.UnmarshalExporterConfig
|
||||
- config.[New]ExporterSettings => component.[New]ExporterConfigSettings
|
||||
- config.Extension => component.ExtensionConfig
|
||||
- config.UnmarshalExtension => component.UnmarshalExtensionConfig
|
||||
- config.[New]ExtensionSettings => component.[New]ExtensionConfigSettings
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
)
|
||||
|
||||
func TestValidateConfigs(t *testing.T) {
|
||||
|
@ -15,15 +15,15 @@ func TestValidateConfigs(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
for _, factory := range factories.Receivers {
|
||||
assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
}
|
||||
for _, factory := range factories.Processors {
|
||||
assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
}
|
||||
for _, factory := range factories.Exporters {
|
||||
assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
}
|
||||
for _, factory := range factories.Extensions {
|
||||
assert.NoError(t, configtest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(factory.CreateDefaultConfig()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -162,17 +160,17 @@ func (sl StabilityLevel) LogMessage() string {
|
|||
// use the factory helpers for the appropriate component type.
|
||||
type Factory interface {
|
||||
// Type gets the type of the component created by this factory.
|
||||
Type() config.Type
|
||||
Type() Type
|
||||
|
||||
unexportedFactoryFunc()
|
||||
}
|
||||
|
||||
type baseFactory struct {
|
||||
cfgType config.Type
|
||||
cfgType Type
|
||||
}
|
||||
|
||||
func (baseFactory) unexportedFactoryFunc() {}
|
||||
|
||||
func (bf baseFactory) Type() config.Type {
|
||||
func (bf baseFactory) Type() Type {
|
||||
return bf.cfgType
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package componenttest // import "go.opentelemetry.io/collector/component/componenttest"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
// The regular expression for valid config field tag.
|
||||
var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$")
|
||||
|
||||
// CheckConfigStruct enforces that given configuration object is following the patterns
|
||||
// used by the collector. This ensures consistency between different implementations
|
||||
// of components and extensions. It is recommended for implementers of components
|
||||
// to call this function on their tests passing the default configuration of the
|
||||
// component factory.
|
||||
func CheckConfigStruct(config interface{}) error {
|
||||
t := reflect.TypeOf(config)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
if t.Kind() != reflect.Struct {
|
||||
return fmt.Errorf("config must be a struct or a pointer to one, the passed object is a %s", t.Kind())
|
||||
}
|
||||
|
||||
return validateConfigDataType(t)
|
||||
}
|
||||
|
||||
// validateConfigDataType performs a descending validation of the given type.
|
||||
// If the type is a struct it goes to each of its fields to check for the proper
|
||||
// tags.
|
||||
func validateConfigDataType(t reflect.Type) error {
|
||||
var errs error
|
||||
|
||||
switch t.Kind() {
|
||||
case reflect.Ptr:
|
||||
errs = multierr.Append(errs, validateConfigDataType(t.Elem()))
|
||||
case reflect.Struct:
|
||||
// Reflect on the pointed data and check each of its fields.
|
||||
nf := t.NumField()
|
||||
for i := 0; i < nf; i++ {
|
||||
f := t.Field(i)
|
||||
errs = multierr.Append(errs, checkStructFieldTags(f))
|
||||
}
|
||||
default:
|
||||
// The config object can carry other types but they are not used when
|
||||
// reading the configuration via koanf so ignore them. Basically ignore:
|
||||
// reflect.Uintptr, reflect.Chan, reflect.Func, reflect.Interface, and
|
||||
// reflect.UnsafePointer.
|
||||
}
|
||||
|
||||
if errs != nil {
|
||||
return fmt.Errorf("type %q from package %q has invalid config settings: %w", t.Name(), t.PkgPath(), errs)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkStructFieldTags inspects the tags of a struct field.
|
||||
func checkStructFieldTags(f reflect.StructField) error {
|
||||
|
||||
tagValue := f.Tag.Get("mapstructure")
|
||||
if tagValue == "" {
|
||||
|
||||
// Ignore special types.
|
||||
switch f.Type.Kind() {
|
||||
case reflect.Interface, reflect.Chan, reflect.Func, reflect.Uintptr, reflect.UnsafePointer:
|
||||
// Allow the config to carry the types above, but since they are not read
|
||||
// when loading configuration, just ignore them.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Public fields of other types should be tagged.
|
||||
chars := []byte(f.Name)
|
||||
if len(chars) > 0 && chars[0] >= 'A' && chars[0] <= 'Z' {
|
||||
return fmt.Errorf("mapstructure tag not present on field %q", f.Name)
|
||||
}
|
||||
|
||||
// Not public field, no need to have a tag.
|
||||
return nil
|
||||
}
|
||||
|
||||
tagParts := strings.Split(tagValue, ",")
|
||||
if tagParts[0] != "" {
|
||||
if tagParts[0] == "-" {
|
||||
// Nothing to do, as mapstructure decode skips this field.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check if squash is specified.
|
||||
squash := false
|
||||
for _, tag := range tagParts[1:] {
|
||||
if tag == "squash" {
|
||||
squash = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if squash {
|
||||
// Field was squashed.
|
||||
if (f.Type.Kind() != reflect.Struct) && (f.Type.Kind() != reflect.Ptr || f.Type.Elem().Kind() != reflect.Struct) {
|
||||
return fmt.Errorf(
|
||||
"attempt to squash non-struct type on field %q", f.Name)
|
||||
}
|
||||
}
|
||||
|
||||
switch f.Type.Kind() {
|
||||
case reflect.Struct:
|
||||
// It is another struct, continue down-level.
|
||||
return validateConfigDataType(f.Type)
|
||||
|
||||
case reflect.Map, reflect.Slice, reflect.Array:
|
||||
// The element of map, array, or slice can be itself a configuration object.
|
||||
return validateConfigDataType(f.Type.Elem())
|
||||
|
||||
default:
|
||||
fieldTag := tagParts[0]
|
||||
if !configFieldTagRegExp.MatchString(fieldTag) {
|
||||
return fmt.Errorf(
|
||||
"field %q has config tag %q which doesn't satisfy %q",
|
||||
f.Name,
|
||||
fieldTag,
|
||||
configFieldTagRegExp.String())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package configtest
|
||||
package componenttest
|
||||
|
||||
import (
|
||||
"io"
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
)
|
||||
|
||||
|
@ -31,16 +30,16 @@ func NewNopExporterCreateSettings() component.ExporterCreateSettings {
|
|||
}
|
||||
|
||||
type nopExporterConfig struct {
|
||||
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
}
|
||||
|
||||
// NewNopExporterFactory returns a component.ExporterFactory that constructs nop exporters.
|
||||
func NewNopExporterFactory() component.ExporterFactory {
|
||||
return component.NewExporterFactory(
|
||||
"nop",
|
||||
func() config.Exporter {
|
||||
func() component.ExporterConfig {
|
||||
return &nopExporterConfig{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop")),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop")),
|
||||
}
|
||||
},
|
||||
component.WithTracesExporter(createTracesExporter, component.StabilityLevelStable),
|
||||
|
@ -49,15 +48,15 @@ func NewNopExporterFactory() component.ExporterFactory {
|
|||
)
|
||||
}
|
||||
|
||||
func createTracesExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.TracesExporter, error) {
|
||||
func createTracesExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.TracesExporter, error) {
|
||||
return nopExporterInstance, nil
|
||||
}
|
||||
|
||||
func createMetricsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.MetricsExporter, error) {
|
||||
func createMetricsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.MetricsExporter, error) {
|
||||
return nopExporterInstance, nil
|
||||
}
|
||||
|
||||
func createLogsExporter(context.Context, component.ExporterCreateSettings, config.Exporter) (component.LogsExporter, error) {
|
||||
func createLogsExporter(context.Context, component.ExporterCreateSettings, component.ExporterConfig) (component.LogsExporter, error) {
|
||||
return nopExporterInstance, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/pdata/plog"
|
||||
"go.opentelemetry.io/collector/pdata/pmetric"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
|
@ -30,9 +30,9 @@ import (
|
|||
func TestNewNopExporterFactory(t *testing.T) {
|
||||
factory := NewNopExporterFactory()
|
||||
require.NotNil(t, factory)
|
||||
assert.Equal(t, config.Type("nop"), factory.Type())
|
||||
assert.Equal(t, component.Type("nop"), factory.Type())
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.Equal(t, &nopExporterConfig{ExporterSettings: config.NewExporterSettings(config.NewComponentID("nop"))}, cfg)
|
||||
assert.Equal(t, &nopExporterConfig{ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID("nop"))}, cfg)
|
||||
|
||||
traces, err := factory.CreateTracesExporter(context.Background(), NewNopExporterCreateSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
// NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions.
|
||||
|
@ -30,19 +29,19 @@ func NewNopExtensionCreateSettings() component.ExtensionCreateSettings {
|
|||
}
|
||||
|
||||
type nopExtensionConfig struct {
|
||||
config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
}
|
||||
|
||||
// NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions.
|
||||
func NewNopExtensionFactory() component.ExtensionFactory {
|
||||
return component.NewExtensionFactory(
|
||||
"nop",
|
||||
func() config.Extension {
|
||||
func() component.ExtensionConfig {
|
||||
return &nopExtensionConfig{
|
||||
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop")),
|
||||
ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop")),
|
||||
}
|
||||
},
|
||||
func(context.Context, component.ExtensionCreateSettings, config.Extension) (component.Extension, error) {
|
||||
func(context.Context, component.ExtensionCreateSettings, component.ExtensionConfig) (component.Extension, error) {
|
||||
return nopExtensionInstance, nil
|
||||
},
|
||||
component.StabilityLevelStable)
|
||||
|
|
|
@ -21,15 +21,15 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
func TestNewNopExtensionFactory(t *testing.T) {
|
||||
factory := NewNopExtensionFactory()
|
||||
require.NotNil(t, factory)
|
||||
assert.Equal(t, config.Type("nop"), factory.Type())
|
||||
assert.Equal(t, component.Type("nop"), factory.Type())
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.Equal(t, &nopExtensionConfig{ExtensionSettings: config.NewExtensionSettings(config.NewComponentID("nop"))}, cfg)
|
||||
assert.Equal(t, &nopExtensionConfig{ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID("nop"))}, cfg)
|
||||
|
||||
traces, err := factory.CreateExtension(context.Background(), NewNopExtensionCreateSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -16,7 +16,6 @@ package componenttest // import "go.opentelemetry.io/collector/component/compone
|
|||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
// nopHost mocks a receiver.ReceiverHost for test purposes.
|
||||
|
@ -29,14 +28,14 @@ func NewNopHost() component.Host {
|
|||
|
||||
func (nh *nopHost) ReportFatalError(_ error) {}
|
||||
|
||||
func (nh *nopHost) GetFactory(_ component.Kind, _ config.Type) component.Factory {
|
||||
func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nh *nopHost) GetExtensions() map[config.ComponentID]component.Extension {
|
||||
func (nh *nopHost) GetExtensions() map[component.ID]component.Extension {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nh *nopHost) GetExporters() map[config.DataType]map[config.ComponentID]component.Exporter {
|
||||
func (nh *nopHost) GetExporters() map[component.DataType]map[component.ID]component.Exporter {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
)
|
||||
|
@ -32,16 +31,16 @@ func NewNopProcessorCreateSettings() component.ProcessorCreateSettings {
|
|||
}
|
||||
|
||||
type nopProcessorConfig struct {
|
||||
config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
}
|
||||
|
||||
// NewNopProcessorFactory returns a component.ProcessorFactory that constructs nop processors.
|
||||
func NewNopProcessorFactory() component.ProcessorFactory {
|
||||
return component.NewProcessorFactory(
|
||||
"nop",
|
||||
func() config.Processor {
|
||||
func() component.ProcessorConfig {
|
||||
return &nopProcessorConfig{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop")),
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop")),
|
||||
}
|
||||
},
|
||||
component.WithTracesProcessor(createTracesProcessor, component.StabilityLevelStable),
|
||||
|
@ -50,15 +49,15 @@ func NewNopProcessorFactory() component.ProcessorFactory {
|
|||
)
|
||||
}
|
||||
|
||||
func createTracesProcessor(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Traces) (component.TracesProcessor, error) {
|
||||
func createTracesProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Traces) (component.TracesProcessor, error) {
|
||||
return nopProcessorInstance, nil
|
||||
}
|
||||
|
||||
func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Metrics) (component.MetricsProcessor, error) {
|
||||
func createMetricsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Metrics) (component.MetricsProcessor, error) {
|
||||
return nopProcessorInstance, nil
|
||||
}
|
||||
|
||||
func createLogsProcessor(context.Context, component.ProcessorCreateSettings, config.Processor, consumer.Logs) (component.LogsProcessor, error) {
|
||||
func createLogsProcessor(context.Context, component.ProcessorCreateSettings, component.ProcessorConfig, consumer.Logs) (component.LogsProcessor, error) {
|
||||
return nopProcessorInstance, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
"go.opentelemetry.io/collector/pdata/plog"
|
||||
|
@ -32,9 +32,9 @@ import (
|
|||
func TestNewNopProcessorFactory(t *testing.T) {
|
||||
factory := NewNopProcessorFactory()
|
||||
require.NotNil(t, factory)
|
||||
assert.Equal(t, config.Type("nop"), factory.Type())
|
||||
assert.Equal(t, component.Type("nop"), factory.Type())
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.Equal(t, &nopProcessorConfig{ProcessorSettings: config.NewProcessorSettings(config.NewComponentID("nop"))}, cfg)
|
||||
assert.Equal(t, &nopProcessorConfig{ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID("nop"))}, cfg)
|
||||
|
||||
traces, err := factory.CreateTracesProcessor(context.Background(), NewNopProcessorCreateSettings(), cfg, consumertest.NewNop())
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
|
@ -31,16 +30,16 @@ func NewNopReceiverCreateSettings() component.ReceiverCreateSettings {
|
|||
}
|
||||
|
||||
type nopReceiverConfig struct {
|
||||
config.ReceiverSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ReceiverConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
}
|
||||
|
||||
// NewNopReceiverFactory returns a component.ReceiverFactory that constructs nop receivers.
|
||||
func NewNopReceiverFactory() component.ReceiverFactory {
|
||||
return component.NewReceiverFactory(
|
||||
"nop",
|
||||
func() config.Receiver {
|
||||
func() component.ReceiverConfig {
|
||||
return &nopReceiverConfig{
|
||||
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop")),
|
||||
ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop")),
|
||||
}
|
||||
},
|
||||
component.WithTracesReceiver(createTracesReceiver, component.StabilityLevelStable),
|
||||
|
@ -48,15 +47,15 @@ func NewNopReceiverFactory() component.ReceiverFactory {
|
|||
component.WithLogsReceiver(createLogsReceiver, component.StabilityLevelStable))
|
||||
}
|
||||
|
||||
func createTracesReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Traces) (component.TracesReceiver, error) {
|
||||
func createTracesReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Traces) (component.TracesReceiver, error) {
|
||||
return nopReceiverInstance, nil
|
||||
}
|
||||
|
||||
func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Metrics) (component.MetricsReceiver, error) {
|
||||
func createMetricsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Metrics) (component.MetricsReceiver, error) {
|
||||
return nopReceiverInstance, nil
|
||||
}
|
||||
|
||||
func createLogsReceiver(context.Context, component.ReceiverCreateSettings, config.Receiver, consumer.Logs) (component.LogsReceiver, error) {
|
||||
func createLogsReceiver(context.Context, component.ReceiverCreateSettings, component.ReceiverConfig, consumer.Logs) (component.LogsReceiver, error) {
|
||||
return nopReceiverInstance, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,16 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
)
|
||||
|
||||
func TestNewNopReceiverFactory(t *testing.T) {
|
||||
factory := NewNopReceiverFactory()
|
||||
require.NotNil(t, factory)
|
||||
assert.Equal(t, config.Type("nop"), factory.Type())
|
||||
assert.Equal(t, component.Type("nop"), factory.Type())
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.Equal(t, &nopReceiverConfig{ReceiverSettings: config.NewReceiverSettings(config.NewComponentID("nop"))}, cfg)
|
||||
assert.Equal(t, &nopReceiverConfig{ReceiverConfigSettings: component.NewReceiverConfigSettings(component.NewID("nop"))}, cfg)
|
||||
|
||||
traces, err := factory.CreateTracesReceiver(context.Background(), NewNopReceiverCreateSettings(), cfg, consumertest.NewNop())
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -23,12 +23,11 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
"go.opentelemetry.io/collector/internal/testdata"
|
||||
)
|
||||
|
||||
func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg config.Processor) {
|
||||
func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.ProcessorConfig) {
|
||||
// Create a processor and output its produce to a sink.
|
||||
nextSink := new(consumertest.TracesSink)
|
||||
processor, err := factory.CreateTracesProcessor(
|
||||
|
@ -62,7 +61,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
|
|||
}
|
||||
|
||||
// VerifyProcessorShutdown verifies the processor doesn't produce telemetry data after shutdown.
|
||||
func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg config.Processor) {
|
||||
func VerifyProcessorShutdown(t *testing.T, factory component.ProcessorFactory, cfg component.ProcessorConfig) {
|
||||
verifyTracesProcessorDoesntProduceAfterShutdown(t, factory, cfg)
|
||||
// TODO: add metrics and logs verification.
|
||||
// TODO: add other shutdown verifications.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/confmap"
|
|
@ -20,7 +20,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
stableconfig "go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/experimental/config"
|
||||
"go.opentelemetry.io/collector/config/experimental/configsource"
|
||||
)
|
||||
|
@ -44,7 +43,7 @@ type ConfigSourceFactory interface {
|
|||
// configuration and should not cause side-effects that prevent the creation
|
||||
// of multiple instances of the Source.
|
||||
// The object returned by this method needs to pass the checks implemented by
|
||||
// 'configtest.CheckConfigStruct'. It is recommended to have such check in the
|
||||
// 'componenttest.CheckConfigStruct'. It is recommended to have such check in the
|
||||
// tests of any implementation of the ConfigSourceFactory interface.
|
||||
CreateDefaultConfig() config.Source
|
||||
|
||||
|
@ -57,4 +56,4 @@ type ConfigSourceFactory interface {
|
|||
}
|
||||
|
||||
// ConfigSourceFactories maps the type of a ConfigSource to the respective factory object.
|
||||
type ConfigSourceFactories map[stableconfig.Type]ConfigSourceFactory
|
||||
type ConfigSourceFactories map[component.Type]ConfigSourceFactory
|
||||
|
|
|
@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
|
|||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
|
@ -64,14 +63,14 @@ type ExporterFactory interface {
|
|||
// configuration and should not cause side-effects that prevent the creation
|
||||
// of multiple instances of the Exporter.
|
||||
// The object returned by this method needs to pass the checks implemented by
|
||||
// 'configtest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// tests of any implementation of the Factory interface.
|
||||
CreateDefaultConfig() config.Exporter
|
||||
CreateDefaultConfig() ExporterConfig
|
||||
|
||||
// CreateTracesExporter creates a TracesExporter based on this config.
|
||||
// If the exporter type does not support tracing or if the config is not valid,
|
||||
// an error will be returned instead.
|
||||
CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error)
|
||||
CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (TracesExporter, error)
|
||||
|
||||
// TracesExporterStability gets the stability level of the TracesExporter.
|
||||
TracesExporterStability() StabilityLevel
|
||||
|
@ -79,7 +78,7 @@ type ExporterFactory interface {
|
|||
// CreateMetricsExporter creates a MetricsExporter based on this config.
|
||||
// If the exporter type does not support metrics or if the config is not valid,
|
||||
// an error will be returned instead.
|
||||
CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (MetricsExporter, error)
|
||||
CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (MetricsExporter, error)
|
||||
|
||||
// MetricsExporterStability gets the stability level of the MetricsExporter.
|
||||
MetricsExporterStability() StabilityLevel
|
||||
|
@ -87,7 +86,7 @@ type ExporterFactory interface {
|
|||
// CreateLogsExporter creates a LogsExporter based on the config.
|
||||
// If the exporter type does not support logs or if the config is not valid,
|
||||
// an error will be returned instead.
|
||||
CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (LogsExporter, error)
|
||||
CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (LogsExporter, error)
|
||||
|
||||
// LogsExporterStability gets the stability level of the LogsExporter.
|
||||
LogsExporterStability() StabilityLevel
|
||||
|
@ -109,18 +108,18 @@ func (f exporterFactoryOptionFunc) applyExporterFactoryOption(o *exporterFactory
|
|||
}
|
||||
|
||||
// ExporterCreateDefaultConfigFunc is the equivalent of ExporterFactory.CreateDefaultConfig().
|
||||
type ExporterCreateDefaultConfigFunc func() config.Exporter
|
||||
type ExporterCreateDefaultConfigFunc func() ExporterConfig
|
||||
|
||||
// CreateDefaultConfig implements ExporterFactory.CreateDefaultConfig().
|
||||
func (f ExporterCreateDefaultConfigFunc) CreateDefaultConfig() config.Exporter {
|
||||
func (f ExporterCreateDefaultConfigFunc) CreateDefaultConfig() ExporterConfig {
|
||||
return f()
|
||||
}
|
||||
|
||||
// CreateTracesExporterFunc is the equivalent of ExporterFactory.CreateTracesExporter().
|
||||
type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, config.Exporter) (TracesExporter, error)
|
||||
type CreateTracesExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error)
|
||||
|
||||
// CreateTracesExporter implements ExporterFactory.CreateTracesExporter().
|
||||
func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (TracesExporter, error) {
|
||||
func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (TracesExporter, error) {
|
||||
if f == nil {
|
||||
return nil, ErrDataTypeIsNotSupported
|
||||
}
|
||||
|
@ -128,10 +127,10 @@ func (f CreateTracesExporterFunc) CreateTracesExporter(ctx context.Context, set
|
|||
}
|
||||
|
||||
// CreateMetricsExporterFunc is the equivalent of ExporterFactory.CreateMetricsExporter().
|
||||
type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, config.Exporter) (MetricsExporter, error)
|
||||
type CreateMetricsExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (MetricsExporter, error)
|
||||
|
||||
// CreateMetricsExporter implements ExporterFactory.CreateMetricsExporter().
|
||||
func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (MetricsExporter, error) {
|
||||
func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (MetricsExporter, error) {
|
||||
if f == nil {
|
||||
return nil, ErrDataTypeIsNotSupported
|
||||
}
|
||||
|
@ -139,10 +138,10 @@ func (f CreateMetricsExporterFunc) CreateMetricsExporter(ctx context.Context, se
|
|||
}
|
||||
|
||||
// CreateLogsExporterFunc is the equivalent of ExporterFactory.CreateLogsExporter().
|
||||
type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, config.Exporter) (LogsExporter, error)
|
||||
type CreateLogsExporterFunc func(context.Context, ExporterCreateSettings, ExporterConfig) (LogsExporter, error)
|
||||
|
||||
// CreateLogsExporter implements ExporterFactory.CreateLogsExporter().
|
||||
func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg config.Exporter) (LogsExporter, error) {
|
||||
func (f CreateLogsExporterFunc) CreateLogsExporter(ctx context.Context, set ExporterCreateSettings, cfg ExporterConfig) (LogsExporter, error) {
|
||||
if f == nil {
|
||||
return nil, ErrDataTypeIsNotSupported
|
||||
}
|
||||
|
@ -197,7 +196,7 @@ func WithLogsExporter(createLogsExporter CreateLogsExporterFunc, sl StabilityLev
|
|||
}
|
||||
|
||||
// NewExporterFactory returns a ExporterFactory.
|
||||
func NewExporterFactory(cfgType config.Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory {
|
||||
func NewExporterFactory(cfgType Type, createDefaultConfig ExporterCreateDefaultConfigFunc, options ...ExporterFactoryOption) ExporterFactory {
|
||||
f := &exporterFactory{
|
||||
baseFactory: baseFactory{cfgType: cfgType},
|
||||
ExporterCreateDefaultConfigFunc: createDefaultConfig,
|
||||
|
|
|
@ -12,57 +12,58 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
)
|
||||
|
||||
// Exporter is the configuration of a component.Exporter. Specific extensions must implement
|
||||
// ExporterConfig is the configuration of a component.Exporter. Specific extensions must implement
|
||||
// this interface and must embed ExporterSettings struct or a struct that extends it.
|
||||
type Exporter interface {
|
||||
type ExporterConfig interface {
|
||||
identifiable
|
||||
validatable
|
||||
|
||||
privateConfigExporter()
|
||||
}
|
||||
|
||||
// UnmarshalExporter helper function to unmarshal an Exporter config.
|
||||
// UnmarshalExporterConfig helper function to unmarshal an ExporterConfig.
|
||||
// It checks if the config implements confmap.Unmarshaler and uses that if available,
|
||||
// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent.
|
||||
func UnmarshalExporter(conf *confmap.Conf, cfg Exporter) error {
|
||||
func UnmarshalExporterConfig(conf *confmap.Conf, cfg ExporterConfig) error {
|
||||
return unmarshal(conf, cfg)
|
||||
}
|
||||
|
||||
// ExporterSettings defines common settings for a component.Exporter configuration.
|
||||
// ExporterConfigSettings defines common settings for a component.Exporter configuration.
|
||||
// Specific exporters can embed this struct and extend it with more fields if needed.
|
||||
//
|
||||
// It is highly recommended to "override" the Validate() function.
|
||||
//
|
||||
// When embedded in the exporter config, it must be with `mapstructure:",squash"` tag.
|
||||
type ExporterSettings struct {
|
||||
id ComponentID `mapstructure:"-"`
|
||||
type ExporterConfigSettings struct {
|
||||
id ID `mapstructure:"-"`
|
||||
}
|
||||
|
||||
// NewExporterSettings return a new ExporterSettings with the given ComponentID.
|
||||
func NewExporterSettings(id ComponentID) ExporterSettings {
|
||||
return ExporterSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
// NewExporterConfigSettings return a new ExporterSettings with the given ComponentID.
|
||||
func NewExporterConfigSettings(id ID) ExporterConfigSettings {
|
||||
return ExporterConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
}
|
||||
|
||||
var _ Exporter = (*ExporterSettings)(nil)
|
||||
var _ ExporterConfig = (*ExporterConfigSettings)(nil)
|
||||
|
||||
// ID returns the receiver ComponentID.
|
||||
func (es *ExporterSettings) ID() ComponentID {
|
||||
func (es *ExporterConfigSettings) ID() ID {
|
||||
return es.id
|
||||
}
|
||||
|
||||
// SetIDName sets the receiver name.
|
||||
func (es *ExporterSettings) SetIDName(idName string) {
|
||||
func (es *ExporterConfigSettings) SetIDName(idName string) {
|
||||
es.id.nameVal = idName
|
||||
}
|
||||
|
||||
// Validate validates the configuration and returns an error if invalid.
|
||||
func (es *ExporterSettings) Validate() error {
|
||||
func (es *ExporterConfigSettings) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (es *ExporterSettings) privateConfigExporter() {}
|
||||
func (es *ExporterConfigSettings) privateConfigExporter() {}
|
|
@ -19,16 +19,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
func TestNewExporterFactory(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewExporterSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewExporterConfigSettings(NewID(typeStr))
|
||||
factory := NewExporterFactory(
|
||||
typeStr,
|
||||
func() config.Exporter { return &defaultCfg })
|
||||
func() ExporterConfig { return &defaultCfg })
|
||||
assert.EqualValues(t, typeStr, factory.Type())
|
||||
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
|
||||
_, err := factory.CreateTracesExporter(context.Background(), ExporterCreateSettings{}, &defaultCfg)
|
||||
|
@ -41,10 +39,10 @@ func TestNewExporterFactory(t *testing.T) {
|
|||
|
||||
func TestNewExporterFactory_WithOptions(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewExporterSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewExporterConfigSettings(NewID(typeStr))
|
||||
factory := NewExporterFactory(
|
||||
typeStr,
|
||||
func() config.Exporter { return &defaultCfg },
|
||||
func() ExporterConfig { return &defaultCfg },
|
||||
WithTracesExporter(createTracesExporter, StabilityLevelInDevelopment),
|
||||
WithMetricsExporter(createMetricsExporter, StabilityLevelAlpha),
|
||||
WithLogsExporter(createLogsExporter, StabilityLevelDeprecated))
|
||||
|
@ -64,14 +62,14 @@ func TestNewExporterFactory_WithOptions(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func createTracesExporter(context.Context, ExporterCreateSettings, config.Exporter) (TracesExporter, error) {
|
||||
func createTracesExporter(context.Context, ExporterCreateSettings, ExporterConfig) (TracesExporter, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createMetricsExporter(context.Context, ExporterCreateSettings, config.Exporter) (MetricsExporter, error) {
|
||||
func createMetricsExporter(context.Context, ExporterCreateSettings, ExporterConfig) (MetricsExporter, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createLogsExporter(context.Context, ExporterCreateSettings, config.Exporter) (LogsExporter, error) {
|
||||
func createLogsExporter(context.Context, ExporterCreateSettings, ExporterConfig) (LogsExporter, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ package component // import "go.opentelemetry.io/collector/component"
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
// Extension is the interface for objects hosted by the OpenTelemetry Collector that
|
||||
|
@ -52,19 +50,19 @@ type ExtensionCreateSettings struct {
|
|||
BuildInfo BuildInfo
|
||||
}
|
||||
|
||||
// ExtensionCreateDefaultConfigFunc is the equivalent of component.ExtensionFactory.CreateDefaultConfig()
|
||||
type ExtensionCreateDefaultConfigFunc func() config.Extension
|
||||
// ExtensionCreateDefaultConfigFunc is the equivalent of ExtensionFactory.CreateDefaultConfig()
|
||||
type ExtensionCreateDefaultConfigFunc func() ExtensionConfig
|
||||
|
||||
// CreateDefaultConfig implements ExtensionFactory.CreateDefaultConfig()
|
||||
func (f ExtensionCreateDefaultConfigFunc) CreateDefaultConfig() config.Extension {
|
||||
func (f ExtensionCreateDefaultConfigFunc) CreateDefaultConfig() ExtensionConfig {
|
||||
return f()
|
||||
}
|
||||
|
||||
// CreateExtensionFunc is the equivalent of component.ExtensionFactory.CreateExtension()
|
||||
type CreateExtensionFunc func(context.Context, ExtensionCreateSettings, config.Extension) (Extension, error)
|
||||
// CreateExtensionFunc is the equivalent of ExtensionFactory.CreateExtension()
|
||||
type CreateExtensionFunc func(context.Context, ExtensionCreateSettings, ExtensionConfig) (Extension, error)
|
||||
|
||||
// CreateExtension implements ExtensionFactory.CreateExtension.
|
||||
func (f CreateExtensionFunc) CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg config.Extension) (Extension, error) {
|
||||
func (f CreateExtensionFunc) CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg ExtensionConfig) (Extension, error) {
|
||||
return f(ctx, set, cfg)
|
||||
}
|
||||
|
||||
|
@ -77,12 +75,12 @@ type ExtensionFactory interface {
|
|||
// configuration and should not cause side-effects that prevent the creation
|
||||
// of multiple instances of the Extension.
|
||||
// The object returned by this method needs to pass the checks implemented by
|
||||
// 'configtest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// tests of any implementation of the Factory interface.
|
||||
CreateDefaultConfig() config.Extension
|
||||
CreateDefaultConfig() ExtensionConfig
|
||||
|
||||
// CreateExtension creates an extension based on the given config.
|
||||
CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg config.Extension) (Extension, error)
|
||||
CreateExtension(ctx context.Context, set ExtensionCreateSettings, cfg ExtensionConfig) (Extension, error)
|
||||
|
||||
// ExtensionStability gets the stability level of the Extension.
|
||||
ExtensionStability() StabilityLevel
|
||||
|
@ -101,7 +99,7 @@ func (ef *extensionFactory) ExtensionStability() StabilityLevel {
|
|||
|
||||
// NewExtensionFactory returns a new ExtensionFactory based on this configuration.
|
||||
func NewExtensionFactory(
|
||||
cfgType config.Type,
|
||||
cfgType Type,
|
||||
createDefaultConfig ExtensionCreateDefaultConfigFunc,
|
||||
createServiceExtension CreateExtensionFunc,
|
||||
sl StabilityLevel) ExtensionFactory {
|
||||
|
|
|
@ -12,57 +12,58 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
)
|
||||
|
||||
// Extension is the configuration of a component.Extension. Specific extensions must implement
|
||||
// this interface and must embed ExtensionSettings struct or a struct that extends it.
|
||||
type Extension interface {
|
||||
// ExtensionConfig is the configuration of a component.Extension. Specific extensions must implement
|
||||
// this interface and must embed ExtensionConfigSettings struct or a struct that extends it.
|
||||
type ExtensionConfig interface {
|
||||
identifiable
|
||||
validatable
|
||||
|
||||
privateConfigExtension()
|
||||
}
|
||||
|
||||
// UnmarshalExtension helper function to unmarshal an Extension config.
|
||||
// UnmarshalExtensionConfig helper function to unmarshal an ExtensionConfig.
|
||||
// It checks if the config implements confmap.Unmarshaler and uses that if available,
|
||||
// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent.
|
||||
func UnmarshalExtension(conf *confmap.Conf, cfg Extension) error {
|
||||
func UnmarshalExtensionConfig(conf *confmap.Conf, cfg ExtensionConfig) error {
|
||||
return unmarshal(conf, cfg)
|
||||
}
|
||||
|
||||
// ExtensionSettings defines common settings for a component.Extension configuration.
|
||||
// ExtensionConfigSettings defines common settings for a component.Extension configuration.
|
||||
// Specific processors can embed this struct and extend it with more fields if needed.
|
||||
//
|
||||
// It is highly recommended to "override" the Validate() function.
|
||||
//
|
||||
// When embedded in the extension config, it must be with `mapstructure:",squash"` tag.
|
||||
type ExtensionSettings struct {
|
||||
id ComponentID `mapstructure:"-"`
|
||||
type ExtensionConfigSettings struct {
|
||||
id ID `mapstructure:"-"`
|
||||
}
|
||||
|
||||
// NewExtensionSettings return a new ExtensionSettings with the given ComponentID.
|
||||
func NewExtensionSettings(id ComponentID) ExtensionSettings {
|
||||
return ExtensionSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
// NewExtensionConfigSettings return a new ExtensionConfigSettings with the given ID.
|
||||
func NewExtensionConfigSettings(id ID) ExtensionConfigSettings {
|
||||
return ExtensionConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
}
|
||||
|
||||
var _ Extension = (*ExtensionSettings)(nil)
|
||||
var _ ExtensionConfig = (*ExtensionConfigSettings)(nil)
|
||||
|
||||
// ID returns the receiver ComponentID.
|
||||
func (es *ExtensionSettings) ID() ComponentID {
|
||||
// ID returns the receiver ID.
|
||||
func (es *ExtensionConfigSettings) ID() ID {
|
||||
return es.id
|
||||
}
|
||||
|
||||
// SetIDName sets the receiver name.
|
||||
func (es *ExtensionSettings) SetIDName(idName string) {
|
||||
func (es *ExtensionConfigSettings) SetIDName(idName string) {
|
||||
es.id.nameVal = idName
|
||||
}
|
||||
|
||||
// Validate validates the configuration and returns an error if invalid.
|
||||
func (es *ExtensionSettings) Validate() error {
|
||||
func (es *ExtensionConfigSettings) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (es *ExtensionSettings) privateConfigExtension() {}
|
||||
func (es *ExtensionConfigSettings) privateConfigExtension() {}
|
|
@ -19,8 +19,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
type nopExtension struct {
|
||||
|
@ -30,13 +28,13 @@ type nopExtension struct {
|
|||
|
||||
func TestNewExtensionFactory(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewExtensionSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewExtensionConfigSettings(NewID(typeStr))
|
||||
nopExtensionInstance := new(nopExtension)
|
||||
|
||||
factory := NewExtensionFactory(
|
||||
typeStr,
|
||||
func() config.Extension { return &defaultCfg },
|
||||
func(ctx context.Context, settings ExtensionCreateSettings, extension config.Extension) (Extension, error) {
|
||||
func() ExtensionConfig { return &defaultCfg },
|
||||
func(ctx context.Context, settings ExtensionCreateSettings, extension ExtensionConfig) (Extension, error) {
|
||||
return nopExtensionInstance, nil
|
||||
},
|
||||
StabilityLevelInDevelopment)
|
||||
|
|
|
@ -16,31 +16,29 @@ package component // import "go.opentelemetry.io/collector/component"
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
// Factories struct holds in a single type all component factories that
|
||||
// can be handled by the Config.
|
||||
type Factories struct {
|
||||
// Receivers maps receiver type names in the config to the respective factory.
|
||||
Receivers map[config.Type]ReceiverFactory
|
||||
Receivers map[Type]ReceiverFactory
|
||||
|
||||
// Processors maps processor type names in the config to the respective factory.
|
||||
Processors map[config.Type]ProcessorFactory
|
||||
Processors map[Type]ProcessorFactory
|
||||
|
||||
// Exporters maps exporter type names in the config to the respective factory.
|
||||
Exporters map[config.Type]ExporterFactory
|
||||
Exporters map[Type]ExporterFactory
|
||||
|
||||
// Extensions maps extension type names in the config to the respective factory.
|
||||
Extensions map[config.Type]ExtensionFactory
|
||||
Extensions map[Type]ExtensionFactory
|
||||
}
|
||||
|
||||
// MakeReceiverFactoryMap takes a list of receiver factories and returns a map
|
||||
// with factory type as keys. It returns a non-nil error when more than one factories
|
||||
// have the same type.
|
||||
func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[config.Type]ReceiverFactory, error) {
|
||||
fMap := map[config.Type]ReceiverFactory{}
|
||||
func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[Type]ReceiverFactory, error) {
|
||||
fMap := map[Type]ReceiverFactory{}
|
||||
for _, f := range factories {
|
||||
if _, ok := fMap[f.Type()]; ok {
|
||||
return fMap, fmt.Errorf("duplicate receiver factory %q", f.Type())
|
||||
|
@ -53,8 +51,8 @@ func MakeReceiverFactoryMap(factories ...ReceiverFactory) (map[config.Type]Recei
|
|||
// MakeProcessorFactoryMap takes a list of processor factories and returns a map
|
||||
// with factory type as keys. It returns a non-nil error when more than one factories
|
||||
// have the same type.
|
||||
func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[config.Type]ProcessorFactory, error) {
|
||||
fMap := map[config.Type]ProcessorFactory{}
|
||||
func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[Type]ProcessorFactory, error) {
|
||||
fMap := map[Type]ProcessorFactory{}
|
||||
for _, f := range factories {
|
||||
if _, ok := fMap[f.Type()]; ok {
|
||||
return fMap, fmt.Errorf("duplicate processor factory %q", f.Type())
|
||||
|
@ -67,8 +65,8 @@ func MakeProcessorFactoryMap(factories ...ProcessorFactory) (map[config.Type]Pro
|
|||
// MakeExporterFactoryMap takes a list of exporter factories and returns a map
|
||||
// with factory type as keys. It returns a non-nil error when more than one factories
|
||||
// have the same type.
|
||||
func MakeExporterFactoryMap(factories ...ExporterFactory) (map[config.Type]ExporterFactory, error) {
|
||||
fMap := map[config.Type]ExporterFactory{}
|
||||
func MakeExporterFactoryMap(factories ...ExporterFactory) (map[Type]ExporterFactory, error) {
|
||||
fMap := map[Type]ExporterFactory{}
|
||||
for _, f := range factories {
|
||||
if _, ok := fMap[f.Type()]; ok {
|
||||
return fMap, fmt.Errorf("duplicate exporter factory %q", f.Type())
|
||||
|
@ -81,8 +79,8 @@ func MakeExporterFactoryMap(factories ...ExporterFactory) (map[config.Type]Expor
|
|||
// MakeExtensionFactoryMap takes a list of extension factories and returns a map
|
||||
// with factory type as keys. It returns a non-nil error when more than one factories
|
||||
// have the same type.
|
||||
func MakeExtensionFactoryMap(factories ...ExtensionFactory) (map[config.Type]ExtensionFactory, error) {
|
||||
fMap := map[config.Type]ExtensionFactory{}
|
||||
func MakeExtensionFactoryMap(factories ...ExtensionFactory) (map[Type]ExtensionFactory, error) {
|
||||
fMap := map[Type]ExtensionFactory{}
|
||||
for _, f := range factories {
|
||||
if _, ok := fMap[f.Type()]; ok {
|
||||
return fMap, fmt.Errorf("duplicate extension factory %q", f.Type())
|
||||
|
|
|
@ -18,15 +18,13 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
func TestMakeExtensionFactoryMap(t *testing.T) {
|
||||
type testCase struct {
|
||||
name string
|
||||
in []ExtensionFactory
|
||||
out map[config.Type]ExtensionFactory
|
||||
out map[Type]ExtensionFactory
|
||||
}
|
||||
|
||||
p1 := NewExtensionFactory("p1", nil, nil, StabilityLevelAlpha)
|
||||
|
@ -35,7 +33,7 @@ func TestMakeExtensionFactoryMap(t *testing.T) {
|
|||
{
|
||||
name: "different names",
|
||||
in: []ExtensionFactory{p1, p2},
|
||||
out: map[config.Type]ExtensionFactory{
|
||||
out: map[Type]ExtensionFactory{
|
||||
p1.Type(): p1,
|
||||
p2.Type(): p2,
|
||||
},
|
||||
|
@ -63,7 +61,7 @@ func TestMakeReceiverFactoryMap(t *testing.T) {
|
|||
type testCase struct {
|
||||
name string
|
||||
in []ReceiverFactory
|
||||
out map[config.Type]ReceiverFactory
|
||||
out map[Type]ReceiverFactory
|
||||
}
|
||||
|
||||
p1 := NewReceiverFactory("p1", nil)
|
||||
|
@ -72,7 +70,7 @@ func TestMakeReceiverFactoryMap(t *testing.T) {
|
|||
{
|
||||
name: "different names",
|
||||
in: []ReceiverFactory{p1, p2},
|
||||
out: map[config.Type]ReceiverFactory{
|
||||
out: map[Type]ReceiverFactory{
|
||||
p1.Type(): p1,
|
||||
p2.Type(): p2,
|
||||
},
|
||||
|
@ -101,7 +99,7 @@ func TestMakeProcessorFactoryMap(t *testing.T) {
|
|||
type testCase struct {
|
||||
name string
|
||||
in []ProcessorFactory
|
||||
out map[config.Type]ProcessorFactory
|
||||
out map[Type]ProcessorFactory
|
||||
}
|
||||
|
||||
p1 := NewProcessorFactory("p1", nil)
|
||||
|
@ -110,7 +108,7 @@ func TestMakeProcessorFactoryMap(t *testing.T) {
|
|||
{
|
||||
name: "different names",
|
||||
in: []ProcessorFactory{p1, p2},
|
||||
out: map[config.Type]ProcessorFactory{
|
||||
out: map[Type]ProcessorFactory{
|
||||
p1.Type(): p1,
|
||||
p2.Type(): p2,
|
||||
},
|
||||
|
@ -139,7 +137,7 @@ func TestMakeExporterFactoryMap(t *testing.T) {
|
|||
type testCase struct {
|
||||
name string
|
||||
in []ExporterFactory
|
||||
out map[config.Type]ExporterFactory
|
||||
out map[Type]ExporterFactory
|
||||
}
|
||||
|
||||
p1 := NewExporterFactory("p1", nil)
|
||||
|
@ -148,7 +146,7 @@ func TestMakeExporterFactoryMap(t *testing.T) {
|
|||
{
|
||||
name: "different names",
|
||||
in: []ExporterFactory{p1, p2},
|
||||
out: map[config.Type]ExporterFactory{
|
||||
out: map[Type]ExporterFactory{
|
||||
p1.Type(): p1,
|
||||
p2.Type(): p2,
|
||||
},
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
// Host represents the entity that is hosting a Component. It is used to allow communication
|
||||
// between the Component and its host (normally the service.Collector is the host).
|
||||
type Host interface {
|
||||
|
@ -40,7 +36,7 @@ type Host interface {
|
|||
// GetFactory can be called by the component anytime after Component.Start() begins and
|
||||
// until Component.Shutdown() ends. Note that the component is responsible for destroying
|
||||
// other components that it creates.
|
||||
GetFactory(kind Kind, componentType config.Type) Factory
|
||||
GetFactory(kind Kind, componentType Type) Factory
|
||||
|
||||
// GetExtensions returns the map of extensions. Only enabled and created extensions will be returned.
|
||||
// Typically is used to find an extension by type or by full config name. Both cases
|
||||
|
@ -49,7 +45,7 @@ type Host interface {
|
|||
//
|
||||
// GetExtensions can be called by the component anytime after Component.Start() begins and
|
||||
// until Component.Shutdown() ends.
|
||||
GetExtensions() map[config.ComponentID]Extension
|
||||
GetExtensions() map[ID]Extension
|
||||
|
||||
// GetExporters returns the map of exporters. Only enabled and created exporters will be returned.
|
||||
// Typically is used to find exporters by type or by full config name. Both cases
|
||||
|
@ -62,5 +58,5 @@ type Host interface {
|
|||
//
|
||||
// GetExporters can be called by the component anytime after Component.Start() begins and
|
||||
// until Component.Shutdown() ends.
|
||||
GetExporters() map[config.DataType]map[config.ComponentID]Exporter
|
||||
GetExporters() map[DataType]map[ID]Exporter
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -26,57 +26,48 @@ const typeAndNameSeparator = "/"
|
|||
// identifiable is an interface that all components configurations MUST embed.
|
||||
type identifiable interface {
|
||||
// ID returns the ID of the component that this configuration belongs to.
|
||||
ID() ComponentID
|
||||
ID() ID
|
||||
// SetIDName updates the name part of the ID for the component that this configuration belongs to.
|
||||
SetIDName(idName string)
|
||||
}
|
||||
|
||||
// ComponentID represents the identity for a component. It combines two values:
|
||||
// ID represents the identity for a component. It combines two values:
|
||||
// * type - the Type of the component.
|
||||
// * name - the name of that component.
|
||||
// The component ComponentID (combination type + name) is unique for a given component.Kind.
|
||||
type ComponentID struct {
|
||||
// The component ID (combination type + name) is unique for a given component.Kind.
|
||||
type ID struct {
|
||||
typeVal Type `mapstructure:"-"`
|
||||
nameVal string `mapstructure:"-"`
|
||||
}
|
||||
|
||||
// NewComponentID returns a new ComponentID with the given Type and empty name.
|
||||
func NewComponentID(typeVal Type) ComponentID {
|
||||
return ComponentID{typeVal: typeVal}
|
||||
// NewID returns a new ID with the given Type and empty name.
|
||||
func NewID(typeVal Type) ID {
|
||||
return ID{typeVal: typeVal}
|
||||
}
|
||||
|
||||
// NewComponentIDWithName returns a new ComponentID with the given Type and name.
|
||||
func NewComponentIDWithName(typeVal Type, nameVal string) ComponentID {
|
||||
return ComponentID{typeVal: typeVal, nameVal: nameVal}
|
||||
}
|
||||
|
||||
// NewComponentIDFromString decodes a string in type[/name] format into ComponentID.
|
||||
// The type and name components will have spaces trimmed, the "type" part must be present,
|
||||
// the forward slash and "name" are optional.
|
||||
// The returned ComponentID will be invalid if err is not-nil.
|
||||
func NewComponentIDFromString(idStr string) (ComponentID, error) {
|
||||
id := ComponentID{}
|
||||
return id, id.UnmarshalText([]byte(idStr))
|
||||
// NewIDWithName returns a new ID with the given Type and name.
|
||||
func NewIDWithName(typeVal Type, nameVal string) ID {
|
||||
return ID{typeVal: typeVal, nameVal: nameVal}
|
||||
}
|
||||
|
||||
// Type returns the type of the component.
|
||||
func (id ComponentID) Type() Type {
|
||||
func (id ID) Type() Type {
|
||||
return id.typeVal
|
||||
}
|
||||
|
||||
// Name returns the custom name of the component.
|
||||
func (id ComponentID) Name() string {
|
||||
func (id ID) Name() string {
|
||||
return id.nameVal
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface.
|
||||
// This marshals the type and name as one string in the config.
|
||||
func (id ComponentID) MarshalText() (text []byte, err error) {
|
||||
func (id ID) MarshalText() (text []byte, err error) {
|
||||
return []byte(id.String()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||
func (id *ComponentID) UnmarshalText(text []byte) error {
|
||||
func (id *ID) UnmarshalText(text []byte) error {
|
||||
idStr := string(text)
|
||||
items := strings.SplitN(idStr, typeAndNameSeparator, 2)
|
||||
if len(items) >= 1 {
|
||||
|
@ -102,8 +93,8 @@ func (id *ComponentID) UnmarshalText(text []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// String returns the ComponentID string representation as "type[/name]" format.
|
||||
func (id ComponentID) String() string {
|
||||
// String returns the ID string representation as "type[/name]" format.
|
||||
func (id ID) String() string {
|
||||
if id.nameVal == "" {
|
||||
return string(id.typeVal)
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config
|
||||
package component
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -20,23 +20,30 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIDFromString(t *testing.T) {
|
||||
func TestMarshalText(t *testing.T) {
|
||||
id := NewIDWithName("test", "name")
|
||||
got, err := id.MarshalText()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, id.String(), string(got))
|
||||
}
|
||||
|
||||
func TestUnmarshalText(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
idStr string
|
||||
expectedErr bool
|
||||
expectedID ComponentID
|
||||
expectedID ID
|
||||
}{
|
||||
{
|
||||
idStr: "valid_type",
|
||||
expectedID: ComponentID{typeVal: "valid_type", nameVal: ""},
|
||||
expectedID: ID{typeVal: "valid_type", nameVal: ""},
|
||||
},
|
||||
{
|
||||
idStr: "valid_type/valid_name",
|
||||
expectedID: ComponentID{typeVal: "valid_type", nameVal: "valid_name"},
|
||||
expectedID: ID{typeVal: "valid_type", nameVal: "valid_name"},
|
||||
},
|
||||
{
|
||||
idStr: " valid_type / valid_name ",
|
||||
expectedID: ComponentID{typeVal: "valid_type", nameVal: "valid_name"},
|
||||
expectedID: ID{typeVal: "valid_type", nameVal: "valid_name"},
|
||||
},
|
||||
{
|
||||
idStr: "/valid_name",
|
||||
|
@ -62,7 +69,8 @@ func TestIDFromString(t *testing.T) {
|
|||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.idStr, func(t *testing.T) {
|
||||
id, err := NewComponentIDFromString(test.idStr)
|
||||
id := ID{}
|
||||
err := id.UnmarshalText([]byte(test.idStr))
|
||||
if test.expectedErr {
|
||||
assert.Error(t, err)
|
||||
return
|
||||
|
@ -76,10 +84,3 @@ func TestIDFromString(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalText(t *testing.T) {
|
||||
id := NewComponentIDWithName("test", "name")
|
||||
got, err := id.MarshalText()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, id.String(), string(got))
|
||||
}
|
|
@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
|
|||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
|
@ -65,14 +64,14 @@ type ProcessorFactory interface {
|
|||
// configuration and should not cause side-effects that prevent the creation
|
||||
// of multiple instances of the Processor.
|
||||
// The object returned by this method needs to pass the checks implemented by
|
||||
// 'configtest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// tests of any implementation of the Factory interface.
|
||||
CreateDefaultConfig() config.Processor
|
||||
CreateDefaultConfig() ProcessorConfig
|
||||
|
||||
// CreateTracesProcessor creates a TracesProcessor based on this config.
|
||||
// If the processor type does not support tracing or if the config is not valid,
|
||||
// an error will be returned instead.
|
||||
CreateTracesProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Traces) (TracesProcessor, error)
|
||||
CreateTracesProcessor(ctx context.Context, set ProcessorCreateSettings, cfg ProcessorConfig, nextConsumer consumer.Traces) (TracesProcessor, error)
|
||||
|
||||
// TracesProcessorStability gets the stability level of the TracesProcessor.
|
||||
TracesProcessorStability() StabilityLevel
|
||||
|
@ -80,7 +79,7 @@ type ProcessorFactory interface {
|
|||
// CreateMetricsProcessor creates a MetricsProcessor based on this config.
|
||||
// If the processor type does not support metrics or if the config is not valid,
|
||||
// an error will be returned instead.
|
||||
CreateMetricsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Metrics) (MetricsProcessor, error)
|
||||
CreateMetricsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg ProcessorConfig, nextConsumer consumer.Metrics) (MetricsProcessor, error)
|
||||
|
||||
// MetricsProcessorStability gets the stability level of the MetricsProcessor.
|
||||
MetricsProcessorStability() StabilityLevel
|
||||
|
@ -88,17 +87,17 @@ type ProcessorFactory interface {
|
|||
// CreateLogsProcessor creates a LogsProcessor based on the config.
|
||||
// If the processor type does not support logs or if the config is not valid,
|
||||
// an error will be returned instead.
|
||||
CreateLogsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg config.Processor, nextConsumer consumer.Logs) (LogsProcessor, error)
|
||||
CreateLogsProcessor(ctx context.Context, set ProcessorCreateSettings, cfg ProcessorConfig, nextConsumer consumer.Logs) (LogsProcessor, error)
|
||||
|
||||
// LogsProcessorStability gets the stability level of the LogsProcessor.
|
||||
LogsProcessorStability() StabilityLevel
|
||||
}
|
||||
|
||||
// ProcessorCreateDefaultConfigFunc is the equivalent of ProcessorFactory.CreateDefaultConfig().
|
||||
type ProcessorCreateDefaultConfigFunc func() config.Processor
|
||||
type ProcessorCreateDefaultConfigFunc func() ProcessorConfig
|
||||
|
||||
// CreateDefaultConfig implements ProcessorFactory.CreateDefaultConfig().
|
||||
func (f ProcessorCreateDefaultConfigFunc) CreateDefaultConfig() config.Processor {
|
||||
func (f ProcessorCreateDefaultConfigFunc) CreateDefaultConfig() ProcessorConfig {
|
||||
return f()
|
||||
}
|
||||
|
||||
|
@ -118,13 +117,13 @@ func (f processorFactoryOptionFunc) applyProcessorFactoryOption(o *processorFact
|
|||
}
|
||||
|
||||
// CreateTracesProcessorFunc is the equivalent of ProcessorFactory.CreateTracesProcessor().
|
||||
type CreateTracesProcessorFunc func(context.Context, ProcessorCreateSettings, config.Processor, consumer.Traces) (TracesProcessor, error)
|
||||
type CreateTracesProcessorFunc func(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Traces) (TracesProcessor, error)
|
||||
|
||||
// CreateTracesProcessor implements ProcessorFactory.CreateTracesProcessor().
|
||||
func (f CreateTracesProcessorFunc) CreateTracesProcessor(
|
||||
ctx context.Context,
|
||||
set ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg ProcessorConfig,
|
||||
nextConsumer consumer.Traces) (TracesProcessor, error) {
|
||||
if f == nil {
|
||||
return nil, ErrDataTypeIsNotSupported
|
||||
|
@ -133,13 +132,13 @@ func (f CreateTracesProcessorFunc) CreateTracesProcessor(
|
|||
}
|
||||
|
||||
// CreateMetricsProcessorFunc is the equivalent of ProcessorFactory.CreateMetricsProcessor().
|
||||
type CreateMetricsProcessorFunc func(context.Context, ProcessorCreateSettings, config.Processor, consumer.Metrics) (MetricsProcessor, error)
|
||||
type CreateMetricsProcessorFunc func(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Metrics) (MetricsProcessor, error)
|
||||
|
||||
// CreateMetricsProcessor implements ProcessorFactory.CreateMetricsProcessor().
|
||||
func (f CreateMetricsProcessorFunc) CreateMetricsProcessor(
|
||||
ctx context.Context,
|
||||
set ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg ProcessorConfig,
|
||||
nextConsumer consumer.Metrics,
|
||||
) (MetricsProcessor, error) {
|
||||
if f == nil {
|
||||
|
@ -149,13 +148,13 @@ func (f CreateMetricsProcessorFunc) CreateMetricsProcessor(
|
|||
}
|
||||
|
||||
// CreateLogsProcessorFunc is the equivalent of ProcessorFactory.CreateLogsProcessor().
|
||||
type CreateLogsProcessorFunc func(context.Context, ProcessorCreateSettings, config.Processor, consumer.Logs) (LogsProcessor, error)
|
||||
type CreateLogsProcessorFunc func(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Logs) (LogsProcessor, error)
|
||||
|
||||
// CreateLogsProcessor implements ProcessorFactory.CreateLogsProcessor().
|
||||
func (f CreateLogsProcessorFunc) CreateLogsProcessor(
|
||||
ctx context.Context,
|
||||
set ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg ProcessorConfig,
|
||||
nextConsumer consumer.Logs,
|
||||
) (LogsProcessor, error) {
|
||||
if f == nil {
|
||||
|
@ -212,7 +211,7 @@ func WithLogsProcessor(createLogsProcessor CreateLogsProcessorFunc, sl Stability
|
|||
}
|
||||
|
||||
// NewProcessorFactory returns a ProcessorFactory.
|
||||
func NewProcessorFactory(cfgType config.Type, createDefaultConfig ProcessorCreateDefaultConfigFunc, options ...ProcessorFactoryOption) ProcessorFactory {
|
||||
func NewProcessorFactory(cfgType Type, createDefaultConfig ProcessorCreateDefaultConfigFunc, options ...ProcessorFactoryOption) ProcessorFactory {
|
||||
f := &processorFactory{
|
||||
baseFactory: baseFactory{cfgType: cfgType},
|
||||
ProcessorCreateDefaultConfigFunc: createDefaultConfig,
|
||||
|
|
|
@ -12,57 +12,58 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
)
|
||||
|
||||
// Processor is the configuration of a component.Processor. Specific extensions must implement
|
||||
// this interface and must embed ProcessorSettings struct or a struct that extends it.
|
||||
type Processor interface {
|
||||
// ProcessorConfig is the configuration of a component.Processor. Specific extensions must implement
|
||||
// this interface and must embed ProcessorConfigSettings struct or a struct that extends it.
|
||||
type ProcessorConfig interface {
|
||||
identifiable
|
||||
validatable
|
||||
|
||||
privateConfigProcessor()
|
||||
}
|
||||
|
||||
// UnmarshalProcessor helper function to unmarshal a Processor config.
|
||||
// UnmarshalProcessorConfig helper function to unmarshal a ProcessorConfig.
|
||||
// It checks if the config implements confmap.Unmarshaler and uses that if available,
|
||||
// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent.
|
||||
func UnmarshalProcessor(conf *confmap.Conf, cfg Processor) error {
|
||||
func UnmarshalProcessorConfig(conf *confmap.Conf, cfg ProcessorConfig) error {
|
||||
return unmarshal(conf, cfg)
|
||||
}
|
||||
|
||||
// ProcessorSettings defines common settings for a component.Processor configuration.
|
||||
// ProcessorConfigSettings defines common settings for a component.Processor configuration.
|
||||
// Specific processors can embed this struct and extend it with more fields if needed.
|
||||
//
|
||||
// It is highly recommended to "override" the Validate() function.
|
||||
//
|
||||
// When embedded in the processor config it must be with `mapstructure:",squash"` tag.
|
||||
type ProcessorSettings struct {
|
||||
id ComponentID `mapstructure:"-"`
|
||||
type ProcessorConfigSettings struct {
|
||||
id ID `mapstructure:"-"`
|
||||
}
|
||||
|
||||
// NewProcessorSettings return a new ProcessorSettings with the given ComponentID.
|
||||
func NewProcessorSettings(id ComponentID) ProcessorSettings {
|
||||
return ProcessorSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
// NewProcessorConfigSettings return a new ProcessorConfigSettings with the given ComponentID.
|
||||
func NewProcessorConfigSettings(id ID) ProcessorConfigSettings {
|
||||
return ProcessorConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
}
|
||||
|
||||
var _ Processor = (*ProcessorSettings)(nil)
|
||||
var _ ProcessorConfig = (*ProcessorConfigSettings)(nil)
|
||||
|
||||
// ID returns the receiver ComponentID.
|
||||
func (ps *ProcessorSettings) ID() ComponentID {
|
||||
func (ps *ProcessorConfigSettings) ID() ID {
|
||||
return ps.id
|
||||
}
|
||||
|
||||
// SetIDName sets the receiver name.
|
||||
func (ps *ProcessorSettings) SetIDName(idName string) {
|
||||
func (ps *ProcessorConfigSettings) SetIDName(idName string) {
|
||||
ps.id.nameVal = idName
|
||||
}
|
||||
|
||||
// Validate validates the configuration and returns an error if invalid.
|
||||
func (ps *ProcessorSettings) Validate() error {
|
||||
func (ps *ProcessorConfigSettings) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *ProcessorSettings) privateConfigProcessor() {}
|
||||
func (ps *ProcessorConfigSettings) privateConfigProcessor() {}
|
|
@ -20,16 +20,15 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
func TestNewProcessorFactory(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewProcessorSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewProcessorConfigSettings(NewID(typeStr))
|
||||
factory := NewProcessorFactory(
|
||||
typeStr,
|
||||
func() config.Processor { return &defaultCfg })
|
||||
func() ProcessorConfig { return &defaultCfg })
|
||||
assert.EqualValues(t, typeStr, factory.Type())
|
||||
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
|
||||
_, err := factory.CreateTracesProcessor(context.Background(), ProcessorCreateSettings{}, &defaultCfg, nil)
|
||||
|
@ -42,10 +41,10 @@ func TestNewProcessorFactory(t *testing.T) {
|
|||
|
||||
func TestNewProcessorFactory_WithOptions(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewProcessorSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewProcessorConfigSettings(NewID(typeStr))
|
||||
factory := NewProcessorFactory(
|
||||
typeStr,
|
||||
func() config.Processor { return &defaultCfg },
|
||||
func() ProcessorConfig { return &defaultCfg },
|
||||
WithTracesProcessor(createTracesProcessor, StabilityLevelAlpha),
|
||||
WithMetricsProcessor(createMetricsProcessor, StabilityLevelBeta),
|
||||
WithLogsProcessor(createLogsProcessor, StabilityLevelUnmaintained))
|
||||
|
@ -65,14 +64,14 @@ func TestNewProcessorFactory_WithOptions(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func createTracesProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Traces) (TracesProcessor, error) {
|
||||
func createTracesProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Traces) (TracesProcessor, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createMetricsProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Metrics) (MetricsProcessor, error) {
|
||||
func createMetricsProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Metrics) (MetricsProcessor, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createLogsProcessor(context.Context, ProcessorCreateSettings, config.Processor, consumer.Logs) (LogsProcessor, error) {
|
||||
func createLogsProcessor(context.Context, ProcessorCreateSettings, ProcessorConfig, consumer.Logs) (LogsProcessor, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package component // import "go.opentelemetry.io/collector/component"
|
|||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
|
@ -110,14 +109,14 @@ type ReceiverFactory interface {
|
|||
// configuration and should not cause side-effects that prevent the creation
|
||||
// of multiple instances of the Receiver.
|
||||
// The object returned by this method needs to pass the checks implemented by
|
||||
// 'configtest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// 'componenttest.CheckConfigStruct'. It is recommended to have these checks in the
|
||||
// tests of any implementation of the Factory interface.
|
||||
CreateDefaultConfig() config.Receiver
|
||||
CreateDefaultConfig() ReceiverConfig
|
||||
|
||||
// CreateTracesReceiver creates a TracesReceiver based on this config.
|
||||
// If the receiver type does not support tracing or if the config is not valid
|
||||
// an error will be returned instead.
|
||||
CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Traces) (TracesReceiver, error)
|
||||
CreateTracesReceiver(ctx context.Context, set ReceiverCreateSettings, cfg ReceiverConfig, nextConsumer consumer.Traces) (TracesReceiver, error)
|
||||
|
||||
// TracesReceiverStability gets the stability level of the TracesReceiver.
|
||||
TracesReceiverStability() StabilityLevel
|
||||
|
@ -125,7 +124,7 @@ type ReceiverFactory interface {
|
|||
// CreateMetricsReceiver creates a MetricsReceiver based on this config.
|
||||
// If the receiver type does not support metrics or if the config is not valid
|
||||
// an error will be returned instead.
|
||||
CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Metrics) (MetricsReceiver, error)
|
||||
CreateMetricsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg ReceiverConfig, nextConsumer consumer.Metrics) (MetricsReceiver, error)
|
||||
|
||||
// MetricsReceiverStability gets the stability level of the MetricsReceiver.
|
||||
MetricsReceiverStability() StabilityLevel
|
||||
|
@ -133,7 +132,7 @@ type ReceiverFactory interface {
|
|||
// CreateLogsReceiver creates a LogsReceiver based on this config.
|
||||
// If the receiver type does not support the data type or if the config is not valid
|
||||
// an error will be returned instead.
|
||||
CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg config.Receiver, nextConsumer consumer.Logs) (LogsReceiver, error)
|
||||
CreateLogsReceiver(ctx context.Context, set ReceiverCreateSettings, cfg ReceiverConfig, nextConsumer consumer.Logs) (LogsReceiver, error)
|
||||
|
||||
// LogsReceiverStability gets the stability level of the LogsReceiver.
|
||||
LogsReceiverStability() StabilityLevel
|
||||
|
@ -155,21 +154,21 @@ func (f receiverFactoryOptionFunc) applyReceiverFactoryOption(o *receiverFactory
|
|||
}
|
||||
|
||||
// ReceiverCreateDefaultConfigFunc is the equivalent of ReceiverFactory.CreateDefaultConfig().
|
||||
type ReceiverCreateDefaultConfigFunc func() config.Receiver
|
||||
type ReceiverCreateDefaultConfigFunc func() ReceiverConfig
|
||||
|
||||
// CreateDefaultConfig implements ReceiverFactory.CreateDefaultConfig().
|
||||
func (f ReceiverCreateDefaultConfigFunc) CreateDefaultConfig() config.Receiver {
|
||||
func (f ReceiverCreateDefaultConfigFunc) CreateDefaultConfig() ReceiverConfig {
|
||||
return f()
|
||||
}
|
||||
|
||||
// CreateTracesReceiverFunc is the equivalent of ReceiverFactory.CreateTracesReceiver().
|
||||
type CreateTracesReceiverFunc func(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Traces) (TracesReceiver, error)
|
||||
type CreateTracesReceiverFunc func(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Traces) (TracesReceiver, error)
|
||||
|
||||
// CreateTracesReceiver implements ReceiverFactory.CreateTracesReceiver().
|
||||
func (f CreateTracesReceiverFunc) CreateTracesReceiver(
|
||||
ctx context.Context,
|
||||
set ReceiverCreateSettings,
|
||||
cfg config.Receiver,
|
||||
cfg ReceiverConfig,
|
||||
nextConsumer consumer.Traces) (TracesReceiver, error) {
|
||||
if f == nil {
|
||||
return nil, ErrDataTypeIsNotSupported
|
||||
|
@ -178,13 +177,13 @@ func (f CreateTracesReceiverFunc) CreateTracesReceiver(
|
|||
}
|
||||
|
||||
// CreateMetricsReceiverFunc is the equivalent of ReceiverFactory.CreateMetricsReceiver().
|
||||
type CreateMetricsReceiverFunc func(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Metrics) (MetricsReceiver, error)
|
||||
type CreateMetricsReceiverFunc func(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Metrics) (MetricsReceiver, error)
|
||||
|
||||
// CreateMetricsReceiver implements ReceiverFactory.CreateMetricsReceiver().
|
||||
func (f CreateMetricsReceiverFunc) CreateMetricsReceiver(
|
||||
ctx context.Context,
|
||||
set ReceiverCreateSettings,
|
||||
cfg config.Receiver,
|
||||
cfg ReceiverConfig,
|
||||
nextConsumer consumer.Metrics,
|
||||
) (MetricsReceiver, error) {
|
||||
if f == nil {
|
||||
|
@ -194,13 +193,13 @@ func (f CreateMetricsReceiverFunc) CreateMetricsReceiver(
|
|||
}
|
||||
|
||||
// CreateLogsReceiverFunc is the equivalent of ReceiverFactory.CreateLogsReceiver().
|
||||
type CreateLogsReceiverFunc func(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Logs) (LogsReceiver, error)
|
||||
type CreateLogsReceiverFunc func(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Logs) (LogsReceiver, error)
|
||||
|
||||
// CreateLogsReceiver implements ReceiverFactory.CreateLogsReceiver().
|
||||
func (f CreateLogsReceiverFunc) CreateLogsReceiver(
|
||||
ctx context.Context,
|
||||
set ReceiverCreateSettings,
|
||||
cfg config.Receiver,
|
||||
cfg ReceiverConfig,
|
||||
nextConsumer consumer.Logs,
|
||||
) (LogsReceiver, error) {
|
||||
if f == nil {
|
||||
|
@ -257,7 +256,7 @@ func WithLogsReceiver(createLogsReceiver CreateLogsReceiverFunc, sl StabilityLev
|
|||
}
|
||||
|
||||
// NewReceiverFactory returns a ReceiverFactory.
|
||||
func NewReceiverFactory(cfgType config.Type, createDefaultConfig ReceiverCreateDefaultConfigFunc, options ...ReceiverFactoryOption) ReceiverFactory {
|
||||
func NewReceiverFactory(cfgType Type, createDefaultConfig ReceiverCreateDefaultConfigFunc, options ...ReceiverFactoryOption) ReceiverFactory {
|
||||
f := &receiverFactory{
|
||||
baseFactory: baseFactory{cfgType: cfgType},
|
||||
ReceiverCreateDefaultConfigFunc: createDefaultConfig,
|
||||
|
|
|
@ -12,57 +12,58 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
package component // import "go.opentelemetry.io/collector/component"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
)
|
||||
|
||||
// Receiver is the configuration of a component.Receiver. Specific extensions must implement
|
||||
// this interface and must embed ReceiverSettings struct or a struct that extends it.
|
||||
type Receiver interface {
|
||||
// ReceiverConfig is the configuration of a component.Receiver. Specific extensions must implement
|
||||
// this interface and must embed ReceiverConfigSettings struct or a struct that extends it.
|
||||
type ReceiverConfig interface {
|
||||
identifiable
|
||||
validatable
|
||||
|
||||
privateConfigReceiver()
|
||||
}
|
||||
|
||||
// UnmarshalReceiver helper function to unmarshal a Receiver config.
|
||||
// UnmarshalReceiverConfig helper function to unmarshal a ReceiverConfig.
|
||||
// It checks if the config implements confmap.Unmarshaler and uses that if available,
|
||||
// otherwise uses Map.UnmarshalExact, erroring if a field is nonexistent.
|
||||
func UnmarshalReceiver(conf *confmap.Conf, cfg Receiver) error {
|
||||
func UnmarshalReceiverConfig(conf *confmap.Conf, cfg ReceiverConfig) error {
|
||||
return unmarshal(conf, cfg)
|
||||
}
|
||||
|
||||
// ReceiverSettings defines common settings for a component.Receiver configuration.
|
||||
// ReceiverConfigSettings defines common settings for a component.Receiver configuration.
|
||||
// Specific receivers can embed this struct and extend it with more fields if needed.
|
||||
//
|
||||
// It is highly recommended to "override" the Validate() function.
|
||||
//
|
||||
// When embedded in the receiver config it must be with `mapstructure:",squash"` tag.
|
||||
type ReceiverSettings struct {
|
||||
id ComponentID `mapstructure:"-"`
|
||||
type ReceiverConfigSettings struct {
|
||||
id ID `mapstructure:"-"`
|
||||
}
|
||||
|
||||
// NewReceiverSettings return a new ReceiverSettings with the given ComponentID.
|
||||
func NewReceiverSettings(id ComponentID) ReceiverSettings {
|
||||
return ReceiverSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
// NewReceiverConfigSettings return a new ReceiverConfigSettings with the given ID.
|
||||
func NewReceiverConfigSettings(id ID) ReceiverConfigSettings {
|
||||
return ReceiverConfigSettings{id: ID{typeVal: id.Type(), nameVal: id.Name()}}
|
||||
}
|
||||
|
||||
var _ Receiver = (*ReceiverSettings)(nil)
|
||||
var _ ReceiverConfig = (*ReceiverConfigSettings)(nil)
|
||||
|
||||
// ID returns the receiver ComponentID.
|
||||
func (rs *ReceiverSettings) ID() ComponentID {
|
||||
// ID returns the receiver ID.
|
||||
func (rs *ReceiverConfigSettings) ID() ID {
|
||||
return rs.id
|
||||
}
|
||||
|
||||
// SetIDName sets the receiver name.
|
||||
func (rs *ReceiverSettings) SetIDName(idName string) {
|
||||
func (rs *ReceiverConfigSettings) SetIDName(idName string) {
|
||||
rs.id.nameVal = idName
|
||||
}
|
||||
|
||||
// Validate validates the configuration and returns an error if invalid.
|
||||
func (rs *ReceiverSettings) Validate() error {
|
||||
func (rs *ReceiverConfigSettings) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rs *ReceiverSettings) privateConfigReceiver() {}
|
||||
func (rs *ReceiverConfigSettings) privateConfigReceiver() {}
|
|
@ -20,16 +20,15 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
func TestNewReceiverFactory(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewReceiverSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewReceiverConfigSettings(NewID(typeStr))
|
||||
factory := NewReceiverFactory(
|
||||
typeStr,
|
||||
func() config.Receiver { return &defaultCfg })
|
||||
func() ReceiverConfig { return &defaultCfg })
|
||||
assert.EqualValues(t, typeStr, factory.Type())
|
||||
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
|
||||
_, err := factory.CreateTracesReceiver(context.Background(), ReceiverCreateSettings{}, &defaultCfg, nil)
|
||||
|
@ -42,10 +41,10 @@ func TestNewReceiverFactory(t *testing.T) {
|
|||
|
||||
func TestNewReceiverFactory_WithOptions(t *testing.T) {
|
||||
const typeStr = "test"
|
||||
defaultCfg := config.NewReceiverSettings(config.NewComponentID(typeStr))
|
||||
defaultCfg := NewReceiverConfigSettings(NewID(typeStr))
|
||||
factory := NewReceiverFactory(
|
||||
typeStr,
|
||||
func() config.Receiver { return &defaultCfg },
|
||||
func() ReceiverConfig { return &defaultCfg },
|
||||
WithTracesReceiver(createTracesReceiver, StabilityLevelDeprecated),
|
||||
WithMetricsReceiver(createMetricsReceiver, StabilityLevelAlpha),
|
||||
WithLogsReceiver(createLogsReceiver, StabilityLevelStable))
|
||||
|
@ -65,14 +64,14 @@ func TestNewReceiverFactory_WithOptions(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func createTracesReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Traces) (TracesReceiver, error) {
|
||||
func createTracesReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Traces) (TracesReceiver, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createMetricsReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Metrics) (MetricsReceiver, error) {
|
||||
func createMetricsReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Metrics) (MetricsReceiver, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func createLogsReceiver(context.Context, ReceiverCreateSettings, config.Receiver, consumer.Logs) (LogsReceiver, error) {
|
||||
func createLogsReceiver(context.Context, ReceiverCreateSettings, ReceiverConfig, consumer.Logs) (LogsReceiver, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -31,12 +30,12 @@ var (
|
|||
// Authentication defines the auth settings for the receiver.
|
||||
type Authentication struct {
|
||||
// AuthenticatorID specifies the name of the extension to use in order to authenticate the incoming data point.
|
||||
AuthenticatorID config.ComponentID `mapstructure:"authenticator"`
|
||||
AuthenticatorID component.ID `mapstructure:"authenticator"`
|
||||
}
|
||||
|
||||
// GetServerAuthenticator attempts to select the appropriate ServerAuthenticator from the list of extensions,
|
||||
// based on the requested extension name. If an authenticator is not found, an error is returned.
|
||||
func (a Authentication) GetServerAuthenticator(extensions map[config.ComponentID]component.Extension) (ServerAuthenticator, error) {
|
||||
func (a Authentication) GetServerAuthenticator(extensions map[component.ID]component.Extension) (ServerAuthenticator, error) {
|
||||
if ext, found := extensions[a.AuthenticatorID]; found {
|
||||
if auth, ok := ext.(ServerAuthenticator); ok {
|
||||
return auth, nil
|
||||
|
@ -50,7 +49,7 @@ func (a Authentication) GetServerAuthenticator(extensions map[config.ComponentID
|
|||
// GetClientAuthenticator attempts to select the appropriate ClientAuthenticator from the list of extensions,
|
||||
// based on the component id of the extension. If an authenticator is not found, an error is returned.
|
||||
// This should be only used by HTTP clients.
|
||||
func (a Authentication) GetClientAuthenticator(extensions map[config.ComponentID]component.Extension) (ClientAuthenticator, error) {
|
||||
func (a Authentication) GetClientAuthenticator(extensions map[component.ID]component.Extension) (ClientAuthenticator, error) {
|
||||
if ext, found := extensions[a.AuthenticatorID]; found {
|
||||
if auth, ok := ext.(ClientAuthenticator); ok {
|
||||
return auth, nil
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
func TestGetServerAuthenticator(t *testing.T) {
|
||||
|
@ -44,10 +43,10 @@ func TestGetServerAuthenticator(t *testing.T) {
|
|||
t.Run(tC.desc, func(t *testing.T) {
|
||||
// prepare
|
||||
cfg := &Authentication{
|
||||
AuthenticatorID: config.NewComponentID("mock"),
|
||||
AuthenticatorID: component.NewID("mock"),
|
||||
}
|
||||
ext := map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): tC.authenticator,
|
||||
ext := map[component.ID]component.Extension{
|
||||
component.NewID("mock"): tC.authenticator,
|
||||
}
|
||||
|
||||
authenticator, err := cfg.GetServerAuthenticator(ext)
|
||||
|
@ -66,10 +65,10 @@ func TestGetServerAuthenticator(t *testing.T) {
|
|||
|
||||
func TestGetServerAuthenticatorFails(t *testing.T) {
|
||||
cfg := &Authentication{
|
||||
AuthenticatorID: config.NewComponentID("does-not-exist"),
|
||||
AuthenticatorID: component.NewID("does-not-exist"),
|
||||
}
|
||||
|
||||
authenticator, err := cfg.GetServerAuthenticator(map[config.ComponentID]component.Extension{})
|
||||
authenticator, err := cfg.GetServerAuthenticator(map[component.ID]component.Extension{})
|
||||
assert.ErrorIs(t, err, errAuthenticatorNotFound)
|
||||
assert.Nil(t, authenticator)
|
||||
}
|
||||
|
@ -95,10 +94,10 @@ func TestGetClientAuthenticator(t *testing.T) {
|
|||
t.Run(tC.desc, func(t *testing.T) {
|
||||
// prepare
|
||||
cfg := &Authentication{
|
||||
AuthenticatorID: config.NewComponentID("mock"),
|
||||
AuthenticatorID: component.NewID("mock"),
|
||||
}
|
||||
ext := map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): tC.authenticator,
|
||||
ext := map[component.ID]component.Extension{
|
||||
component.NewID("mock"): tC.authenticator,
|
||||
}
|
||||
|
||||
authenticator, err := cfg.GetClientAuthenticator(ext)
|
||||
|
@ -117,9 +116,9 @@ func TestGetClientAuthenticator(t *testing.T) {
|
|||
|
||||
func TestGetClientAuthenticatorFails(t *testing.T) {
|
||||
cfg := &Authentication{
|
||||
AuthenticatorID: config.NewComponentID("does-not-exist"),
|
||||
AuthenticatorID: component.NewID("does-not-exist"),
|
||||
}
|
||||
authenticator, err := cfg.GetClientAuthenticator(map[config.ComponentID]component.Extension{})
|
||||
authenticator, err := cfg.GetClientAuthenticator(map[component.ID]component.Extension{})
|
||||
assert.ErrorIs(t, err, errAuthenticatorNotFound)
|
||||
assert.Nil(t, authenticator)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import (
|
|||
"go.opentelemetry.io/collector/client"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configauth"
|
||||
"go.opentelemetry.io/collector/config/configcompression"
|
||||
"go.opentelemetry.io/collector/config/confignet"
|
||||
|
@ -89,11 +88,11 @@ func TestAllGrpcClientSettings(t *testing.T) {
|
|||
WriteBufferSize: 1024,
|
||||
WaitForReady: true,
|
||||
BalancerName: "round_robin",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("testauth")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
|
||||
},
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("testauth"): &configauth.MockClientAuthenticator{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -117,11 +116,11 @@ func TestAllGrpcClientSettings(t *testing.T) {
|
|||
WriteBufferSize: 1024,
|
||||
WaitForReady: true,
|
||||
BalancerName: "round_robin",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("testauth")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
|
||||
},
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("testauth"): &configauth.MockClientAuthenticator{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -145,11 +144,11 @@ func TestAllGrpcClientSettings(t *testing.T) {
|
|||
WriteBufferSize: 1024,
|
||||
WaitForReady: true,
|
||||
BalancerName: "round_robin",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("testauth")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")},
|
||||
},
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("testauth"): &configauth.MockClientAuthenticator{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -214,11 +213,11 @@ func TestGrpcServerAuthSettings(t *testing.T) {
|
|||
},
|
||||
}
|
||||
gss.Auth = &configauth.Authentication{
|
||||
AuthenticatorID: config.NewComponentID("mock"),
|
||||
AuthenticatorID: component.NewID("mock"),
|
||||
}
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): configauth.NewServerAuthenticator(),
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): configauth.NewServerAuthenticator(),
|
||||
},
|
||||
}
|
||||
srv, err := gss.ToServer(host, componenttest.NewNopTelemetrySettings())
|
||||
|
@ -294,15 +293,15 @@ func TestGRPCClientSettingsError(t *testing.T) {
|
|||
err: "failed to resolve authenticator \"doesntexist\": authenticator not found",
|
||||
settings: GRPCClientSettings{
|
||||
Endpoint: "localhost:1234",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("doesntexist")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")},
|
||||
},
|
||||
host: &mockHost{ext: map[config.ComponentID]component.Extension{}},
|
||||
host: &mockHost{ext: map[component.ID]component.Extension{}},
|
||||
},
|
||||
{
|
||||
err: "no extensions configuration available",
|
||||
settings: GRPCClientSettings{
|
||||
Endpoint: "localhost:1234",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("doesntexist")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")},
|
||||
},
|
||||
host: &mockHost{},
|
||||
},
|
||||
|
@ -1076,9 +1075,9 @@ func tempSocketName(t *testing.T) string {
|
|||
|
||||
type mockHost struct {
|
||||
component.Host
|
||||
ext map[config.ComponentID]component.Extension
|
||||
ext map[component.ID]component.Extension
|
||||
}
|
||||
|
||||
func (nh *mockHost) GetExtensions() map[config.ComponentID]component.Extension {
|
||||
func (nh *mockHost) GetExtensions() map[component.ID]component.Extension {
|
||||
return nh.ext
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import (
|
|||
"go.opentelemetry.io/collector/client"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configauth"
|
||||
"go.opentelemetry.io/collector/config/configtls"
|
||||
)
|
||||
|
@ -51,8 +50,8 @@ func (c *customRoundTripper) RoundTrip(request *http.Request) (*http.Response, e
|
|||
|
||||
func TestAllHTTPClientSettings(t *testing.T) {
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -161,8 +160,8 @@ func TestAllHTTPClientSettings(t *testing.T) {
|
|||
|
||||
func TestPartialHTTPClientSettings(t *testing.T) {
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("testauth"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -212,7 +211,7 @@ func TestDefaultHTTPClientSettings(t *testing.T) {
|
|||
|
||||
func TestHTTPClientSettingsError(t *testing.T) {
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{},
|
||||
ext: map[component.ID]component.Extension{},
|
||||
}
|
||||
tests := []struct {
|
||||
settings HTTPClientSettings
|
||||
|
@ -248,7 +247,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
|
|||
err: "failed to resolve authenticator \"dummy\": authenticator not found",
|
||||
settings: HTTPClientSettings{
|
||||
Endpoint: "https://localhost:1234/v1/traces",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("dummy")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -275,8 +274,8 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
|
|||
},
|
||||
shouldErr: false,
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): &configauth.MockClientAuthenticator{
|
||||
ResultRoundTripper: &customRoundTripper{},
|
||||
},
|
||||
},
|
||||
|
@ -286,12 +285,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
|
|||
name: "with_auth_configuration_and_no_extension",
|
||||
settings: HTTPClientSettings{
|
||||
Endpoint: "localhost:1234",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("dummy")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")},
|
||||
},
|
||||
shouldErr: true,
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -299,7 +298,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
|
|||
name: "with_auth_configuration_and_no_extension_map",
|
||||
settings: HTTPClientSettings{
|
||||
Endpoint: "localhost:1234",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("dummy")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")},
|
||||
},
|
||||
shouldErr: true,
|
||||
host: componenttest.NewNopHost(),
|
||||
|
@ -308,12 +307,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
|
|||
name: "with_auth_configuration_has_extension",
|
||||
settings: HTTPClientSettings{
|
||||
Endpoint: "localhost:1234",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("mock")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
|
||||
},
|
||||
shouldErr: false,
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): &configauth.MockClientAuthenticator{ResultRoundTripper: &customRoundTripper{}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -321,12 +320,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
|
|||
name: "with_auth_configuration_has_err_extension",
|
||||
settings: HTTPClientSettings{
|
||||
Endpoint: "localhost:1234",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("mock")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
|
||||
},
|
||||
shouldErr: true,
|
||||
host: &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): &configauth.MockClientAuthenticator{
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): &configauth.MockClientAuthenticator{
|
||||
ResultRoundTripper: &customRoundTripper{}, MustError: true},
|
||||
},
|
||||
},
|
||||
|
@ -733,13 +732,13 @@ func TestHttpCorsWithAuthentication(t *testing.T) {
|
|||
AllowedOrigins: []string{"*"},
|
||||
},
|
||||
Auth: &configauth.Authentication{
|
||||
AuthenticatorID: config.NewComponentID("mock"),
|
||||
AuthenticatorID: component.NewID("mock"),
|
||||
},
|
||||
}
|
||||
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): configauth.NewServerAuthenticator(
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): configauth.NewServerAuthenticator(
|
||||
configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) {
|
||||
return ctx, errors.New("authentication failed")
|
||||
}),
|
||||
|
@ -928,13 +927,13 @@ func TestServerAuth(t *testing.T) {
|
|||
hss := HTTPServerSettings{
|
||||
Endpoint: "localhost:0",
|
||||
Auth: &configauth.Authentication{
|
||||
AuthenticatorID: config.NewComponentID("mock"),
|
||||
AuthenticatorID: component.NewID("mock"),
|
||||
},
|
||||
}
|
||||
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): configauth.NewServerAuthenticator(
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): configauth.NewServerAuthenticator(
|
||||
configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) {
|
||||
authCalled = true
|
||||
return ctx, nil
|
||||
|
@ -962,7 +961,7 @@ func TestServerAuth(t *testing.T) {
|
|||
func TestInvalidServerAuth(t *testing.T) {
|
||||
hss := HTTPServerSettings{
|
||||
Auth: &configauth.Authentication{
|
||||
AuthenticatorID: config.NewComponentID("non-existing"),
|
||||
AuthenticatorID: component.NewID("non-existing"),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -976,12 +975,12 @@ func TestFailedServerAuth(t *testing.T) {
|
|||
hss := HTTPServerSettings{
|
||||
Endpoint: "localhost:0",
|
||||
Auth: &configauth.Authentication{
|
||||
AuthenticatorID: config.NewComponentID("mock"),
|
||||
AuthenticatorID: component.NewID("mock"),
|
||||
},
|
||||
}
|
||||
host := &mockHost{
|
||||
ext: map[config.ComponentID]component.Extension{
|
||||
config.NewComponentID("mock"): configauth.NewServerAuthenticator(
|
||||
ext: map[component.ID]component.Extension{
|
||||
component.NewID("mock"): configauth.NewServerAuthenticator(
|
||||
configauth.WithAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) {
|
||||
return ctx, errors.New("authentication failed")
|
||||
}),
|
||||
|
@ -1003,10 +1002,10 @@ func TestFailedServerAuth(t *testing.T) {
|
|||
|
||||
type mockHost struct {
|
||||
component.Host
|
||||
ext map[config.ComponentID]component.Extension
|
||||
ext map[component.ID]component.Extension
|
||||
}
|
||||
|
||||
func (nh *mockHost) GetExtensions() map[config.ComponentID]component.Extension {
|
||||
func (nh *mockHost) GetExtensions() map[component.ID]component.Extension {
|
||||
return nh.ext
|
||||
}
|
||||
|
||||
|
|
|
@ -15,133 +15,8 @@
|
|||
package configtest // import "go.opentelemetry.io/collector/config/configtest"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
)
|
||||
|
||||
// The regular expression for valid config field tag.
|
||||
var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$")
|
||||
|
||||
// CheckConfigStruct enforces that given configuration object is following the patterns
|
||||
// used by the collector. This ensures consistency between different implementations
|
||||
// of components and extensions. It is recommended for implementers of components
|
||||
// to call this function on their tests passing the default configuration of the
|
||||
// component factory.
|
||||
func CheckConfigStruct(config interface{}) error {
|
||||
t := reflect.TypeOf(config)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
if t.Kind() != reflect.Struct {
|
||||
return fmt.Errorf("config must be a struct or a pointer to one, the passed object is a %s", t.Kind())
|
||||
}
|
||||
|
||||
return validateConfigDataType(t)
|
||||
}
|
||||
|
||||
// validateConfigDataType performs a descending validation of the given type.
|
||||
// If the type is a struct it goes to each of its fields to check for the proper
|
||||
// tags.
|
||||
func validateConfigDataType(t reflect.Type) error {
|
||||
var errs error
|
||||
|
||||
switch t.Kind() {
|
||||
case reflect.Ptr:
|
||||
errs = multierr.Append(errs, validateConfigDataType(t.Elem()))
|
||||
case reflect.Struct:
|
||||
// Reflect on the pointed data and check each of its fields.
|
||||
nf := t.NumField()
|
||||
for i := 0; i < nf; i++ {
|
||||
f := t.Field(i)
|
||||
errs = multierr.Append(errs, checkStructFieldTags(f))
|
||||
}
|
||||
default:
|
||||
// The config object can carry other types but they are not used when
|
||||
// reading the configuration via koanf so ignore them. Basically ignore:
|
||||
// reflect.Uintptr, reflect.Chan, reflect.Func, reflect.Interface, and
|
||||
// reflect.UnsafePointer.
|
||||
}
|
||||
|
||||
if errs != nil {
|
||||
return fmt.Errorf("type %q from package %q has invalid config settings: %w", t.Name(), t.PkgPath(), errs)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkStructFieldTags inspects the tags of a struct field.
|
||||
func checkStructFieldTags(f reflect.StructField) error {
|
||||
|
||||
tagValue := f.Tag.Get("mapstructure")
|
||||
if tagValue == "" {
|
||||
|
||||
// Ignore special types.
|
||||
switch f.Type.Kind() {
|
||||
case reflect.Interface, reflect.Chan, reflect.Func, reflect.Uintptr, reflect.UnsafePointer:
|
||||
// Allow the config to carry the types above, but since they are not read
|
||||
// when loading configuration, just ignore them.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Public fields of other types should be tagged.
|
||||
chars := []byte(f.Name)
|
||||
if len(chars) > 0 && chars[0] >= 'A' && chars[0] <= 'Z' {
|
||||
return fmt.Errorf("mapstructure tag not present on field %q", f.Name)
|
||||
}
|
||||
|
||||
// Not public field, no need to have a tag.
|
||||
return nil
|
||||
}
|
||||
|
||||
tagParts := strings.Split(tagValue, ",")
|
||||
if tagParts[0] != "" {
|
||||
if tagParts[0] == "-" {
|
||||
// Nothing to do, as mapstructure decode skips this field.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check if squash is specified.
|
||||
squash := false
|
||||
for _, tag := range tagParts[1:] {
|
||||
if tag == "squash" {
|
||||
squash = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if squash {
|
||||
// Field was squashed.
|
||||
if (f.Type.Kind() != reflect.Struct) && (f.Type.Kind() != reflect.Ptr || f.Type.Elem().Kind() != reflect.Struct) {
|
||||
return fmt.Errorf(
|
||||
"attempt to squash non-struct type on field %q", f.Name)
|
||||
}
|
||||
}
|
||||
|
||||
switch f.Type.Kind() {
|
||||
case reflect.Struct:
|
||||
// It is another struct, continue down-level.
|
||||
return validateConfigDataType(f.Type)
|
||||
|
||||
case reflect.Map, reflect.Slice, reflect.Array:
|
||||
// The element of map, array, or slice can be itself a configuration object.
|
||||
return validateConfigDataType(f.Type.Elem())
|
||||
|
||||
default:
|
||||
fieldTag := tagParts[0]
|
||||
if !configFieldTagRegExp.MatchString(fieldTag) {
|
||||
return fmt.Errorf(
|
||||
"field %q has config tag %q which doesn't satisfy %q",
|
||||
f.Name,
|
||||
fieldTag,
|
||||
configFieldTagRegExp.String())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
// Deprecated: [v0.64.0] use componenttest.CheckConfigStruct.
|
||||
var CheckConfigStruct = componenttest.CheckConfigStruct
|
||||
|
|
|
@ -15,28 +15,28 @@
|
|||
package config // import "go.opentelemetry.io/collector/config/experimental/config"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
// SourceSettings defines common settings of a Source configuration.
|
||||
// Specific config sources can embed this struct and extend it with more fields if needed.
|
||||
// When embedded it must be with `mapstructure:",squash"` tag.
|
||||
type SourceSettings struct {
|
||||
config.ComponentID `mapstructure:"-"`
|
||||
id component.ID `mapstructure:"-"`
|
||||
}
|
||||
|
||||
// ID returns the ID of the component that this configuration belongs to.
|
||||
func (s *SourceSettings) ID() config.ComponentID {
|
||||
return s.ComponentID
|
||||
func (s *SourceSettings) ID() component.ID {
|
||||
return s.id
|
||||
}
|
||||
|
||||
// SetIDName updates the name part of the ID for the component that this configuration belongs to.
|
||||
func (s *SourceSettings) SetIDName(idName string) {
|
||||
s.ComponentID = config.NewComponentIDWithName(s.ComponentID.Type(), idName)
|
||||
s.id = component.NewIDWithName(s.id.Type(), idName)
|
||||
}
|
||||
|
||||
// NewSourceSettings return a new config.SourceSettings struct with the given ComponentID.
|
||||
func NewSourceSettings(id config.ComponentID) SourceSettings {
|
||||
func NewSourceSettings(id component.ID) SourceSettings {
|
||||
return SourceSettings{id}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ type Source interface {
|
|||
// From config.identifiable:
|
||||
|
||||
// ID returns the ID of the component that this configuration belongs to.
|
||||
ID() config.ComponentID
|
||||
ID() component.ID
|
||||
// SetIDName updates the name part of the ID for the component that this configuration belongs to.
|
||||
SetIDName(idName string)
|
||||
|
||||
|
|
|
@ -14,13 +14,95 @@
|
|||
|
||||
package config // import "go.opentelemetry.io/collector/config"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
// Pipeline defines a single pipeline.
|
||||
// Deprecated: [v0.52.0] Use service.ConfigServicePipeline
|
||||
type Pipeline struct {
|
||||
Receivers []ComponentID `mapstructure:"receivers"`
|
||||
Processors []ComponentID `mapstructure:"processors"`
|
||||
Exporters []ComponentID `mapstructure:"exporters"`
|
||||
Receivers []component.ID `mapstructure:"receivers"`
|
||||
Processors []component.ID `mapstructure:"processors"`
|
||||
Exporters []component.ID `mapstructure:"exporters"`
|
||||
}
|
||||
|
||||
// Deprecated: [v0.52.0] will be removed soon.
|
||||
type Pipelines = map[ComponentID]*Pipeline
|
||||
type Pipelines = map[component.ID]*Pipeline
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ReceiverConfig.
|
||||
type Receiver = component.ReceiverConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.UnmarshalReceiverConfig.
|
||||
var UnmarshalReceiver = component.UnmarshalReceiverConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ReceiverConfigSettings.
|
||||
type ReceiverSettings = component.ReceiverConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.NewReceiverConfigSettings.
|
||||
var NewReceiverSettings = component.NewReceiverConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ProcessorConfig.
|
||||
type Processor = component.ProcessorConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.UnmarshalProcessorConfig.
|
||||
var UnmarshalProcessor = component.UnmarshalProcessorConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ProcessorConfigSettings.
|
||||
type ProcessorSettings = component.ProcessorConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.NewProcessorConfigSettings.
|
||||
var NewProcessorSettings = component.NewProcessorConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ExporterConfig.
|
||||
type Exporter = component.ExporterConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.UnmarshalExporterConfig.
|
||||
var UnmarshalExporter = component.UnmarshalExporterConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ExporterConfigSettings.
|
||||
type ExporterSettings = component.ExporterConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.NewExporterConfigSettings.
|
||||
var NewExporterSettings = component.NewExporterConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ExtensionConfig.
|
||||
type Extension = component.ExtensionConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.UnmarshalExtensionConfig.
|
||||
var UnmarshalExtension = component.UnmarshalExtensionConfig
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ExtensionConfigSettings.
|
||||
type ExtensionSettings = component.ExtensionConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.NewExtensionConfigSettings.
|
||||
var NewExtensionSettings = component.NewExtensionConfigSettings
|
||||
|
||||
// Deprecated: [v0.64.0] use component.Type.
|
||||
type Type = component.Type
|
||||
|
||||
// Deprecated: [v0.64.0] use component.DataType.
|
||||
type DataType = component.DataType
|
||||
|
||||
// Deprecated: [v0.64.0] use component.TracesDataType.
|
||||
const TracesDataType = component.TracesDataType
|
||||
|
||||
// Deprecated: [v0.64.0] use component.MetricsDataType.
|
||||
const MetricsDataType = component.MetricsDataType
|
||||
|
||||
// Deprecated: [v0.64.0] use component.LogsDataType.
|
||||
const LogsDataType = component.LogsDataType
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ID.
|
||||
type ComponentID = component.ID
|
||||
|
||||
// Deprecated: [v0.64.0] use component.NewID.
|
||||
var NewComponentID = component.NewID
|
||||
|
||||
// Deprecated: [v0.64.0] use component.NewIDWithName.
|
||||
var NewComponentIDWithName = component.NewIDWithName
|
||||
|
||||
// Deprecated: [v0.64.0] use component.ID.UnmarshalText.
|
||||
func NewComponentIDFromString(idStr string) (ComponentID, error) {
|
||||
id := component.ID{}
|
||||
return id, id.UnmarshalText([]byte(idStr))
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"time"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
"go.opentelemetry.io/collector/obsreport"
|
||||
|
@ -156,7 +155,7 @@ type baseExporter struct {
|
|||
qrSender *queuedRetrySender
|
||||
}
|
||||
|
||||
func newBaseExporter(cfg config.Exporter, set component.ExporterCreateSettings, bs *baseSettings, signal config.DataType, reqUnmarshaler internal.RequestUnmarshaler) *baseExporter {
|
||||
func newBaseExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings, bs *baseSettings, signal component.DataType, reqUnmarshaler internal.RequestUnmarshaler) *baseExporter {
|
||||
be := &baseExporter{}
|
||||
|
||||
be.obsrep = newObsExporter(obsreport.ExporterSettings{ExporterID: cfg.ID(), ExporterCreateSettings: set}, globalInstruments)
|
||||
|
|
|
@ -25,14 +25,13 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultExporterCfg = config.NewExporterSettings(config.NewComponentID("test"))
|
||||
defaultExporterCfg = component.NewExporterConfigSettings(component.NewID("test"))
|
||||
exporterTag, _ = tag.NewKey("exporter")
|
||||
defaultExporterTags = []tag.Tag{
|
||||
{Key: exporterTag, Value: "test"},
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/extension/experimental/storage"
|
||||
)
|
||||
|
||||
|
@ -37,12 +37,12 @@ type persistentQueue struct {
|
|||
|
||||
// buildPersistentStorageName returns a name that is constructed out of queue name and signal type. This is done
|
||||
// to avoid conflicts between different signals, which require unique persistent storage name
|
||||
func buildPersistentStorageName(name string, signal config.DataType) string {
|
||||
func buildPersistentStorageName(name string, signal component.DataType) string {
|
||||
return fmt.Sprintf("%s-%s", name, signal)
|
||||
}
|
||||
|
||||
// NewPersistentQueue creates a new queue backed by file storage; name and signal must be a unique combination that identifies the queue storage
|
||||
func NewPersistentQueue(ctx context.Context, name string, signal config.DataType, capacity int, logger *zap.Logger, client storage.Client, unmarshaler RequestUnmarshaler) ProducerConsumerQueue {
|
||||
func NewPersistentQueue(ctx context.Context, name string, signal component.DataType, capacity int, logger *zap.Logger, client storage.Client, unmarshaler RequestUnmarshaler) ProducerConsumerQueue {
|
||||
return &persistentQueue{
|
||||
logger: logger,
|
||||
stopChan: make(chan struct{}),
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/extension/experimental/storage"
|
||||
"go.opentelemetry.io/collector/pdata/pcommon"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
|
@ -34,12 +33,12 @@ import (
|
|||
func createTestQueue(extension storage.Extension, capacity int) *persistentQueue {
|
||||
logger := zap.NewNop()
|
||||
|
||||
client, err := extension.GetClient(context.Background(), component.KindReceiver, config.ComponentID{}, "")
|
||||
client, err := extension.GetClient(context.Background(), component.KindReceiver, component.ID{}, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
wq := NewPersistentQueue(context.Background(), "foo", config.TracesDataType, capacity, logger, client, newFakeTracesRequestUnmarshalerFunc())
|
||||
wq := NewPersistentQueue(context.Background(), "foo", component.TracesDataType, capacity, logger, client, newFakeTracesRequestUnmarshalerFunc())
|
||||
return wq.(*persistentQueue)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/extension/experimental/storage"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
)
|
||||
|
@ -38,7 +37,7 @@ func createStorageExtension(_ string) storage.Extension {
|
|||
}
|
||||
|
||||
func createTestClient(extension storage.Extension) storage.Client {
|
||||
client, err := extension.GetClient(context.Background(), component.KindReceiver, config.ComponentID{}, "")
|
||||
client, err := extension.GetClient(context.Background(), component.KindReceiver, component.ID{}, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -459,7 +458,7 @@ func (m mockStorageExtension) Shutdown(_ context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m mockStorageExtension) GetClient(ctx context.Context, kind component.Kind, id config.ComponentID, s string) (storage.Client, error) {
|
||||
func (m mockStorageExtension) GetClient(ctx context.Context, kind component.Kind, id component.ID, s string) (storage.Client, error) {
|
||||
return newMockStorageClient(), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
|
@ -82,7 +81,7 @@ type logsExporter struct {
|
|||
func NewLogsExporter(
|
||||
_ context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
pusher consumer.ConsumeLogsFunc,
|
||||
options ...Option,
|
||||
) (component.LogsExporter, error) {
|
||||
|
@ -99,7 +98,7 @@ func NewLogsExporter(
|
|||
}
|
||||
|
||||
bs := fromOptions(options...)
|
||||
be := newBaseExporter(cfg, set, bs, config.LogsDataType, newLogsRequestUnmarshalerFunc(pusher))
|
||||
be := newBaseExporter(cfg, set, bs, component.LogsDataType, newLogsRequestUnmarshalerFunc(pusher))
|
||||
be.wrapConsumerSender(func(nextSender requestSender) requestSender {
|
||||
return &logsExporterWithObservability{
|
||||
obsrep: be.obsrep,
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
|
||||
|
@ -41,10 +40,10 @@ const (
|
|||
fakeLogsParentSpanName = "fake_logs_parent_span_name"
|
||||
)
|
||||
|
||||
var fakeLogsExporterName = config.NewComponentIDWithName("fake_logs_exporter", "with_name")
|
||||
var fakeLogsExporterName = component.NewIDWithName("fake_logs_exporter", "with_name")
|
||||
|
||||
var (
|
||||
fakeLogsExporterConfig = config.NewExporterSettings(fakeLogsExporterName)
|
||||
fakeLogsExporterConfig = component.NewExporterConfigSettings(fakeLogsExporterName)
|
||||
)
|
||||
|
||||
func TestLogsRequest(t *testing.T) {
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
|
@ -83,7 +82,7 @@ type metricsExporter struct {
|
|||
func NewMetricsExporter(
|
||||
_ context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
pusher consumer.ConsumeMetricsFunc,
|
||||
options ...Option,
|
||||
) (component.MetricsExporter, error) {
|
||||
|
@ -100,7 +99,7 @@ func NewMetricsExporter(
|
|||
}
|
||||
|
||||
bs := fromOptions(options...)
|
||||
be := newBaseExporter(cfg, set, bs, config.MetricsDataType, newMetricsRequestUnmarshalerFunc(pusher))
|
||||
be := newBaseExporter(cfg, set, bs, component.MetricsDataType, newMetricsRequestUnmarshalerFunc(pusher))
|
||||
be.wrapConsumerSender(func(nextSender requestSender) requestSender {
|
||||
return &metricsSenderWithObservability{
|
||||
obsrep: be.obsrep,
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
|
||||
|
@ -42,8 +41,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
fakeMetricsExporterName = config.NewComponentIDWithName("fake_metrics_exporter", "with_name")
|
||||
fakeMetricsExporterConfig = config.NewExporterSettings(fakeMetricsExporterName)
|
||||
fakeMetricsExporterName = component.NewIDWithName("fake_metrics_exporter", "with_name")
|
||||
fakeMetricsExporterConfig = component.NewExporterConfigSettings(fakeMetricsExporterName)
|
||||
)
|
||||
|
||||
func TestMetricsRequest(t *testing.T) {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"go.opencensus.io/metric"
|
||||
"go.opencensus.io/tag"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/obsreport"
|
||||
"go.opentelemetry.io/collector/obsreport/obsreporttest"
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ func TestExportEnqueueFailure(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })
|
||||
|
||||
exporter := config.NewComponentID("fakeExporter")
|
||||
exporter := component.NewID("fakeExporter")
|
||||
|
||||
insts := newInstruments(metric.NewRegistry())
|
||||
obsrep := newObsExporter(obsreport.ExporterSettings{
|
||||
|
@ -55,24 +55,24 @@ func TestExportEnqueueFailure(t *testing.T) {
|
|||
|
||||
// checkExporterEnqueueFailedTracesStats checks that reported number of spans failed to enqueue match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func checkExporterEnqueueFailedTracesStats(t *testing.T, insts *instruments, exporter config.ComponentID, spans int64) {
|
||||
func checkExporterEnqueueFailedTracesStats(t *testing.T, insts *instruments, exporter component.ID, spans int64) {
|
||||
checkValueForProducer(t, insts.registry, tagsForExporterView(exporter), spans, "exporter/enqueue_failed_spans")
|
||||
}
|
||||
|
||||
// checkExporterEnqueueFailedMetricsStats checks that reported number of metric points failed to enqueue match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func checkExporterEnqueueFailedMetricsStats(t *testing.T, insts *instruments, exporter config.ComponentID, metricPoints int64) {
|
||||
func checkExporterEnqueueFailedMetricsStats(t *testing.T, insts *instruments, exporter component.ID, metricPoints int64) {
|
||||
checkValueForProducer(t, insts.registry, tagsForExporterView(exporter), metricPoints, "exporter/enqueue_failed_metric_points")
|
||||
}
|
||||
|
||||
// checkExporterEnqueueFailedLogsStats checks that reported number of log records failed to enqueue match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func checkExporterEnqueueFailedLogsStats(t *testing.T, insts *instruments, exporter config.ComponentID, logRecords int64) {
|
||||
func checkExporterEnqueueFailedLogsStats(t *testing.T, insts *instruments, exporter component.ID, logRecords int64) {
|
||||
checkValueForProducer(t, insts.registry, tagsForExporterView(exporter), logRecords, "exporter/enqueue_failed_log_records")
|
||||
}
|
||||
|
||||
// tagsForExporterView returns the tags that are needed for the exporter views.
|
||||
func tagsForExporterView(exporter config.ComponentID) []tag.Tag {
|
||||
func tagsForExporterView(exporter component.ID) []tag.Tag {
|
||||
return []tag.Tag{
|
||||
{Key: exporterTag, Value: exporter.String()},
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
"go.opentelemetry.io/collector/extension/experimental/storage"
|
||||
|
@ -51,7 +50,7 @@ type QueueSettings struct {
|
|||
QueueSize int `mapstructure:"queue_size"`
|
||||
// StorageID if not empty, enables the persistent storage and uses the component specified
|
||||
// as a storage extension for the persistent queue
|
||||
StorageID *config.ComponentID `mapstructure:"storage"`
|
||||
StorageID *component.ID `mapstructure:"storage"`
|
||||
}
|
||||
|
||||
// NewDefaultQueueSettings returns the default settings for QueueSettings.
|
||||
|
@ -82,8 +81,8 @@ func (qCfg *QueueSettings) Validate() error {
|
|||
|
||||
type queuedRetrySender struct {
|
||||
fullName string
|
||||
id config.ComponentID
|
||||
signal config.DataType
|
||||
id component.ID
|
||||
signal component.DataType
|
||||
cfg QueueSettings
|
||||
consumerSender requestSender
|
||||
queue internal.ProducerConsumerQueue
|
||||
|
@ -94,7 +93,7 @@ type queuedRetrySender struct {
|
|||
requestUnmarshaler internal.RequestUnmarshaler
|
||||
}
|
||||
|
||||
func newQueuedRetrySender(id config.ComponentID, signal config.DataType, qCfg QueueSettings, rCfg RetrySettings, reqUnmarshaler internal.RequestUnmarshaler, nextSender requestSender, logger *zap.Logger) *queuedRetrySender {
|
||||
func newQueuedRetrySender(id component.ID, signal component.DataType, qCfg QueueSettings, rCfg RetrySettings, reqUnmarshaler internal.RequestUnmarshaler, nextSender requestSender, logger *zap.Logger) *queuedRetrySender {
|
||||
retryStopCh := make(chan struct{})
|
||||
sampledLogger := createSampledLogger(logger)
|
||||
traceAttr := attribute.String(obsmetrics.ExporterKey, id.String())
|
||||
|
@ -128,7 +127,7 @@ func newQueuedRetrySender(id config.ComponentID, signal config.DataType, qCfg Qu
|
|||
return qrs
|
||||
}
|
||||
|
||||
func getStorageExtension(extensions map[config.ComponentID]component.Extension, storageID config.ComponentID) (storage.Extension, error) {
|
||||
func getStorageExtension(extensions map[component.ID]component.Extension, storageID component.ID) (storage.Extension, error) {
|
||||
if ext, found := extensions[storageID]; found {
|
||||
if storageExt, ok := ext.(storage.Extension); ok {
|
||||
return storageExt, nil
|
||||
|
@ -138,7 +137,7 @@ func getStorageExtension(extensions map[config.ComponentID]component.Extension,
|
|||
return nil, errNoStorageClient
|
||||
}
|
||||
|
||||
func toStorageClient(ctx context.Context, storageID config.ComponentID, host component.Host, ownerID config.ComponentID, signal config.DataType) (storage.Client, error) {
|
||||
func toStorageClient(ctx context.Context, storageID component.ID, host component.Host, ownerID component.ID, signal component.DataType) (storage.Client, error) {
|
||||
extension, err := getStorageExtension(host.GetExtensions(), storageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -32,7 +32,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
"go.opentelemetry.io/collector/extension/experimental/storage"
|
||||
|
@ -423,17 +422,17 @@ func TestGetRetrySettings(t *testing.T) {
|
|||
|
||||
for _, tC := range testCases {
|
||||
t.Run(tC.desc, func(t *testing.T) {
|
||||
storageID := config.NewComponentIDWithName("file_storage", strconv.Itoa(tC.storageIndex))
|
||||
storageID := component.NewIDWithName("file_storage", strconv.Itoa(tC.storageIndex))
|
||||
|
||||
var extensions = map[config.ComponentID]component.Extension{}
|
||||
var extensions = map[component.ID]component.Extension{}
|
||||
for i := 0; i < tC.numStorages; i++ {
|
||||
extensions[config.NewComponentIDWithName("file_storage", strconv.Itoa(i))] = &mockStorageExtension{GetClientError: tC.getClientError}
|
||||
extensions[component.NewIDWithName("file_storage", strconv.Itoa(i))] = &mockStorageExtension{GetClientError: tC.getClientError}
|
||||
}
|
||||
host := &mockHost{ext: extensions}
|
||||
ownerID := config.NewComponentID("foo_exporter")
|
||||
ownerID := component.NewID("foo_exporter")
|
||||
|
||||
// execute
|
||||
client, err := toStorageClient(context.Background(), storageID, host, ownerID, config.TracesDataType)
|
||||
client, err := toStorageClient(context.Background(), storageID, host, ownerID, component.TracesDataType)
|
||||
|
||||
// verify
|
||||
if tC.expectedError != nil {
|
||||
|
@ -448,7 +447,7 @@ func TestGetRetrySettings(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInvalidStorageExtensionType(t *testing.T) {
|
||||
storageID := config.NewComponentIDWithName("extension", "extension")
|
||||
storageID := component.NewIDWithName("extension", "extension")
|
||||
|
||||
// make a test extension
|
||||
factory := componenttest.NewNopExtensionFactory()
|
||||
|
@ -456,14 +455,14 @@ func TestInvalidStorageExtensionType(t *testing.T) {
|
|||
settings := componenttest.NewNopExtensionCreateSettings()
|
||||
extension, err := factory.CreateExtension(context.Background(), settings, extConfig)
|
||||
assert.NoError(t, err)
|
||||
var extensions = map[config.ComponentID]component.Extension{
|
||||
var extensions = map[component.ID]component.Extension{
|
||||
storageID: extension,
|
||||
}
|
||||
host := &mockHost{ext: extensions}
|
||||
ownerID := config.NewComponentID("foo_exporter")
|
||||
ownerID := component.NewID("foo_exporter")
|
||||
|
||||
// execute
|
||||
client, err := toStorageClient(context.Background(), storageID, host, ownerID, config.TracesDataType)
|
||||
client, err := toStorageClient(context.Background(), storageID, host, ownerID, component.TracesDataType)
|
||||
|
||||
// we should get an error about the extension type
|
||||
assert.ErrorIs(t, err, errWrongExtensionType)
|
||||
|
@ -527,12 +526,12 @@ func TestQueuedRetryPersistenceEnabled(t *testing.T) {
|
|||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })
|
||||
|
||||
qCfg := NewDefaultQueueSettings()
|
||||
storageID := config.NewComponentIDWithName("file_storage", "storage")
|
||||
storageID := component.NewIDWithName("file_storage", "storage")
|
||||
qCfg.StorageID = &storageID // enable persistence
|
||||
rCfg := NewDefaultRetrySettings()
|
||||
be := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
|
||||
|
||||
var extensions = map[config.ComponentID]component.Extension{
|
||||
var extensions = map[component.ID]component.Extension{
|
||||
storageID: &mockStorageExtension{},
|
||||
}
|
||||
host := &mockHost{ext: extensions}
|
||||
|
@ -549,12 +548,12 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) {
|
|||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })
|
||||
|
||||
qCfg := NewDefaultQueueSettings()
|
||||
storageID := config.NewComponentIDWithName("file_storage", "storage")
|
||||
storageID := component.NewIDWithName("file_storage", "storage")
|
||||
qCfg.StorageID = &storageID // enable persistence
|
||||
rCfg := NewDefaultRetrySettings()
|
||||
be := newBaseExporter(&defaultExporterCfg, tt.ToExporterCreateSettings(), fromOptions(WithRetry(rCfg), WithQueue(qCfg)), "", nopRequestUnmarshaler())
|
||||
|
||||
var extensions = map[config.ComponentID]component.Extension{
|
||||
var extensions = map[component.ID]component.Extension{
|
||||
storageID: &mockStorageExtension{GetClientError: storageError},
|
||||
}
|
||||
host := &mockHost{ext: extensions}
|
||||
|
@ -732,10 +731,10 @@ func tagsMatchLabelKeys(tags []tag.Tag, keys []metricdata.LabelKey, labels []met
|
|||
|
||||
type mockHost struct {
|
||||
component.Host
|
||||
ext map[config.ComponentID]component.Extension
|
||||
ext map[component.ID]component.Extension
|
||||
}
|
||||
|
||||
func (nh *mockHost) GetExtensions() map[config.ComponentID]component.Extension {
|
||||
func (nh *mockHost) GetExtensions() map[component.ID]component.Extension {
|
||||
return nh.ext
|
||||
}
|
||||
|
||||
|
@ -751,7 +750,7 @@ func (mse *mockStorageExtension) Shutdown(_ context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (mse *mockStorageExtension) GetClient(_ context.Context, _ component.Kind, _ config.ComponentID, _ string) (storage.Client, error) {
|
||||
func (mse *mockStorageExtension) GetClient(_ context.Context, _ component.Kind, _ component.ID, _ string) (storage.Client, error) {
|
||||
if mse.GetClientError != nil {
|
||||
return nil, mse.GetClientError
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
|
||||
|
@ -83,7 +82,7 @@ type traceExporter struct {
|
|||
func NewTracesExporter(
|
||||
_ context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
pusher consumer.ConsumeTracesFunc,
|
||||
options ...Option,
|
||||
) (component.TracesExporter, error) {
|
||||
|
@ -100,7 +99,7 @@ func NewTracesExporter(
|
|||
}
|
||||
|
||||
bs := fromOptions(options...)
|
||||
be := newBaseExporter(cfg, set, bs, config.TracesDataType, newTraceRequestUnmarshalerFunc(pusher))
|
||||
be := newBaseExporter(cfg, set, bs, component.TracesDataType, newTraceRequestUnmarshalerFunc(pusher))
|
||||
be.wrapConsumerSender(func(nextSender requestSender) requestSender {
|
||||
return &tracesExporterWithObservability{
|
||||
obsrep: be.obsrep,
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
|
||||
|
@ -42,8 +41,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
fakeTracesExporterName = config.NewComponentIDWithName("fake_traces_exporter", "with_name")
|
||||
fakeTracesExporterConfig = config.NewExporterSettings(fakeTracesExporterName)
|
||||
fakeTracesExporterName = component.NewIDWithName("fake_traces_exporter", "with_name")
|
||||
fakeTracesExporterConfig = component.NewExporterConfigSettings(fakeTracesExporterName)
|
||||
)
|
||||
|
||||
func TestTracesRequest(t *testing.T) {
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
)
|
||||
|
@ -36,7 +36,7 @@ var (
|
|||
|
||||
// Config defines configuration for logging exporter.
|
||||
type Config struct {
|
||||
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
|
||||
// LogLevel defines log level of the logging exporter; options are debug, info, warn, error.
|
||||
// Deprecated: Use `Verbosity` instead.
|
||||
|
@ -55,7 +55,7 @@ type Config struct {
|
|||
warnLogLevel bool
|
||||
}
|
||||
|
||||
var _ config.Exporter = (*Config)(nil)
|
||||
var _ component.ExporterConfig = (*Config)(nil)
|
||||
var _ confmap.Unmarshaler = (*Config)(nil)
|
||||
|
||||
func mapLevel(level zapcore.Level) (configtelemetry.Level, error) {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
"go.opentelemetry.io/collector/confmap/confmaptest"
|
||||
|
@ -31,7 +31,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExporter(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
}
|
||||
|
||||
|
@ -44,33 +44,33 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
{
|
||||
filename: "config_loglevel.yaml",
|
||||
cfg: &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
LogLevel: zapcore.DebugLevel,
|
||||
Verbosity: configtelemetry.LevelDetailed,
|
||||
SamplingInitial: 10,
|
||||
SamplingThereafter: 50,
|
||||
warnLogLevel: true,
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
LogLevel: zapcore.DebugLevel,
|
||||
Verbosity: configtelemetry.LevelDetailed,
|
||||
SamplingInitial: 10,
|
||||
SamplingThereafter: 50,
|
||||
warnLogLevel: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
filename: "config_verbosity.yaml",
|
||||
cfg: &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
LogLevel: zapcore.InfoLevel,
|
||||
Verbosity: configtelemetry.LevelDetailed,
|
||||
SamplingInitial: 10,
|
||||
SamplingThereafter: 50,
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
LogLevel: zapcore.InfoLevel,
|
||||
Verbosity: configtelemetry.LevelDetailed,
|
||||
SamplingInitial: 10,
|
||||
SamplingThereafter: 50,
|
||||
},
|
||||
},
|
||||
{
|
||||
filename: "loglevel_info.yaml",
|
||||
cfg: &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
LogLevel: zapcore.InfoLevel,
|
||||
Verbosity: configtelemetry.LevelNormal,
|
||||
SamplingInitial: 2,
|
||||
SamplingThereafter: 500,
|
||||
warnLogLevel: true,
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
LogLevel: zapcore.InfoLevel,
|
||||
Verbosity: configtelemetry.LevelNormal,
|
||||
SamplingInitial: 2,
|
||||
SamplingThereafter: 500,
|
||||
warnLogLevel: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
err = config.UnmarshalExporter(cm, cfg)
|
||||
err = component.UnmarshalExporterConfig(cm, cfg)
|
||||
if tt.expectedErr != "" {
|
||||
assert.EqualError(t, err, tt.expectedErr)
|
||||
} else {
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
||||
|
@ -49,17 +48,17 @@ func NewFactory() component.ExporterFactory {
|
|||
)
|
||||
}
|
||||
|
||||
func createDefaultConfig() config.Exporter {
|
||||
func createDefaultConfig() component.ExporterConfig {
|
||||
return &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
LogLevel: zapcore.InfoLevel,
|
||||
Verbosity: configtelemetry.LevelNormal,
|
||||
SamplingInitial: defaultSamplingInitial,
|
||||
SamplingThereafter: defaultSamplingThereafter,
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
LogLevel: zapcore.InfoLevel,
|
||||
Verbosity: configtelemetry.LevelNormal,
|
||||
SamplingInitial: defaultSamplingInitial,
|
||||
SamplingThereafter: defaultSamplingThereafter,
|
||||
}
|
||||
}
|
||||
|
||||
func createTracesExporter(ctx context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.TracesExporter, error) {
|
||||
func createTracesExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.TracesExporter, error) {
|
||||
cfg := config.(*Config)
|
||||
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
|
||||
s := newLoggingExporter(exporterLogger, cfg.Verbosity)
|
||||
|
@ -74,7 +73,7 @@ func createTracesExporter(ctx context.Context, set component.ExporterCreateSetti
|
|||
)
|
||||
}
|
||||
|
||||
func createMetricsExporter(ctx context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.MetricsExporter, error) {
|
||||
func createMetricsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.MetricsExporter, error) {
|
||||
cfg := config.(*Config)
|
||||
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
|
||||
s := newLoggingExporter(exporterLogger, cfg.Verbosity)
|
||||
|
@ -89,7 +88,7 @@ func createMetricsExporter(ctx context.Context, set component.ExporterCreateSett
|
|||
)
|
||||
}
|
||||
|
||||
func createLogsExporter(ctx context.Context, set component.ExporterCreateSettings, config config.Exporter) (component.LogsExporter, error) {
|
||||
func createLogsExporter(ctx context.Context, set component.ExporterCreateSettings, config component.ExporterConfig) (component.LogsExporter, error) {
|
||||
cfg := config.(*Config)
|
||||
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
|
||||
s := newLoggingExporter(exporterLogger, cfg.Verbosity)
|
||||
|
|
|
@ -21,14 +21,13 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
)
|
||||
|
||||
func TestCreateDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NotNil(t, cfg, "failed to create default config")
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
}
|
||||
|
||||
func TestCreateMetricsExporter(t *testing.T) {
|
||||
|
|
|
@ -17,22 +17,22 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexpor
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/configgrpc"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
||||
)
|
||||
|
||||
// Config defines configuration for OpenCensus exporter.
|
||||
type Config struct {
|
||||
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
||||
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
|
||||
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
|
||||
component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
||||
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
|
||||
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
|
||||
|
||||
configgrpc.GRPCClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
||||
}
|
||||
|
||||
var _ config.Exporter = (*Config)(nil)
|
||||
var _ component.ExporterConfig = (*Config)(nil)
|
||||
|
||||
// Validate checks if the exporter configuration is valid
|
||||
func (cfg *Config) Validate() error {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/configauth"
|
||||
"go.opentelemetry.io/collector/config/configgrpc"
|
||||
"go.opentelemetry.io/collector/config/configtls"
|
||||
|
@ -34,7 +34,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExporter(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,10 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExporter(cm, cfg))
|
||||
assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg))
|
||||
assert.Equal(t,
|
||||
&Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
TimeoutSettings: exporterhelper.TimeoutSettings{
|
||||
Timeout: 10 * time.Second,
|
||||
},
|
||||
|
@ -82,7 +82,7 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
},
|
||||
WriteBufferSize: 512 * 1024,
|
||||
BalancerName: "round_robin",
|
||||
Auth: &configauth.Authentication{AuthenticatorID: config.NewComponentID("nop")},
|
||||
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("nop")},
|
||||
},
|
||||
}, cfg)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configcompression"
|
||||
"go.opentelemetry.io/collector/config/configgrpc"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
|
@ -41,12 +40,12 @@ func NewFactory() component.ExporterFactory {
|
|||
)
|
||||
}
|
||||
|
||||
func createDefaultConfig() config.Exporter {
|
||||
func createDefaultConfig() component.ExporterConfig {
|
||||
return &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
|
||||
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
|
||||
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
TimeoutSettings: exporterhelper.NewDefaultTimeoutSettings(),
|
||||
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
|
||||
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Headers: map[string]string{},
|
||||
// Default to gzip compression
|
||||
|
@ -60,7 +59,7 @@ func createDefaultConfig() config.Exporter {
|
|||
func createTracesExporter(
|
||||
ctx context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
) (component.TracesExporter, error) {
|
||||
oce, err := newExporter(cfg, set)
|
||||
if err != nil {
|
||||
|
@ -80,7 +79,7 @@ func createTracesExporter(
|
|||
func createMetricsExporter(
|
||||
ctx context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
) (component.MetricsExporter, error) {
|
||||
oce, err := newExporter(cfg, set)
|
||||
if err != nil {
|
||||
|
@ -101,7 +100,7 @@ func createMetricsExporter(
|
|||
func createLogsExporter(
|
||||
ctx context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
) (component.LogsExporter, error) {
|
||||
oce, err := newExporter(cfg, set)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,11 +23,10 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configcompression"
|
||||
"go.opentelemetry.io/collector/config/configgrpc"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
"go.opentelemetry.io/collector/config/configtls"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
||||
"go.opentelemetry.io/collector/internal/testutil"
|
||||
|
@ -37,7 +36,7 @@ func TestCreateDefaultConfig(t *testing.T) {
|
|||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NotNil(t, cfg, "failed to create default config")
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
ocfg, ok := factory.CreateDefaultConfig().(*Config)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, ocfg.RetrySettings, exporterhelper.NewDefaultRetrySettings())
|
||||
|
@ -68,7 +67,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "NoEndpoint",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: "",
|
||||
},
|
||||
|
@ -78,7 +77,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "UseSecure",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
TLSSetting: configtls.TLSClientSetting{
|
||||
|
@ -90,7 +89,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "Keepalive",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Keepalive: &configgrpc.KeepaliveClientConfig{
|
||||
|
@ -104,7 +103,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "NoneCompression",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Compression: "none",
|
||||
|
@ -114,7 +113,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "GzipCompression",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Compression: configcompression.Gzip,
|
||||
|
@ -142,7 +141,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "Headers",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Headers: map[string]string{
|
||||
|
@ -155,7 +154,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "NumConsumers",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
},
|
||||
|
@ -164,7 +163,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "CaCert",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
TLSSetting: configtls.TLSClientSetting{
|
||||
|
@ -178,7 +177,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "CertPemFileError",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
GRPCClientSettings: configgrpc.GRPCClientSettings{
|
||||
Endpoint: endpoint,
|
||||
TLSSetting: configtls.TLSClientSetting{
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
||||
"go.opentelemetry.io/collector/pdata/plog"
|
||||
|
@ -59,7 +58,7 @@ type exporter struct {
|
|||
|
||||
// Crete new exporter and start it. The exporter will begin connecting but
|
||||
// this function may return before the connection is established.
|
||||
func newExporter(cfg config.Exporter, set component.ExporterCreateSettings) (*exporter, error) {
|
||||
func newExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings) (*exporter, error) {
|
||||
oCfg := cfg.(*Config)
|
||||
|
||||
if oCfg.Endpoint == "" {
|
||||
|
|
|
@ -17,17 +17,17 @@ package otlphttpexporter // import "go.opentelemetry.io/collector/exporter/otlph
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/confighttp"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
||||
)
|
||||
|
||||
// Config defines configuration for OTLP/HTTP exporter.
|
||||
type Config struct {
|
||||
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
||||
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
|
||||
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
|
||||
component.ExporterConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
||||
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
|
||||
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
|
||||
|
||||
// The URL to send traces to. If omitted the Endpoint + "/v1/traces" will be used.
|
||||
TracesEndpoint string `mapstructure:"traces_endpoint"`
|
||||
|
@ -39,7 +39,7 @@ type Config struct {
|
|||
LogsEndpoint string `mapstructure:"logs_endpoint"`
|
||||
}
|
||||
|
||||
var _ config.Exporter = (*Config)(nil)
|
||||
var _ component.ExporterConfig = (*Config)(nil)
|
||||
|
||||
// Validate checks if the exporter configuration is valid
|
||||
func (cfg *Config) Validate() error {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/confighttp"
|
||||
"go.opentelemetry.io/collector/config/configtls"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
|
@ -33,7 +33,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExporter(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalExporterConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
// Default/Empty config is invalid.
|
||||
assert.Error(t, cfg.Validate())
|
||||
|
@ -44,10 +44,10 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExporter(cm, cfg))
|
||||
assert.NoError(t, component.UnmarshalExporterConfig(cm, cfg))
|
||||
assert.Equal(t,
|
||||
&Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
RetrySettings: exporterhelper.RetrySettings{
|
||||
Enabled: true,
|
||||
InitialInterval: 10 * time.Second,
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"time"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configcompression"
|
||||
"go.opentelemetry.io/collector/config/confighttp"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
|
@ -44,11 +43,11 @@ func NewFactory() component.ExporterFactory {
|
|||
)
|
||||
}
|
||||
|
||||
func createDefaultConfig() config.Exporter {
|
||||
func createDefaultConfig() component.ExporterConfig {
|
||||
return &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
|
||||
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
RetrySettings: exporterhelper.NewDefaultRetrySettings(),
|
||||
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: "",
|
||||
Timeout: 30 * time.Second,
|
||||
|
@ -79,7 +78,7 @@ func composeSignalURL(oCfg *Config, signalOverrideURL string, signalName string)
|
|||
func createTracesExporter(
|
||||
ctx context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
) (component.TracesExporter, error) {
|
||||
oce, err := newExporter(cfg, set)
|
||||
if err != nil {
|
||||
|
@ -105,7 +104,7 @@ func createTracesExporter(
|
|||
func createMetricsExporter(
|
||||
ctx context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
) (component.MetricsExporter, error) {
|
||||
oce, err := newExporter(cfg, set)
|
||||
if err != nil {
|
||||
|
@ -131,7 +130,7 @@ func createMetricsExporter(
|
|||
func createLogsExporter(
|
||||
ctx context.Context,
|
||||
set component.ExporterCreateSettings,
|
||||
cfg config.Exporter,
|
||||
cfg component.ExporterConfig,
|
||||
) (component.LogsExporter, error) {
|
||||
oce, err := newExporter(cfg, set)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,11 +23,10 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configcompression"
|
||||
"go.opentelemetry.io/collector/config/confighttp"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
"go.opentelemetry.io/collector/config/configtls"
|
||||
"go.opentelemetry.io/collector/internal/testutil"
|
||||
)
|
||||
|
@ -36,7 +35,7 @@ func TestCreateDefaultConfig(t *testing.T) {
|
|||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NotNil(t, cfg, "failed to create default config")
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
ocfg, ok := factory.CreateDefaultConfig().(*Config)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, ocfg.HTTPClientSettings.Endpoint, "")
|
||||
|
@ -72,7 +71,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "NoEndpoint",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: "",
|
||||
},
|
||||
|
@ -82,7 +81,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "UseSecure",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
TLSSetting: configtls.TLSClientSetting{
|
||||
|
@ -94,7 +93,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "Headers",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Headers: map[string]string{
|
||||
|
@ -107,7 +106,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "CaCert",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
TLSSetting: configtls.TLSClientSetting{
|
||||
|
@ -121,7 +120,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "CertPemFileError",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
TLSSetting: configtls.TLSClientSetting{
|
||||
|
@ -137,7 +136,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "NoneCompression",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Compression: "none",
|
||||
|
@ -147,7 +146,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "GzipCompression",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Compression: configcompression.Gzip,
|
||||
|
@ -157,7 +156,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "SnappyCompression",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Compression: configcompression.Snappy,
|
||||
|
@ -167,7 +166,7 @@ func TestCreateTracesExporter(t *testing.T) {
|
|||
{
|
||||
name: "ZstdCompression",
|
||||
config: Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Endpoint: endpoint,
|
||||
Compression: configcompression.Zstd,
|
||||
|
|
|
@ -31,7 +31,6 @@ import (
|
|||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
||||
"go.opentelemetry.io/collector/pdata/plog"
|
||||
|
@ -61,7 +60,7 @@ const (
|
|||
)
|
||||
|
||||
// Create new exporter.
|
||||
func newExporter(cfg config.Exporter, set component.ExporterCreateSettings) (*exporter, error) {
|
||||
func newExporter(cfg component.ExporterConfig, set component.ExporterCreateSettings) (*exporter, error) {
|
||||
oCfg := cfg.(*Config)
|
||||
|
||||
if oCfg.Endpoint != "" {
|
||||
|
|
|
@ -37,7 +37,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/confighttp"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumererror"
|
||||
|
@ -328,7 +327,7 @@ func startLogsExporter(t *testing.T, baseURL string, overrideURL string) compone
|
|||
return exp
|
||||
}
|
||||
|
||||
func createExporterConfig(baseURL string, defaultCfg config.Exporter) *Config {
|
||||
func createExporterConfig(baseURL string, defaultCfg component.ExporterConfig) *Config {
|
||||
cfg := defaultCfg.(*Config)
|
||||
cfg.Endpoint = baseURL
|
||||
cfg.QueueSettings.Enabled = false
|
||||
|
@ -360,7 +359,7 @@ func startLogsReceiver(t *testing.T, addr string, next consumer.Logs) {
|
|||
startAndCleanup(t, recv)
|
||||
}
|
||||
|
||||
func createReceiverConfig(addr string, defaultCfg config.Receiver) *otlpreceiver.Config {
|
||||
func createReceiverConfig(addr string, defaultCfg component.ReceiverConfig) *otlpreceiver.Config {
|
||||
cfg := defaultCfg.(*otlpreceiver.Config)
|
||||
cfg.HTTP.Endpoint = addr
|
||||
cfg.GRPC = nil
|
||||
|
@ -481,8 +480,8 @@ func TestErrorResponses(t *testing.T) {
|
|||
}()
|
||||
|
||||
cfg := &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr),
|
||||
// Create without QueueSettings and RetrySettings so that ConsumeTraces
|
||||
// returns the errors that we want to check immediately.
|
||||
}
|
||||
|
@ -558,8 +557,8 @@ func TestUserAgent(t *testing.T) {
|
|||
}()
|
||||
|
||||
cfg := &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
TracesEndpoint: fmt.Sprintf("http://%s/v1/traces", addr),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Headers: test.headers,
|
||||
},
|
||||
|
@ -603,8 +602,8 @@ func TestUserAgent(t *testing.T) {
|
|||
}()
|
||||
|
||||
cfg := &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
MetricsEndpoint: fmt.Sprintf("http://%s/v1/metrics", addr),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
MetricsEndpoint: fmt.Sprintf("http://%s/v1/metrics", addr),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Headers: test.headers,
|
||||
},
|
||||
|
@ -648,8 +647,8 @@ func TestUserAgent(t *testing.T) {
|
|||
}()
|
||||
|
||||
cfg := &Config{
|
||||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
|
||||
LogsEndpoint: fmt.Sprintf("http://%s/v1/logs", addr),
|
||||
ExporterConfigSettings: component.NewExporterConfigSettings(component.NewID(typeStr)),
|
||||
LogsEndpoint: fmt.Sprintf("http://%s/v1/logs", addr),
|
||||
HTTPClientSettings: confighttp.HTTPClientSettings{
|
||||
Headers: test.headers,
|
||||
},
|
||||
|
|
|
@ -17,12 +17,12 @@ package ballastextension // import "go.opentelemetry.io/collector/extension/ball
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
// Config has the configuration for the ballast extension.
|
||||
type Config struct {
|
||||
config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
|
||||
// SizeMiB is the size, in MiB, of the memory ballast
|
||||
// to be created for this process.
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
"go.opentelemetry.io/collector/confmap/confmaptest"
|
||||
)
|
||||
|
@ -29,7 +29,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExtension(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalExtensionConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
}
|
||||
|
||||
|
@ -38,12 +38,12 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExtension(cm, cfg))
|
||||
assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg))
|
||||
assert.Equal(t,
|
||||
&Config{
|
||||
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)),
|
||||
SizeMiB: 123,
|
||||
SizeInPercentage: 20,
|
||||
ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)),
|
||||
SizeMiB: 123,
|
||||
SizeInPercentage: 20,
|
||||
}, cfg)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/internal/iruntime"
|
||||
)
|
||||
|
||||
|
@ -35,12 +34,12 @@ func NewFactory() component.ExtensionFactory {
|
|||
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
|
||||
}
|
||||
|
||||
func createDefaultConfig() config.Extension {
|
||||
func createDefaultConfig() component.ExtensionConfig {
|
||||
return &Config{
|
||||
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)),
|
||||
ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)),
|
||||
}
|
||||
}
|
||||
|
||||
func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg config.Extension) (component.Extension, error) {
|
||||
func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) {
|
||||
return newMemoryBallast(cfg.(*Config), set.Logger, memHandler), nil
|
||||
}
|
||||
|
|
|
@ -21,16 +21,15 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
)
|
||||
|
||||
func TestFactory_CreateDefaultConfig(t *testing.T) {
|
||||
cfg := createDefaultConfig()
|
||||
assert.Equal(t, &Config{ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr))}, cfg)
|
||||
assert.Equal(t, &Config{ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr))}, cfg)
|
||||
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ext)
|
||||
|
|
|
@ -6,7 +6,7 @@ A storage extension persists state beyond the collector process. Other component
|
|||
|
||||
The `storage.Extension` interface extends `component.Extension` by adding the following method:
|
||||
```
|
||||
GetClient(context.Context, component.Kind, config.ComponentID, string) (Client, error)
|
||||
GetClient(context.Context, component.Kind, component.ID, string) (Client, error)
|
||||
```
|
||||
|
||||
The `storage.Client` interface contains the following methods:
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
// Extension is the interface that storage extensions must implement
|
||||
|
@ -29,7 +28,7 @@ type Extension interface {
|
|||
// Each component can have multiple storages (e.g. one for each signal),
|
||||
// which can be identified using storageName parameter.
|
||||
// The component can use the client to manage state
|
||||
GetClient(ctx context.Context, kind component.Kind, id config.ComponentID, storageName string) (Client, error)
|
||||
GetClient(ctx context.Context, kind component.Kind, id component.ID, storageName string) (Client, error)
|
||||
}
|
||||
|
||||
// Client is the interface that storage clients must implement
|
||||
|
|
|
@ -17,13 +17,13 @@ package zpagesextension // import "go.opentelemetry.io/collector/extension/zpage
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/confignet"
|
||||
)
|
||||
|
||||
// Config has the configuration for the extension enabling the zPages extension.
|
||||
type Config struct {
|
||||
config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ExtensionConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
|
||||
// TCPAddr is the address and port in which the zPages will be listening to.
|
||||
// Use localhost:<port> to make it available only locally, or ":<port>" to
|
||||
|
@ -31,7 +31,7 @@ type Config struct {
|
|||
TCPAddr confignet.TCPAddr `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
var _ config.Extension = (*Config)(nil)
|
||||
var _ component.ExtensionConfig = (*Config)(nil)
|
||||
|
||||
// Validate checks if the extension configuration is valid
|
||||
func (cfg *Config) Validate() error {
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config/confignet"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
"go.opentelemetry.io/collector/confmap/confmaptest"
|
||||
|
@ -30,7 +30,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExtension(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalExtensionConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,10 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalExtension(cm, cfg))
|
||||
assert.NoError(t, component.UnmarshalExtensionConfig(cm, cfg))
|
||||
assert.Equal(t,
|
||||
&Config{
|
||||
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)),
|
||||
ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)),
|
||||
TCPAddr: confignet.TCPAddr{
|
||||
Endpoint: "localhost:56888",
|
||||
},
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/confignet"
|
||||
)
|
||||
|
||||
|
@ -34,9 +33,9 @@ func NewFactory() component.ExtensionFactory {
|
|||
return component.NewExtensionFactory(typeStr, createDefaultConfig, createExtension, component.StabilityLevelBeta)
|
||||
}
|
||||
|
||||
func createDefaultConfig() config.Extension {
|
||||
func createDefaultConfig() component.ExtensionConfig {
|
||||
return &Config{
|
||||
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)),
|
||||
ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)),
|
||||
TCPAddr: confignet.TCPAddr{
|
||||
Endpoint: defaultEndpoint,
|
||||
},
|
||||
|
@ -44,6 +43,6 @@ func createDefaultConfig() config.Extension {
|
|||
}
|
||||
|
||||
// createExtension creates the extension based on this config.
|
||||
func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg config.Extension) (component.Extension, error) {
|
||||
func createExtension(_ context.Context, set component.ExtensionCreateSettings, cfg component.ExtensionConfig) (component.Extension, error) {
|
||||
return newServer(cfg.(*Config), set.TelemetrySettings), nil
|
||||
}
|
||||
|
|
|
@ -21,24 +21,23 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/confignet"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
"go.opentelemetry.io/collector/internal/testutil"
|
||||
)
|
||||
|
||||
func TestFactory_CreateDefaultConfig(t *testing.T) {
|
||||
cfg := createDefaultConfig()
|
||||
assert.Equal(t, &Config{
|
||||
ExtensionSettings: config.NewExtensionSettings(config.NewComponentID(typeStr)),
|
||||
ExtensionConfigSettings: component.NewExtensionConfigSettings(component.NewID(typeStr)),
|
||||
TCPAddr: confignet.TCPAddr{
|
||||
Endpoint: "localhost:55679",
|
||||
},
|
||||
},
|
||||
cfg)
|
||||
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
ext, err := createExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ext)
|
||||
|
|
|
@ -23,10 +23,9 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
)
|
||||
|
||||
var id = config.NewComponentID("test")
|
||||
var id = component.NewID("test")
|
||||
|
||||
type baseComponent struct {
|
||||
component.StartFunc
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/featuregate"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig"
|
||||
|
@ -61,7 +60,7 @@ type Exporter struct {
|
|||
|
||||
// ExporterSettings are settings for creating an Exporter.
|
||||
type ExporterSettings struct {
|
||||
ExporterID config.ComponentID
|
||||
ExporterID component.ID
|
||||
ExporterCreateSettings component.ExporterCreateSettings
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"go.opencensus.io/tag"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
|
||||
)
|
||||
|
@ -49,7 +48,7 @@ type Processor struct {
|
|||
|
||||
// ProcessorSettings are settings for creating a Processor.
|
||||
type ProcessorSettings struct {
|
||||
ProcessorID config.ComponentID
|
||||
ProcessorID component.ID
|
||||
ProcessorCreateSettings component.ProcessorCreateSettings
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/featuregate"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig"
|
||||
|
@ -66,7 +65,7 @@ type Receiver struct {
|
|||
|
||||
// ReceiverSettings are settings for creating an Receiver.
|
||||
type ReceiverSettings struct {
|
||||
ReceiverID config.ComponentID
|
||||
ReceiverID component.ID
|
||||
Transport string
|
||||
// LongLivedCtx when true indicates that the context passed in the call
|
||||
// outlives the individual receive operation.
|
||||
|
@ -191,7 +190,7 @@ func (rec *Receiver) EndTracesOp(
|
|||
numReceivedSpans int,
|
||||
err error,
|
||||
) {
|
||||
rec.endOp(receiverCtx, format, numReceivedSpans, err, config.TracesDataType)
|
||||
rec.endOp(receiverCtx, format, numReceivedSpans, err, component.TracesDataType)
|
||||
}
|
||||
|
||||
// StartLogsOp is called when a request is received from a client.
|
||||
|
@ -209,7 +208,7 @@ func (rec *Receiver) EndLogsOp(
|
|||
numReceivedLogRecords int,
|
||||
err error,
|
||||
) {
|
||||
rec.endOp(receiverCtx, format, numReceivedLogRecords, err, config.LogsDataType)
|
||||
rec.endOp(receiverCtx, format, numReceivedLogRecords, err, component.LogsDataType)
|
||||
}
|
||||
|
||||
// StartMetricsOp is called when a request is received from a client.
|
||||
|
@ -227,7 +226,7 @@ func (rec *Receiver) EndMetricsOp(
|
|||
numReceivedPoints int,
|
||||
err error,
|
||||
) {
|
||||
rec.endOp(receiverCtx, format, numReceivedPoints, err, config.MetricsDataType)
|
||||
rec.endOp(receiverCtx, format, numReceivedPoints, err, component.MetricsDataType)
|
||||
}
|
||||
|
||||
// startOp creates the span used to trace the operation. Returning
|
||||
|
@ -261,7 +260,7 @@ func (rec *Receiver) endOp(
|
|||
format string,
|
||||
numReceivedItems int,
|
||||
err error,
|
||||
dataType config.DataType,
|
||||
dataType component.DataType,
|
||||
) {
|
||||
numAccepted := numReceivedItems
|
||||
numRefused := 0
|
||||
|
@ -280,13 +279,13 @@ func (rec *Receiver) endOp(
|
|||
if span.IsRecording() {
|
||||
var acceptedItemsKey, refusedItemsKey string
|
||||
switch dataType {
|
||||
case config.TracesDataType:
|
||||
case component.TracesDataType:
|
||||
acceptedItemsKey = obsmetrics.AcceptedSpansKey
|
||||
refusedItemsKey = obsmetrics.RefusedSpansKey
|
||||
case config.MetricsDataType:
|
||||
case component.MetricsDataType:
|
||||
acceptedItemsKey = obsmetrics.AcceptedMetricPointsKey
|
||||
refusedItemsKey = obsmetrics.RefusedMetricPointsKey
|
||||
case config.LogsDataType:
|
||||
case component.LogsDataType:
|
||||
acceptedItemsKey = obsmetrics.AcceptedLogRecordsKey
|
||||
refusedItemsKey = obsmetrics.RefusedLogRecordsKey
|
||||
}
|
||||
|
@ -301,7 +300,7 @@ func (rec *Receiver) endOp(
|
|||
span.End()
|
||||
}
|
||||
|
||||
func (rec *Receiver) recordMetrics(receiverCtx context.Context, dataType config.DataType, numAccepted, numRefused int) {
|
||||
func (rec *Receiver) recordMetrics(receiverCtx context.Context, dataType component.DataType, numAccepted, numRefused int) {
|
||||
if rec.useOtelForMetrics {
|
||||
rec.recordWithOtel(receiverCtx, dataType, numAccepted, numRefused)
|
||||
} else {
|
||||
|
@ -309,16 +308,16 @@ func (rec *Receiver) recordMetrics(receiverCtx context.Context, dataType config.
|
|||
}
|
||||
}
|
||||
|
||||
func (rec *Receiver) recordWithOtel(receiverCtx context.Context, dataType config.DataType, numAccepted, numRefused int) {
|
||||
func (rec *Receiver) recordWithOtel(receiverCtx context.Context, dataType component.DataType, numAccepted, numRefused int) {
|
||||
var acceptedMeasure, refusedMeasure syncint64.Counter
|
||||
switch dataType {
|
||||
case config.TracesDataType:
|
||||
case component.TracesDataType:
|
||||
acceptedMeasure = rec.acceptedSpansCounter
|
||||
refusedMeasure = rec.refusedSpansCounter
|
||||
case config.MetricsDataType:
|
||||
case component.MetricsDataType:
|
||||
acceptedMeasure = rec.acceptedMetricPointsCounter
|
||||
refusedMeasure = rec.refusedMetricPointsCounter
|
||||
case config.LogsDataType:
|
||||
case component.LogsDataType:
|
||||
acceptedMeasure = rec.acceptedLogRecordsCounter
|
||||
refusedMeasure = rec.refusedLogRecordsCounter
|
||||
}
|
||||
|
@ -327,16 +326,16 @@ func (rec *Receiver) recordWithOtel(receiverCtx context.Context, dataType config
|
|||
refusedMeasure.Add(receiverCtx, int64(numRefused), rec.otelAttrs...)
|
||||
}
|
||||
|
||||
func (rec *Receiver) recordWithOC(receiverCtx context.Context, dataType config.DataType, numAccepted, numRefused int) {
|
||||
func (rec *Receiver) recordWithOC(receiverCtx context.Context, dataType component.DataType, numAccepted, numRefused int) {
|
||||
var acceptedMeasure, refusedMeasure *stats.Int64Measure
|
||||
switch dataType {
|
||||
case config.TracesDataType:
|
||||
case component.TracesDataType:
|
||||
acceptedMeasure = obsmetrics.ReceiverAcceptedSpans
|
||||
refusedMeasure = obsmetrics.ReceiverRefusedSpans
|
||||
case config.MetricsDataType:
|
||||
case component.MetricsDataType:
|
||||
acceptedMeasure = obsmetrics.ReceiverAcceptedMetricPoints
|
||||
refusedMeasure = obsmetrics.ReceiverRefusedMetricPoints
|
||||
case config.LogsDataType:
|
||||
case component.LogsDataType:
|
||||
acceptedMeasure = obsmetrics.ReceiverAcceptedLogRecords
|
||||
refusedMeasure = obsmetrics.ReceiverRefusedLogRecords
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
|
||||
"go.opentelemetry.io/collector/receiver/scrapererror"
|
||||
|
@ -33,16 +32,16 @@ import (
|
|||
// Scraper is a helper to add observability to a component.Scraper.
|
||||
type Scraper struct {
|
||||
level configtelemetry.Level
|
||||
receiverID config.ComponentID
|
||||
scraper config.ComponentID
|
||||
receiverID component.ID
|
||||
scraper component.ID
|
||||
mutators []tag.Mutator
|
||||
tracer trace.Tracer
|
||||
}
|
||||
|
||||
// ScraperSettings are settings for creating a Scraper.
|
||||
type ScraperSettings struct {
|
||||
ReceiverID config.ComponentID
|
||||
Scraper config.ComponentID
|
||||
ReceiverID component.ID
|
||||
Scraper component.ID
|
||||
ReceiverCreateSettings component.ReceiverCreateSettings
|
||||
}
|
||||
|
||||
|
@ -103,7 +102,7 @@ func (s *Scraper) EndMetricsOp(
|
|||
// end span according to errors
|
||||
if span.IsRecording() {
|
||||
span.SetAttributes(
|
||||
attribute.String(obsmetrics.FormatKey, string(config.MetricsDataType)),
|
||||
attribute.String(obsmetrics.FormatKey, string(component.MetricsDataType)),
|
||||
attribute.Int64(obsmetrics.ScrapedMetricPointsKey, int64(numScrapedMetrics)),
|
||||
attribute.Int64(obsmetrics.ErroredMetricPointsKey, int64(numErroredMetrics)),
|
||||
)
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/featuregate"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig/obsmetrics"
|
||||
|
@ -38,10 +38,10 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
receiver = config.NewComponentID("fakeReceiver")
|
||||
scraper = config.NewComponentID("fakeScraper")
|
||||
processor = config.NewComponentID("fakeProcessor")
|
||||
exporter = config.NewComponentID("fakeExporter")
|
||||
receiver = component.NewID("fakeReceiver")
|
||||
scraper = component.NewID("fakeScraper")
|
||||
processor = component.NewID("fakeProcessor")
|
||||
exporter = component.NewID("fakeExporter")
|
||||
|
||||
errFake = errors.New("errFake")
|
||||
partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1)
|
||||
|
|
|
@ -33,7 +33,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/internal/obsreportconfig"
|
||||
)
|
||||
|
@ -140,25 +139,25 @@ func SetupTelemetry() (TestTelemetry, error) {
|
|||
|
||||
// CheckExporterTraces checks that for the current exported values for trace exporter metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckExporterTraces(tts TestTelemetry, exporter config.ComponentID, sentSpans, sendFailedSpans int64) error {
|
||||
func CheckExporterTraces(tts TestTelemetry, exporter component.ID, sentSpans, sendFailedSpans int64) error {
|
||||
return tts.otelPrometheusChecker.checkExporterTraces(exporter, sentSpans, sendFailedSpans)
|
||||
}
|
||||
|
||||
// CheckExporterMetrics checks that for the current exported values for metrics exporter metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckExporterMetrics(tts TestTelemetry, exporter config.ComponentID, sentMetricsPoints, sendFailedMetricsPoints int64) error {
|
||||
func CheckExporterMetrics(tts TestTelemetry, exporter component.ID, sentMetricsPoints, sendFailedMetricsPoints int64) error {
|
||||
return tts.otelPrometheusChecker.checkExporterMetrics(exporter, sentMetricsPoints, sendFailedMetricsPoints)
|
||||
}
|
||||
|
||||
// CheckExporterLogs checks that for the current exported values for logs exporter metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckExporterLogs(tts TestTelemetry, exporter config.ComponentID, sentLogRecords, sendFailedLogRecords int64) error {
|
||||
func CheckExporterLogs(tts TestTelemetry, exporter component.ID, sentLogRecords, sendFailedLogRecords int64) error {
|
||||
return tts.otelPrometheusChecker.checkExporterLogs(exporter, sentLogRecords, sendFailedLogRecords)
|
||||
}
|
||||
|
||||
// CheckProcessorTraces checks that for the current exported values for trace exporter metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckProcessorTraces(_ TestTelemetry, processor config.ComponentID, acceptedSpans, refusedSpans, droppedSpans int64) error {
|
||||
func CheckProcessorTraces(_ TestTelemetry, processor component.ID, acceptedSpans, refusedSpans, droppedSpans int64) error {
|
||||
processorTags := tagsForProcessorView(processor)
|
||||
return multierr.Combine(
|
||||
checkValueForView(processorTags, acceptedSpans, "processor/accepted_spans"),
|
||||
|
@ -168,7 +167,7 @@ func CheckProcessorTraces(_ TestTelemetry, processor config.ComponentID, accepte
|
|||
|
||||
// CheckProcessorMetrics checks that for the current exported values for metrics exporter metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckProcessorMetrics(_ TestTelemetry, processor config.ComponentID, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error {
|
||||
func CheckProcessorMetrics(_ TestTelemetry, processor component.ID, acceptedMetricPoints, refusedMetricPoints, droppedMetricPoints int64) error {
|
||||
processorTags := tagsForProcessorView(processor)
|
||||
return multierr.Combine(
|
||||
checkValueForView(processorTags, acceptedMetricPoints, "processor/accepted_metric_points"),
|
||||
|
@ -178,7 +177,7 @@ func CheckProcessorMetrics(_ TestTelemetry, processor config.ComponentID, accept
|
|||
|
||||
// CheckProcessorLogs checks that for the current exported values for logs exporter metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckProcessorLogs(_ TestTelemetry, processor config.ComponentID, acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error {
|
||||
func CheckProcessorLogs(_ TestTelemetry, processor component.ID, acceptedLogRecords, refusedLogRecords, droppedLogRecords int64) error {
|
||||
processorTags := tagsForProcessorView(processor)
|
||||
return multierr.Combine(
|
||||
checkValueForView(processorTags, acceptedLogRecords, "processor/accepted_log_records"),
|
||||
|
@ -188,25 +187,25 @@ func CheckProcessorLogs(_ TestTelemetry, processor config.ComponentID, acceptedL
|
|||
|
||||
// CheckReceiverTraces checks that for the current exported values for trace receiver metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckReceiverTraces(tts TestTelemetry, receiver config.ComponentID, protocol string, acceptedSpans, droppedSpans int64) error {
|
||||
func CheckReceiverTraces(tts TestTelemetry, receiver component.ID, protocol string, acceptedSpans, droppedSpans int64) error {
|
||||
return tts.otelPrometheusChecker.checkReceiverTraces(receiver, protocol, acceptedSpans, droppedSpans)
|
||||
}
|
||||
|
||||
// CheckReceiverLogs checks that for the current exported values for logs receiver metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckReceiverLogs(tts TestTelemetry, receiver config.ComponentID, protocol string, acceptedLogRecords, droppedLogRecords int64) error {
|
||||
func CheckReceiverLogs(tts TestTelemetry, receiver component.ID, protocol string, acceptedLogRecords, droppedLogRecords int64) error {
|
||||
return tts.otelPrometheusChecker.checkReceiverLogs(receiver, protocol, acceptedLogRecords, droppedLogRecords)
|
||||
}
|
||||
|
||||
// CheckReceiverMetrics checks that for the current exported values for metrics receiver metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckReceiverMetrics(tts TestTelemetry, receiver config.ComponentID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
|
||||
func CheckReceiverMetrics(tts TestTelemetry, receiver component.ID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
|
||||
return tts.otelPrometheusChecker.checkReceiverMetrics(receiver, protocol, acceptedMetricPoints, droppedMetricPoints)
|
||||
}
|
||||
|
||||
// CheckScraperMetrics checks that for the current exported values for metrics scraper metrics match given values.
|
||||
// When this function is called it is required to also call SetupTelemetry as first thing.
|
||||
func CheckScraperMetrics(_ TestTelemetry, receiver config.ComponentID, scraper config.ComponentID, scrapedMetricPoints, erroredMetricPoints int64) error {
|
||||
func CheckScraperMetrics(_ TestTelemetry, receiver component.ID, scraper component.ID, scrapedMetricPoints, erroredMetricPoints int64) error {
|
||||
scraperTags := tagsForScraperView(receiver, scraper)
|
||||
return multierr.Combine(
|
||||
checkValueForView(scraperTags, scrapedMetricPoints, "scraper/scraped_metric_points"),
|
||||
|
@ -239,7 +238,7 @@ func checkValueForView(wantTags []tag.Tag, value int64, vName string) error {
|
|||
}
|
||||
|
||||
// tagsForScraperView returns the tags that are needed for the scraper views.
|
||||
func tagsForScraperView(receiver config.ComponentID, scraper config.ComponentID) []tag.Tag {
|
||||
func tagsForScraperView(receiver component.ID, scraper component.ID) []tag.Tag {
|
||||
return []tag.Tag{
|
||||
{Key: receiverTag, Value: receiver.String()},
|
||||
{Key: scraperTag, Value: scraper.String()},
|
||||
|
@ -247,7 +246,7 @@ func tagsForScraperView(receiver config.ComponentID, scraper config.ComponentID)
|
|||
}
|
||||
|
||||
// tagsForProcessorView returns the tags that are needed for the processor views.
|
||||
func tagsForProcessorView(processor config.ComponentID) []tag.Tag {
|
||||
func tagsForProcessorView(processor component.ID) []tag.Tag {
|
||||
return []tag.Tag{
|
||||
{Key: processorTag, Value: processor.String()},
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/obsreport"
|
||||
"go.opentelemetry.io/collector/obsreport/obsreporttest"
|
||||
)
|
||||
|
@ -32,8 +32,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
receiver = config.NewComponentID("fakeReicever")
|
||||
exporter = config.NewComponentID("fakeExporter")
|
||||
receiver = component.NewID("fakeReicever")
|
||||
exporter = component.NewID("fakeExporter")
|
||||
)
|
||||
|
||||
func TestCheckReceiverTracesViews(t *testing.T) {
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
// prometheusChecker is used to assert exported metrics from a prometheus handler.
|
||||
|
@ -34,21 +34,21 @@ type prometheusChecker struct {
|
|||
promHandler http.Handler
|
||||
}
|
||||
|
||||
func (pc *prometheusChecker) checkReceiverTraces(receiver config.ComponentID, protocol string, acceptedSpans, droppedSpans int64) error {
|
||||
func (pc *prometheusChecker) checkReceiverTraces(receiver component.ID, protocol string, acceptedSpans, droppedSpans int64) error {
|
||||
receiverAttrs := attributesForReceiverMetrics(receiver, protocol)
|
||||
return multierr.Combine(
|
||||
pc.checkCounter("receiver_accepted_spans", acceptedSpans, receiverAttrs),
|
||||
pc.checkCounter("receiver_refused_spans", droppedSpans, receiverAttrs))
|
||||
}
|
||||
|
||||
func (pc *prometheusChecker) checkReceiverLogs(receiver config.ComponentID, protocol string, acceptedLogRecords, droppedLogRecords int64) error {
|
||||
func (pc *prometheusChecker) checkReceiverLogs(receiver component.ID, protocol string, acceptedLogRecords, droppedLogRecords int64) error {
|
||||
receiverAttrs := attributesForReceiverMetrics(receiver, protocol)
|
||||
return multierr.Combine(
|
||||
pc.checkCounter("receiver_accepted_log_records", acceptedLogRecords, receiverAttrs),
|
||||
pc.checkCounter("receiver_refused_log_records", droppedLogRecords, receiverAttrs))
|
||||
}
|
||||
|
||||
func (pc *prometheusChecker) checkReceiverMetrics(receiver config.ComponentID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
|
||||
func (pc *prometheusChecker) checkReceiverMetrics(receiver component.ID, protocol string, acceptedMetricPoints, droppedMetricPoints int64) error {
|
||||
receiverAttrs := attributesForReceiverMetrics(receiver, protocol)
|
||||
return multierr.Combine(
|
||||
pc.checkCounter("receiver_accepted_metric_points", acceptedMetricPoints, receiverAttrs),
|
||||
|
@ -146,7 +146,7 @@ func fetchPrometheusMetrics(handler http.Handler) (map[string]*io_prometheus_cli
|
|||
}
|
||||
|
||||
// attributesForReceiverMetrics returns the attributes that are needed for the receiver metrics.
|
||||
func attributesForReceiverMetrics(receiver config.ComponentID, transport string) []attribute.KeyValue {
|
||||
func attributesForReceiverMetrics(receiver component.ID, transport string) []attribute.KeyValue {
|
||||
return []attribute.KeyValue{
|
||||
attribute.String(receiverTag.Name(), receiver.String()),
|
||||
attribute.String(transportTag.Name(), transport),
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
func newStubPromChecker() (prometheusChecker, error) {
|
||||
|
@ -47,8 +47,8 @@ func TestPromChecker(t *testing.T) {
|
|||
pc, err := newStubPromChecker()
|
||||
require.NoError(t, err)
|
||||
|
||||
receiver := config.NewComponentID("fakeReceiver")
|
||||
exporter := config.NewComponentID("fakeExporter")
|
||||
receiver := component.NewID("fakeReceiver")
|
||||
exporter := component.NewID("fakeExporter")
|
||||
transport := "fakeTransport"
|
||||
|
||||
assert.NoError(t,
|
||||
|
|
|
@ -26,8 +26,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
"go.opencensus.io/stats/view"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
|
@ -285,9 +285,9 @@ func TestBatchProcessorSentByTimeout(t *testing.T) {
|
|||
|
||||
func TestBatchProcessorTraceSendWhenClosing(t *testing.T) {
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 3 * time.Second,
|
||||
SendBatchSize: 1000,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 3 * time.Second,
|
||||
SendBatchSize: 1000,
|
||||
}
|
||||
sink := new(consumertest.TracesSink)
|
||||
|
||||
|
@ -313,9 +313,9 @@ func TestBatchMetricProcessor_ReceivingData(t *testing.T) {
|
|||
// Instantiate the batch processor with low config values to test data
|
||||
// gets sent through the processor.
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 200 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 200 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
}
|
||||
|
||||
requestCount := 100
|
||||
|
@ -367,9 +367,9 @@ func TestBatchMetricProcessor_BatchSize(t *testing.T) {
|
|||
// Instantiate the batch processor with low config values to test data
|
||||
// gets sent through the processor.
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
}
|
||||
|
||||
requestCount := 100
|
||||
|
@ -446,9 +446,9 @@ func TestBatchMetrics_UnevenBatchMaxSize(t *testing.T) {
|
|||
|
||||
func TestBatchMetricsProcessor_Timeout(t *testing.T) {
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 101,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 101,
|
||||
}
|
||||
requestCount := 5
|
||||
metricsPerRequest := 10
|
||||
|
@ -495,9 +495,9 @@ func TestBatchMetricsProcessor_Timeout(t *testing.T) {
|
|||
|
||||
func TestBatchMetricProcessor_Shutdown(t *testing.T) {
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 3 * time.Second,
|
||||
SendBatchSize: 1000,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 3 * time.Second,
|
||||
SendBatchSize: 1000,
|
||||
}
|
||||
requestCount := 5
|
||||
metricsPerRequest := 10
|
||||
|
@ -581,9 +581,9 @@ func BenchmarkTraceSizeSpanCount(b *testing.B) {
|
|||
func BenchmarkBatchMetricProcessor(b *testing.B) {
|
||||
b.StopTimer()
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 2000,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 2000,
|
||||
}
|
||||
ctx := context.Background()
|
||||
sink := new(metricsSink)
|
||||
|
@ -631,9 +631,9 @@ func TestBatchLogProcessor_ReceivingData(t *testing.T) {
|
|||
// Instantiate the batch processor with low config values to test data
|
||||
// gets sent through the processor.
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 200 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 200 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
}
|
||||
|
||||
requestCount := 100
|
||||
|
@ -685,9 +685,9 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) {
|
|||
// Instantiate the batch processor with low config values to test data
|
||||
// gets sent through the processor.
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 50,
|
||||
}
|
||||
|
||||
requestCount := 100
|
||||
|
@ -743,9 +743,9 @@ func TestBatchLogProcessor_BatchSize(t *testing.T) {
|
|||
|
||||
func TestBatchLogsProcessor_Timeout(t *testing.T) {
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 100,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 100 * time.Millisecond,
|
||||
SendBatchSize: 100,
|
||||
}
|
||||
requestCount := 5
|
||||
logsPerRequest := 10
|
||||
|
@ -792,9 +792,9 @@ func TestBatchLogsProcessor_Timeout(t *testing.T) {
|
|||
|
||||
func TestBatchLogProcessor_Shutdown(t *testing.T) {
|
||||
cfg := Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
Timeout: 3 * time.Second,
|
||||
SendBatchSize: 1000,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
Timeout: 3 * time.Second,
|
||||
SendBatchSize: 1000,
|
||||
}
|
||||
requestCount := 5
|
||||
logsPerRequest := 10
|
||||
|
|
|
@ -18,12 +18,12 @@ import (
|
|||
"errors"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
// Config defines configuration for batch processor.
|
||||
type Config struct {
|
||||
config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
|
||||
// Timeout sets the time after which a batch will be sent regardless of size.
|
||||
Timeout time.Duration `mapstructure:"timeout"`
|
||||
|
@ -37,7 +37,7 @@ type Config struct {
|
|||
SendBatchMaxSize uint32 `mapstructure:"send_batch_max_size"`
|
||||
}
|
||||
|
||||
var _ config.Processor = (*Config)(nil)
|
||||
var _ component.ProcessorConfig = (*Config)(nil)
|
||||
|
||||
// Validate checks if the processor configuration is valid
|
||||
func (cfg *Config) Validate() error {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
"go.opentelemetry.io/collector/confmap/confmaptest"
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalProcessor(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalProcessorConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
}
|
||||
|
||||
|
@ -39,30 +39,30 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalProcessor(cm, cfg))
|
||||
assert.NoError(t, component.UnmarshalProcessorConfig(cm, cfg))
|
||||
assert.Equal(t,
|
||||
&Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
SendBatchSize: uint32(10000),
|
||||
SendBatchMaxSize: uint32(11000),
|
||||
Timeout: time.Second * 10,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
SendBatchSize: uint32(10000),
|
||||
SendBatchMaxSize: uint32(11000),
|
||||
Timeout: time.Second * 10,
|
||||
}, cfg)
|
||||
}
|
||||
|
||||
func TestValidateConfig_DefaultBatchMaxSize(t *testing.T) {
|
||||
cfg := &Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")),
|
||||
SendBatchSize: 100,
|
||||
SendBatchMaxSize: 0,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")),
|
||||
SendBatchSize: 100,
|
||||
SendBatchMaxSize: 0,
|
||||
}
|
||||
assert.NoError(t, cfg.Validate())
|
||||
}
|
||||
|
||||
func TestValidateConfig_ValidBatchSizes(t *testing.T) {
|
||||
cfg := &Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")),
|
||||
SendBatchSize: 100,
|
||||
SendBatchMaxSize: 1000,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")),
|
||||
SendBatchSize: 100,
|
||||
SendBatchMaxSize: 1000,
|
||||
}
|
||||
assert.NoError(t, cfg.Validate())
|
||||
|
||||
|
@ -70,9 +70,9 @@ func TestValidateConfig_ValidBatchSizes(t *testing.T) {
|
|||
|
||||
func TestValidateConfig_InvalidBatchSize(t *testing.T) {
|
||||
cfg := &Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentIDWithName(typeStr, "2")),
|
||||
SendBatchSize: 1000,
|
||||
SendBatchMaxSize: 100,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewIDWithName(typeStr, "2")),
|
||||
SendBatchSize: 1000,
|
||||
SendBatchMaxSize: 100,
|
||||
}
|
||||
assert.Error(t, cfg.Validate())
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"time"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
)
|
||||
|
||||
|
@ -41,18 +40,18 @@ func NewFactory() component.ProcessorFactory {
|
|||
component.WithLogsProcessor(createLogsProcessor, component.StabilityLevelStable))
|
||||
}
|
||||
|
||||
func createDefaultConfig() config.Processor {
|
||||
func createDefaultConfig() component.ProcessorConfig {
|
||||
return &Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
SendBatchSize: defaultSendBatchSize,
|
||||
Timeout: defaultTimeout,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
SendBatchSize: defaultSendBatchSize,
|
||||
Timeout: defaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
func createTracesProcessor(
|
||||
_ context.Context,
|
||||
set component.ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg component.ProcessorConfig,
|
||||
nextConsumer consumer.Traces,
|
||||
) (component.TracesProcessor, error) {
|
||||
level := set.MetricsLevel
|
||||
|
@ -62,7 +61,7 @@ func createTracesProcessor(
|
|||
func createMetricsProcessor(
|
||||
_ context.Context,
|
||||
set component.ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg component.ProcessorConfig,
|
||||
nextConsumer consumer.Metrics,
|
||||
) (component.MetricsProcessor, error) {
|
||||
level := set.MetricsLevel
|
||||
|
@ -72,7 +71,7 @@ func createMetricsProcessor(
|
|||
func createLogsProcessor(
|
||||
_ context.Context,
|
||||
set component.ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg component.ProcessorConfig,
|
||||
nextConsumer consumer.Logs,
|
||||
) (component.LogsProcessor, error) {
|
||||
level := set.MetricsLevel
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
)
|
||||
|
||||
func TestCreateDefaultConfig(t *testing.T) {
|
||||
|
@ -29,7 +28,7 @@ func TestCreateDefaultConfig(t *testing.T) {
|
|||
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NotNil(t, cfg, "failed to create default config")
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
}
|
||||
|
||||
func TestCreateProcessor(t *testing.T) {
|
||||
|
|
|
@ -20,12 +20,12 @@ package memorylimiterprocessor // import "go.opentelemetry.io/collector/processo
|
|||
import (
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
)
|
||||
|
||||
// Config defines configuration for memory memoryLimiter processor.
|
||||
type Config struct {
|
||||
config.ProcessorSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
component.ProcessorConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
|
||||
|
||||
// CheckInterval is the time between measurements of memory usage for the
|
||||
// purposes of avoiding going over the limits. Defaults to zero, so no
|
||||
|
@ -49,7 +49,7 @@ type Config struct {
|
|||
MemorySpikePercentage uint32 `mapstructure:"spike_limit_percentage"`
|
||||
}
|
||||
|
||||
var _ config.Processor = (*Config)(nil)
|
||||
var _ component.ProcessorConfig = (*Config)(nil)
|
||||
|
||||
// Validate checks if the processor configuration is valid
|
||||
func (cfg *Config) Validate() error {
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/confmap"
|
||||
"go.opentelemetry.io/collector/confmap/confmaptest"
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ import (
|
|||
func TestUnmarshalDefaultConfig(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalProcessor(confmap.New(), cfg))
|
||||
assert.NoError(t, component.UnmarshalProcessorConfig(confmap.New(), cfg))
|
||||
assert.Equal(t, factory.CreateDefaultConfig(), cfg)
|
||||
}
|
||||
|
||||
|
@ -39,12 +39,12 @@ func TestUnmarshalConfig(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NoError(t, config.UnmarshalProcessor(cm, cfg))
|
||||
assert.NoError(t, component.UnmarshalProcessorConfig(cm, cfg))
|
||||
assert.Equal(t,
|
||||
&Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
CheckInterval: 5 * time.Second,
|
||||
MemoryLimitMiB: 4000,
|
||||
MemorySpikeLimitMiB: 500,
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
CheckInterval: 5 * time.Second,
|
||||
MemoryLimitMiB: 4000,
|
||||
MemorySpikeLimitMiB: 500,
|
||||
}, cfg)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"sync"
|
||||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/processor/processorhelper"
|
||||
)
|
||||
|
@ -34,14 +33,14 @@ var processorCapabilities = consumer.Capabilities{MutatesData: false}
|
|||
type factory struct {
|
||||
// memoryLimiters stores memoryLimiter instances with unique configs that multiple processors can reuse.
|
||||
// This avoids running multiple memory checks (ie: GC) for every processor using the same processor config.
|
||||
memoryLimiters map[config.Processor]*memoryLimiter
|
||||
memoryLimiters map[component.ProcessorConfig]*memoryLimiter
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
// NewFactory returns a new factory for the Memory Limiter processor.
|
||||
func NewFactory() component.ProcessorFactory {
|
||||
f := &factory{
|
||||
memoryLimiters: map[config.Processor]*memoryLimiter{},
|
||||
memoryLimiters: map[component.ProcessorConfig]*memoryLimiter{},
|
||||
}
|
||||
return component.NewProcessorFactory(
|
||||
typeStr,
|
||||
|
@ -53,16 +52,16 @@ func NewFactory() component.ProcessorFactory {
|
|||
|
||||
// CreateDefaultConfig creates the default configuration for processor. Notice
|
||||
// that the default configuration is expected to fail for this processor.
|
||||
func createDefaultConfig() config.Processor {
|
||||
func createDefaultConfig() component.ProcessorConfig {
|
||||
return &Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *factory) createTracesProcessor(
|
||||
ctx context.Context,
|
||||
set component.ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg component.ProcessorConfig,
|
||||
nextConsumer consumer.Traces,
|
||||
) (component.TracesProcessor, error) {
|
||||
memLimiter, err := f.getMemoryLimiter(set, cfg)
|
||||
|
@ -79,7 +78,7 @@ func (f *factory) createTracesProcessor(
|
|||
func (f *factory) createMetricsProcessor(
|
||||
ctx context.Context,
|
||||
set component.ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg component.ProcessorConfig,
|
||||
nextConsumer consumer.Metrics,
|
||||
) (component.MetricsProcessor, error) {
|
||||
memLimiter, err := f.getMemoryLimiter(set, cfg)
|
||||
|
@ -96,7 +95,7 @@ func (f *factory) createMetricsProcessor(
|
|||
func (f *factory) createLogsProcessor(
|
||||
ctx context.Context,
|
||||
set component.ProcessorCreateSettings,
|
||||
cfg config.Processor,
|
||||
cfg component.ProcessorConfig,
|
||||
nextConsumer consumer.Logs,
|
||||
) (component.LogsProcessor, error) {
|
||||
memLimiter, err := f.getMemoryLimiter(set, cfg)
|
||||
|
@ -112,7 +111,7 @@ func (f *factory) createLogsProcessor(
|
|||
|
||||
// getMemoryLimiter checks if we have a cached memoryLimiter with a specific config,
|
||||
// otherwise initialize and add one to the store.
|
||||
func (f *factory) getMemoryLimiter(set component.ProcessorCreateSettings, cfg config.Processor) (*memoryLimiter, error) {
|
||||
func (f *factory) getMemoryLimiter(set component.ProcessorCreateSettings, cfg component.ProcessorConfig) (*memoryLimiter, error) {
|
||||
f.lock.Lock()
|
||||
defer f.lock.Unlock()
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config/configtest"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
)
|
||||
|
||||
|
@ -33,7 +32,7 @@ func TestCreateDefaultConfig(t *testing.T) {
|
|||
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
assert.NotNil(t, cfg, "failed to create default config")
|
||||
assert.NoError(t, configtest.CheckConfigStruct(cfg))
|
||||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
}
|
||||
|
||||
func TestCreateProcessor(t *testing.T) {
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
|
||||
"go.opentelemetry.io/collector/component"
|
||||
"go.opentelemetry.io/collector/component/componenttest"
|
||||
"go.opentelemetry.io/collector/config"
|
||||
"go.opentelemetry.io/collector/config/configtelemetry"
|
||||
"go.opentelemetry.io/collector/consumer"
|
||||
"go.opentelemetry.io/collector/consumer/consumertest"
|
||||
|
@ -123,7 +122,7 @@ func TestMetricsMemoryPressureResponse(t *testing.T) {
|
|||
context.Background(),
|
||||
componenttest.NewNopProcessorCreateSettings(),
|
||||
&Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
},
|
||||
consumertest.NewNop(),
|
||||
ml.processMetrics,
|
||||
|
@ -194,7 +193,7 @@ func TestTraceMemoryPressureResponse(t *testing.T) {
|
|||
context.Background(),
|
||||
componenttest.NewNopProcessorCreateSettings(),
|
||||
&Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
},
|
||||
consumertest.NewNop(),
|
||||
ml.processTraces,
|
||||
|
@ -265,7 +264,7 @@ func TestLogMemoryPressureResponse(t *testing.T) {
|
|||
context.Background(),
|
||||
componenttest.NewNopProcessorCreateSettings(),
|
||||
&Config{
|
||||
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
|
||||
ProcessorConfigSettings: component.NewProcessorConfigSettings(component.NewID(typeStr)),
|
||||
},
|
||||
consumertest.NewNop(),
|
||||
ml.processLogs,
|
||||
|
@ -448,7 +447,7 @@ func (be *ballastExtension) GetBallastSize() uint64 {
|
|||
|
||||
func newObsReport() *obsreport.Processor {
|
||||
set := obsreport.ProcessorSettings{
|
||||
ProcessorID: config.NewComponentID(typeStr),
|
||||
ProcessorID: component.NewID(typeStr),
|
||||
ProcessorCreateSettings: componenttest.NewNopProcessorCreateSettings(),
|
||||
}
|
||||
set.ProcessorCreateSettings.MetricsLevel = configtelemetry.LevelNone
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue