Skip to content

Commit

Permalink
[extension] deprecate CreateSettings -> Settings
Browse files Browse the repository at this point in the history
This deprecates CreateSettings in favour of Settings. NewNopCreateSettings is also being deprecated in favour of NewNopSettings

Part of open-telemetry#9428

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten committed Jun 6, 2024
1 parent 1912879 commit 5bfeb77
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 65 deletions.
28 changes: 28 additions & 0 deletions .chloggen/codeboten_create-settings-extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 CreateSettings and NewNopCreateSettings

# One or more tracking issues or pull requests related to the change
issues: [9428]

# (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: |
The following methods are being renamed:
- extension.CreateSettings -> extension.Settings
- extension.NewNopCreateSettings -> extension.NewNopSettings
# 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]
11 changes: 0 additions & 11 deletions cmd/mdatagen/templates/component_telemetry_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type componentTestTelemetry struct {
meterProvider *sdkmetric.MeterProvider
}

{{- if (or isExporter isReceiver isProcessor isConnector) }}
func (tt *componentTestTelemetry) NewSettings() {{ .Status.Class }}.Settings {
settings := {{ .Status.Class }}test.NewNopSettings()
settings.MeterProvider = tt.meterProvider
Expand All @@ -30,16 +29,6 @@ func (tt *componentTestTelemetry) NewSettings() {{ .Status.Class }}.Settings {
return settings
}

{{ else }}
func (tt *componentTestTelemetry) NewCreateSettings() {{ .Status.Class }}.CreateSettings {
settings := {{ .Status.Class }}test.NewNopCreateSettings()
settings.MeterProvider = tt.meterProvider
settings.ID = component.NewID(component.MustNewType("{{ .Type }}"))

return settings
}

{{ end }}
func setupTestTelemetry() componentTestTelemetry {
reader := sdkmetric.NewManualReader()
return componentTestTelemetry{
Expand Down
6 changes: 3 additions & 3 deletions cmd/mdatagen/templates/component_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestComponentLifecycle(t *testing.T) {

{{- if not .Tests.SkipShutdown }}
t.Run("shutdown", func(t *testing.T) {
e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
require.NoError(t, err)
err = e.Shutdown(context.Background())
require.NoError(t, err)
Expand All @@ -346,12 +346,12 @@ func TestComponentLifecycle(t *testing.T) {

{{- if not .Tests.SkipLifecycle }}
t.Run("lifecycle", func(t *testing.T) {
firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
firstExt, err := factory.CreateExtension(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.NewNopCreateSettings(), cfg)
secondExt, err := factory.CreateExtension(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()))
Expand Down
2 changes: 1 addition & 1 deletion exporter/internal/queue/persistent_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func TestInvalidStorageExtensionType(t *testing.T) {
// make a test extension
factory := extensiontest.NewNopFactory()
extConfig := factory.CreateDefaultConfig()
settings := extensiontest.NewNopCreateSettings()
settings := extensiontest.NewNopSettings()
extension, err := factory.CreateExtension(context.Background(), settings, extConfig)
assert.NoError(t, err)
var extensions = map[component.ID]component.Component{
Expand Down
2 changes: 1 addition & 1 deletion extension/ballastextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func createDefaultConfig() component.Config {
return &Config{}
}

func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) {
func createExtension(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
return newMemoryBallast(cfg.(*Config), set.TelemetrySettings.Logger, memHandler), nil
}
4 changes: 2 additions & 2 deletions extension/ballastextension/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
assert.Equal(t, &Config{}, cfg)

assert.NoError(t, componenttest.CheckConfigStruct(cfg))
ext, err := createExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
require.NoError(t, err)
require.NotNil(t, ext)
}

func TestFactory_CreateExtension(t *testing.T) {
cfg := createDefaultConfig().(*Config)
ext, err := createExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
require.NoError(t, err)
require.NotNil(t, ext)
}
6 changes: 3 additions & 3 deletions extension/ballastextension/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ type StatusWatcher interface {
}

// CreateSettings is passed to Factory.Create(...) function.
type CreateSettings struct {
//
// Deprecated: [v0.103.0] Use extension.Settings instead.
type CreateSettings = Settings

// Settings is passed to Factory.Create(...) function.
type Settings struct {
// ID returns the ID of the component that will be created.
ID component.ID

Expand All @@ -74,18 +79,18 @@ type CreateSettings struct {
}

// CreateFunc is the equivalent of Factory.Create(...) function.
type CreateFunc func(context.Context, CreateSettings, component.Config) (Extension, error)
type CreateFunc func(context.Context, Settings, component.Config) (Extension, error)

// CreateExtension implements Factory.Create.
func (f CreateFunc) CreateExtension(ctx context.Context, set CreateSettings, cfg component.Config) (Extension, error) {
func (f CreateFunc) CreateExtension(ctx context.Context, set Settings, cfg component.Config) (Extension, error) {
return f(ctx, set, cfg)
}

type Factory interface {
component.Factory

// CreateExtension creates an extension based on the given config.
CreateExtension(ctx context.Context, set CreateSettings, cfg component.Config) (Extension, error)
CreateExtension(ctx context.Context, set Settings, cfg component.Config) (Extension, error)

// ExtensionStability gets the stability level of the Extension.
ExtensionStability() component.StabilityLevel
Expand Down Expand Up @@ -149,7 +154,7 @@ func NewBuilder(cfgs map[component.ID]component.Config, factories map[component.
}

// Create creates an extension based on the settings and configs available.
func (b *Builder) Create(ctx context.Context, set CreateSettings) (Extension, error) {
func (b *Builder) Create(ctx context.Context, set Settings) (Extension, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("extension %q is not configured", set.ID)
Expand Down
16 changes: 8 additions & 8 deletions extension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type nopExtension struct {
component.StartFunc
component.ShutdownFunc
CreateSettings
Settings
}

func TestNewFactory(t *testing.T) {
Expand All @@ -28,15 +28,15 @@ func TestNewFactory(t *testing.T) {
factory := NewFactory(
testType,
func() component.Config { return &defaultCfg },
func(context.Context, CreateSettings, component.Config) (Extension, error) {
func(context.Context, Settings, component.Config) (Extension, error) {
return nopExtensionInstance, nil
},
component.StabilityLevelDevelopment)
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(), CreateSettings{}, &defaultCfg)
ext, err := factory.CreateExtension(context.Background(), Settings{}, &defaultCfg)
assert.NoError(t, err)
assert.Same(t, nopExtensionInstance, ext)
}
Expand Down Expand Up @@ -88,8 +88,8 @@ func TestBuilder(t *testing.T) {
NewFactory(
testType,
func() component.Config { return &defaultCfg },
func(_ context.Context, settings CreateSettings, _ component.Config) (Extension, error) {
return nopExtension{CreateSettings: settings}, nil
func(_ context.Context, settings Settings, _ component.Config) (Extension, error) {
return nopExtension{Settings: settings}, nil
},
component.StabilityLevelDevelopment),
}...)
Expand All @@ -105,7 +105,7 @@ func TestBuilder(t *testing.T) {
// Check that the extension has access to the resource attributes.
nop, ok := e.(nopExtension)
assert.True(t, ok)
assert.Equal(t, nop.CreateSettings.Resource.Attributes().Len(), 0)
assert.Equal(t, nop.Settings.Resource.Attributes().Len(), 0)

missingType, err := b.Create(context.Background(), createSettings(unknownID))
assert.EqualError(t, err, "extension factory not available for: \"unknown\"")
Expand All @@ -127,8 +127,8 @@ func TestBuilderFactory(t *testing.T) {
assert.Nil(t, b.Factory(component.MustNewID("bar").Type()))
}

func createSettings(id component.ID) CreateSettings {
return CreateSettings{
func createSettings(id component.ID) Settings {
return Settings{
ID: id,
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
Expand Down
13 changes: 10 additions & 3 deletions extension/extensiontest/nop_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ import (
var nopType = component.MustNewType("nop")

// NewNopCreateSettings returns a new nop settings for extension.Factory Create* functions.
func NewNopCreateSettings() extension.CreateSettings {
return extension.CreateSettings{
//
// Deprecated: [v0.103.0] Use extensiontest.NewNopSettings instead.
func NewNopCreateSettings() extension.Settings {
return NewNopSettings()
}

// NewNopSettings returns a new nop settings for extension.Factory Create* functions.
func NewNopSettings() extension.Settings {
return extension.Settings{
ID: component.NewIDWithName(nopType, uuid.NewString()),
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
Expand All @@ -31,7 +38,7 @@ func NewNopFactory() extension.Factory {
func() component.Config {
return &nopConfig{}
},
func(context.Context, extension.CreateSettings, component.Config) (extension.Extension, error) {
func(context.Context, extension.Settings, component.Config) (extension.Extension, error) {
return nopInstance, nil
},
component.StabilityLevelStable)
Expand Down
4 changes: 2 additions & 2 deletions extension/extensiontest/nop_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestNewNopFactory(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, &nopConfig{}, cfg)

traces, err := factory.CreateExtension(context.Background(), NewNopCreateSettings(), cfg)
traces, err := factory.CreateExtension(context.Background(), NewNopSettings(), cfg)
require.NoError(t, err)
assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, traces.Shutdown(context.Background()))
Expand All @@ -33,7 +33,7 @@ func TestNewNopBuilder(t *testing.T) {

factory := NewNopFactory()
cfg := factory.CreateDefaultConfig()
set := NewNopCreateSettings()
set := NewNopSettings()
set.ID = component.NewID(nopType)

ext, err := factory.CreateExtension(context.Background(), set, cfg)
Expand Down
6 changes: 3 additions & 3 deletions extension/extensiontest/statuswatcher_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

// NewStatusWatcherExtensionCreateSettings returns a new nop settings for Create*Extension functions.
func NewStatusWatcherExtensionCreateSettings() extension.CreateSettings {
return extension.CreateSettings{
func NewStatusWatcherExtensionCreateSettings() extension.Settings {
return extension.Settings{
TelemetrySettings: componenttest.NewNopTelemetrySettings(),
BuildInfo: component.NewDefaultBuildInfo(),
}
Expand All @@ -28,7 +28,7 @@ func NewStatusWatcherExtensionFactory(
func() component.Config {
return &struct{}{}
},
func(context.Context, extension.CreateSettings, component.Config) (component.Component, error) {
func(context.Context, extension.Settings, component.Config) (component.Component, error) {
return &statusWatcherExtension{onStatusChanged: onStatusChanged}, nil
},
component.StabilityLevelStable)
Expand Down
2 changes: 1 addition & 1 deletion extension/memorylimiterextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func createDefaultConfig() component.Config {
return &Config{}
}

func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) {
func createExtension(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
return newMemoryLimiter(cfg.(*Config), set.TelemetrySettings.Logger)
}
2 changes: 1 addition & 1 deletion extension/memorylimiterextension/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestCreateExtension(t *testing.T) {
pCfg.MemorySpikeLimitMiB = 1907
pCfg.CheckInterval = 100 * time.Millisecond

tp, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
tp, err := factory.CreateExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
assert.NoError(t, err)
assert.NotNil(t, tp)
// test if we can shutdown a monitoring routine that has not started
Expand Down
4 changes: 2 additions & 2 deletions extension/memorylimiterextension/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extension/zpagesextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ func createDefaultConfig() component.Config {
}

// createExtension creates the extension based on this config.
func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) {
func createExtension(_ context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) {
return newServer(cfg.(*Config), set.TelemetrySettings), nil
}
4 changes: 2 additions & 2 deletions extension/zpagesextension/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
cfg)

assert.NoError(t, componenttest.CheckConfigStruct(cfg))
ext, err := createExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
require.NoError(t, err)
require.NotNil(t, ext)
}
Expand All @@ -35,7 +35,7 @@ func TestFactory_CreateExtension(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.TCPAddr.Endpoint = testutil.GetAvailableLocalAddress(t)

ext, err := createExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
ext, err := createExtension(context.Background(), extensiontest.NewNopSettings(), cfg)
require.NoError(t, err)
require.NotNil(t, ext)
}
6 changes: 3 additions & 3 deletions extension/zpagesextension/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) {
ID: extID,
Kind: component.KindExtension,
}
extSet := extension.CreateSettings{
extSet := extension.Settings{
ID: extID,
TelemetrySettings: set.Telemetry.ToComponentTelemetrySettings(instanceID),
BuildInfo: set.BuildInfo,
Expand Down
Loading

0 comments on commit 5bfeb77

Please sign in to comment.