Deprecate funcs that repeate extension in name (#11413)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
13134b6017
commit
9701538c89
|
|
@ -0,0 +1,27 @@
|
|||
# Use this changelog template to create an entry for release notes.
|
||||
|
||||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
|
||||
change_type: deprecation
|
||||
|
||||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
|
||||
component: extension
|
||||
|
||||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
|
||||
note: Deprecate funcs that repeat extension in name
|
||||
|
||||
# One or more tracking issues or pull requests related to the change
|
||||
issues: [11413]
|
||||
|
||||
# (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: |
|
||||
Factory.CreateExtension -> Factory.Create |
|
||||
Factory.ExtensionStability -> Factory.Stability
|
||||
|
||||
# Optional: The change log or logs in which this entry should be included.
|
||||
# e.g. '[user]' or '[user, api]'
|
||||
# Include 'user' if the change is relevant to end users.
|
||||
# Include 'api' if there is a change to a library API.
|
||||
# Default: '[user]'
|
||||
change_logs: [api]
|
||||
|
|
@ -338,7 +338,7 @@ func TestComponentLifecycle(t *testing.T) {
|
|||
|
||||
{{- if not .Tests.SkipShutdown }}
|
||||
t.Run("shutdown", func(t *testing.T) {
|
||||
e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
e, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
err = e.Shutdown(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
|
@ -347,12 +347,12 @@ func TestComponentLifecycle(t *testing.T) {
|
|||
|
||||
{{- if not .Tests.SkipLifecycle }}
|
||||
t.Run("lifecycle", func(t *testing.T) {
|
||||
firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
firstExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, firstExt.Start(context.Background(), {{ .Tests.Host }}))
|
||||
require.NoError(t, firstExt.Shutdown(context.Background()))
|
||||
|
||||
secondExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
secondExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, secondExt.Start(context.Background(), {{ .Tests.Host }}))
|
||||
require.NoError(t, secondExt.Shutdown(context.Background()))
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ func TestInvalidStorageExtensionType(t *testing.T) {
|
|||
factory := extensiontest.NewNopFactory()
|
||||
extConfig := factory.CreateDefaultConfig()
|
||||
settings := extensiontest.NewNopSettings()
|
||||
extension, err := factory.CreateExtension(context.Background(), settings, extConfig)
|
||||
extension, err := factory.Create(context.Background(), settings, extConfig)
|
||||
require.NoError(t, err)
|
||||
var extensions = map[component.ID]component.Component{
|
||||
storageID: extension,
|
||||
|
|
|
|||
|
|
@ -41,18 +41,29 @@ type Settings struct {
|
|||
// CreateFunc is the equivalent of Factory.Create(...) function.
|
||||
type CreateFunc func(context.Context, Settings, component.Config) (Extension, error)
|
||||
|
||||
// CreateExtension implements Factory.Create.
|
||||
func (f CreateFunc) CreateExtension(ctx context.Context, set Settings, cfg component.Config) (Extension, error) {
|
||||
// Create implements Factory.Create.
|
||||
func (f CreateFunc) Create(ctx context.Context, set Settings, cfg component.Config) (Extension, error) {
|
||||
return f(ctx, set, cfg)
|
||||
}
|
||||
|
||||
// Deprecated: [v0.112.0] use Create.
|
||||
func (f CreateFunc) CreateExtension(ctx context.Context, set Settings, cfg component.Config) (Extension, error) {
|
||||
return f.Create(ctx, set, cfg)
|
||||
}
|
||||
|
||||
type Factory interface {
|
||||
component.Factory
|
||||
|
||||
// CreateExtension creates an extension based on the given config.
|
||||
// Create an extension based on the given config.
|
||||
Create(ctx context.Context, set Settings, cfg component.Config) (Extension, error)
|
||||
|
||||
// Deprecated: [v0.112.0] use Create.
|
||||
CreateExtension(ctx context.Context, set Settings, cfg component.Config) (Extension, error)
|
||||
|
||||
// ExtensionStability gets the stability level of the Extension.
|
||||
// Stability gets the stability level of the Extension.
|
||||
Stability() component.StabilityLevel
|
||||
|
||||
// Deprecated: [v0.112.0] use Stability.
|
||||
ExtensionStability() component.StabilityLevel
|
||||
|
||||
unexportedFactoryFunc()
|
||||
|
|
@ -71,6 +82,10 @@ func (f *factory) Type() component.Type {
|
|||
|
||||
func (f *factory) unexportedFactoryFunc() {}
|
||||
|
||||
func (f *factory) Stability() component.StabilityLevel {
|
||||
return f.extensionStability
|
||||
}
|
||||
|
||||
func (f *factory) ExtensionStability() component.StabilityLevel {
|
||||
return f.extensionStability
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ func TestNewFactory(t *testing.T) {
|
|||
assert.EqualValues(t, testType, factory.Type())
|
||||
assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
|
||||
|
||||
assert.Equal(t, component.StabilityLevelDevelopment, factory.ExtensionStability())
|
||||
ext, err := factory.CreateExtension(context.Background(), Settings{}, &defaultCfg)
|
||||
assert.Equal(t, component.StabilityLevelDevelopment, factory.Stability())
|
||||
ext, err := factory.Create(context.Background(), Settings{}, &defaultCfg)
|
||||
require.NoError(t, err)
|
||||
assert.Same(t, nopExtensionInstance, ext)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func TestNewNopFactory(t *testing.T) {
|
|||
cfg := factory.CreateDefaultConfig()
|
||||
assert.Equal(t, &nopConfig{}, cfg)
|
||||
|
||||
traces, err := factory.CreateExtension(context.Background(), NewNopSettings(), cfg)
|
||||
traces, err := factory.Create(context.Background(), NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost()))
|
||||
assert.NoError(t, traces.Shutdown(context.Background()))
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func NewFactory() extension.Factory {
|
|||
return extension.NewFactory(
|
||||
metadata.Type,
|
||||
createDefaultConfig,
|
||||
createExtension,
|
||||
create,
|
||||
metadata.ExtensionStability)
|
||||
}
|
||||
|
||||
|
|
@ -28,6 +28,6 @@ func createDefaultConfig() component.Config {
|
|||
return &Config{}
|
||||
}
|
||||
|
||||
func createExtension(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
|
||||
func create(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
|
||||
return newMemoryLimiter(cfg.(*Config), set.TelemetrySettings.Logger)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func TestCreateDefaultConfig(t *testing.T) {
|
|||
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
}
|
||||
|
||||
func TestCreateExtension(t *testing.T) {
|
||||
func TestCreate(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
require.NotNil(t, factory)
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ func TestCreateExtension(t *testing.T) {
|
|||
pCfg.MemorySpikeLimitMiB = 1907
|
||||
pCfg.CheckInterval = 100 * time.Millisecond
|
||||
|
||||
tp, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
tp, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, tp)
|
||||
// test if we can shutdown a monitoring routine that has not started
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ func TestComponentLifecycle(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.NoError(t, sub.Unmarshal(&cfg))
|
||||
t.Run("lifecycle", func(t *testing.T) {
|
||||
firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
firstExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, firstExt.Start(context.Background(), componenttest.NewNopHost()))
|
||||
require.NoError(t, firstExt.Shutdown(context.Background()))
|
||||
|
||||
secondExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
secondExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, secondExt.Start(context.Background(), componenttest.NewNopHost()))
|
||||
require.NoError(t, secondExt.Shutdown(context.Background()))
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const (
|
|||
|
||||
// NewFactory creates a factory for Z-Pages extension.
|
||||
func NewFactory() extension.Factory {
|
||||
return extension.NewFactory(metadata.Type, createDefaultConfig, createExtension, metadata.ExtensionStability)
|
||||
return extension.NewFactory(metadata.Type, createDefaultConfig, create, metadata.ExtensionStability)
|
||||
}
|
||||
|
||||
func createDefaultConfig() component.Config {
|
||||
|
|
@ -29,7 +29,7 @@ func createDefaultConfig() component.Config {
|
|||
}
|
||||
}
|
||||
|
||||
// createExtension creates the extension based on this config.
|
||||
func createExtension(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
|
||||
// create creates the extension based on this config.
|
||||
func create(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
|
||||
return newServer(cfg.(*Config), set.TelemetrySettings), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,16 +26,16 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
|
|||
cfg)
|
||||
|
||||
require.NoError(t, componenttest.CheckConfigStruct(cfg))
|
||||
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
ext, err := create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ext)
|
||||
}
|
||||
|
||||
func TestFactory_CreateExtension(t *testing.T) {
|
||||
func TestFactoryCreate(t *testing.T) {
|
||||
cfg := createDefaultConfig().(*Config)
|
||||
cfg.ServerConfig.Endpoint = testutil.GetAvailableLocalAddress(t)
|
||||
|
||||
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
ext, err := create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ext)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,18 +31,18 @@ func TestComponentLifecycle(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.NoError(t, sub.Unmarshal(&cfg))
|
||||
t.Run("shutdown", func(t *testing.T) {
|
||||
e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
e, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
err = e.Shutdown(context.Background())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("lifecycle", func(t *testing.T) {
|
||||
firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
firstExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, firstExt.Start(context.Background(), componenttest.NewNopHost()))
|
||||
require.NoError(t, firstExt.Shutdown(context.Background()))
|
||||
|
||||
secondExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
secondExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, secondExt.Start(context.Background(), componenttest.NewNopHost()))
|
||||
require.NoError(t, secondExt.Shutdown(context.Background()))
|
||||
|
|
|
|||
|
|
@ -239,12 +239,12 @@ func newExtensionFactory() extension.Factory {
|
|||
return extension.NewFactory(
|
||||
component.MustNewType("watcher"),
|
||||
createDefaultExtensionConfig,
|
||||
createExtension,
|
||||
create,
|
||||
component.StabilityLevelStable,
|
||||
)
|
||||
}
|
||||
|
||||
func createExtension(_ context.Context, _ extension.Settings, cfg component.Config) (extension.Extension, error) {
|
||||
func create(_ context.Context, _ extension.Settings, cfg component.Config) (extension.Extension, error) {
|
||||
oCfg := cfg.(*extensionConfig)
|
||||
return &testExtension{
|
||||
eventsReceived: oCfg.eventsReceived,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
|
|||
Name: ext.Type(),
|
||||
Module: factories.ExtensionModules[ext.Type()],
|
||||
Stability: map[string]string{
|
||||
"extension": ext.ExtensionStability().String(),
|
||||
"extension": ext.Stability().String(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,20 +43,20 @@ func (b *ExtensionBuilder) Create(ctx context.Context, set extension.Settings) (
|
|||
return nil, fmt.Errorf("extension factory not available for: %q", set.ID)
|
||||
}
|
||||
|
||||
sl := f.ExtensionStability()
|
||||
sl := f.Stability()
|
||||
if sl >= component.StabilityLevelAlpha {
|
||||
set.Logger.Debug(sl.LogMessage())
|
||||
} else {
|
||||
set.Logger.Info(sl.LogMessage())
|
||||
}
|
||||
return f.CreateExtension(ctx, set, cfg)
|
||||
return f.Create(ctx, set, cfg)
|
||||
}
|
||||
|
||||
func (b *ExtensionBuilder) Factory(componentType component.Type) component.Factory {
|
||||
return b.factories[componentType]
|
||||
}
|
||||
|
||||
// NewNopProcessorConfigsAndFactories returns a configuration and factories that allows building a new nop processor.
|
||||
// NewNopExtensionConfigsAndFactories returns a configuration and factories that allows building a new nop processor.
|
||||
func NewNopExtensionConfigsAndFactories() (map[component.ID]component.Config, map[component.Type]extension.Factory) {
|
||||
nopFactory := extensiontest.NewNopFactory()
|
||||
configs := map[component.ID]component.Config{
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func TestNewNopExtensionConfigsAndFactories(t *testing.T) {
|
|||
set := extensiontest.NewNopSettings()
|
||||
set.ID = component.NewID(nopType)
|
||||
|
||||
ext, err := factory.CreateExtension(context.Background(), set, cfg)
|
||||
ext, err := factory.Create(context.Background(), set, cfg)
|
||||
require.NoError(t, err)
|
||||
bExt, err := builder.Create(context.Background(), set)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue