Skip to content

Commit 2f87518

Browse files
authored
[confmap] Deprecate NewWithSettings and New (#10134)
#### Description Each of these was deprecated in v0.99.0, so I think removing them in v0.101.0 is a safe deprecation period for an API that is likely only used by vendor distros built without ocb. If we would like to extend the deprecation period or break this change into PRs for each module, let me know and I'll make the necessary changes.
1 parent 634223b commit 2f87518

File tree

8 files changed

+61
-90
lines changed

8 files changed

+61
-90
lines changed

.chloggen/deprecate-confmap-new.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: confmap
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate `NewWithSettings` for all Providers and `New` for all Converters
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10134]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: Use `NewFactory` instead for all affected modules.
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

confmap/converter/expandconverter/expand.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,19 @@ type converter struct {
2121
loggedDeprecations map[string]struct{}
2222
}
2323

24-
// New returns a confmap.Converter, that expands all environment variables for a given confmap.Conf.
25-
//
26-
// Notice: This API is experimental.
27-
//
28-
// Deprecated: [v0.99.0] Use NewFactory instead.
29-
func New(_ confmap.ConverterSettings) confmap.Converter {
24+
// NewFactory returns a factory for a confmap.Converter,
25+
// which expands all environment variables for a given confmap.Conf.
26+
func NewFactory() confmap.ConverterFactory {
27+
return confmap.NewConverterFactory(newConverter)
28+
}
29+
30+
func newConverter(_ confmap.ConverterSettings) confmap.Converter {
3031
return converter{
3132
loggedDeprecations: make(map[string]struct{}),
3233
logger: zap.NewNop(), // TODO: pass logger in ConverterSettings
3334
}
3435
}
3536

36-
// NewFactory returns a factory for a confmap.Converter,
37-
// which expands all environment variables for a given confmap.Conf.
38-
func NewFactory() confmap.ConverterFactory {
39-
return confmap.NewConverterFactory(New)
40-
}
41-
4237
func (c converter) Convert(_ context.Context, conf *confmap.Conf) error {
4338
out := make(map[string]any)
4439
for _, k := range conf.AllKeys() {

confmap/provider/envprovider/provider.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,20 @@ type provider struct {
2121
logger *zap.Logger
2222
}
2323

24-
// NewWithSettings returns a new confmap.Provider that reads the configuration from the given environment variable.
24+
// NewFactory returns a factory for a confmap.Provider that reads the configuration from the given environment variable.
2525
//
2626
// This Provider supports "env" scheme, and can be called with a selector:
2727
// `env:NAME_OF_ENVIRONMENT_VARIABLE`
28-
//
29-
// Deprecated: [v0.99.0] Use NewFactory instead.
30-
func NewWithSettings(ps confmap.ProviderSettings) confmap.Provider {
28+
func NewFactory() confmap.ProviderFactory {
29+
return confmap.NewProviderFactory(newProvider)
30+
}
31+
32+
func newProvider(ps confmap.ProviderSettings) confmap.Provider {
3133
return &provider{
3234
logger: ps.Logger,
3335
}
3436
}
3537

36-
// NewFactory returns a factory for a confmap.Provider that reads the configuration from the given environment variable.
37-
//
38-
// This Provider supports "env" scheme, and can be called with a selector:
39-
// `env:NAME_OF_ENVIRONMENT_VARIABLE`
40-
func NewFactory() confmap.ProviderFactory {
41-
return confmap.NewProviderFactory(NewWithSettings)
42-
}
43-
4438
func (emp *provider) Retrieve(_ context.Context, uri string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) {
4539
if !strings.HasPrefix(uri, schemeName+":") {
4640
return nil, fmt.Errorf("%q uri is not supported by %q provider", uri, schemeName)

confmap/provider/envprovider/provider_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestEnvWithLogger(t *testing.T) {
7777
core, ol := observer.New(zap.WarnLevel)
7878
logger := zap.New(core)
7979

80-
env := NewWithSettings(confmap.ProviderSettings{Logger: logger})
80+
env := NewFactory().Create(confmap.ProviderSettings{Logger: logger})
8181
ret, err := env.Retrieve(context.Background(), envSchemePrefix+envName, nil)
8282
require.NoError(t, err)
8383
retMap, err := ret.AsConf()
@@ -97,7 +97,7 @@ func TestUnsetEnvWithLoggerWarn(t *testing.T) {
9797
core, ol := observer.New(zap.WarnLevel)
9898
logger := zap.New(core)
9999

100-
env := NewWithSettings(confmap.ProviderSettings{Logger: logger})
100+
env := NewFactory().Create(confmap.ProviderSettings{Logger: logger})
101101
ret, err := env.Retrieve(context.Background(), envSchemePrefix+envName, nil)
102102
require.NoError(t, err)
103103
retMap, err := ret.AsConf()
@@ -121,7 +121,7 @@ func TestEmptyEnvWithLoggerWarn(t *testing.T) {
121121
core, ol := observer.New(zap.InfoLevel)
122122
logger := zap.New(core)
123123

124-
env := NewWithSettings(confmap.ProviderSettings{Logger: logger})
124+
env := NewFactory().Create(confmap.ProviderSettings{Logger: logger})
125125
ret, err := env.Retrieve(context.Background(), envSchemePrefix+envName, nil)
126126
require.NoError(t, err)
127127
retMap, err := ret.AsConf()

confmap/provider/fileprovider/provider.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@ const schemeName = "file"
1818

1919
type provider struct{}
2020

21-
// NewWithSettings returns a new confmap.Provider that reads the configuration from a file.
22-
//
23-
// This Provider supports "file" scheme, and can be called with a "uri" that follows:
24-
//
25-
// file-uri = "file:" local-path
26-
// local-path = [ drive-letter ] file-path
27-
// drive-letter = ALPHA ":"
28-
//
29-
// The "file-path" can be relative or absolute, and it can be any OS supported format.
30-
//
31-
// Examples:
32-
// `file:path/to/file` - relative path (unix, windows)
33-
// `file:/path/to/file` - absolute path (unix, windows)
34-
// `file:c:/path/to/file` - absolute path including drive-letter (windows)
35-
// `file:c:\path\to\file` - absolute path including drive-letter (windows)
36-
//
37-
// Deprecated: [v0.99.0] Use NewFactory instead.
38-
func NewWithSettings(confmap.ProviderSettings) confmap.Provider {
39-
return &provider{}
40-
}
41-
4221
// NewFactory returns a factory for a confmap.Provider that reads the configuration from a file.
4322
//
4423
// This Provider supports "file" scheme, and can be called with a "uri" that follows:
@@ -55,7 +34,11 @@ func NewWithSettings(confmap.ProviderSettings) confmap.Provider {
5534
// `file:c:/path/to/file` - absolute path including drive-letter (windows)
5635
// `file:c:\path\to\file` - absolute path including drive-letter (windows)
5736
func NewFactory() confmap.ProviderFactory {
58-
return confmap.NewProviderFactory(NewWithSettings)
37+
return confmap.NewProviderFactory(newProvider)
38+
}
39+
40+
func newProvider(confmap.ProviderSettings) confmap.Provider {
41+
return &provider{}
5942
}
6043

6144
func (fmp *provider) Retrieve(_ context.Context, uri string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) {

confmap/provider/httpprovider/provider.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@ import (
88
"go.opentelemetry.io/collector/confmap/provider/internal/configurablehttpprovider"
99
)
1010

11-
// NewWithSettings returns a new confmap.Provider that reads the configuration from a http server.
12-
//
13-
// This Provider supports "http" scheme.
14-
//
15-
// One example for HTTP URI is: http://localhost:3333/getConfig
16-
//
17-
// Deprecated: [v0.99.0] Use NewFactory instead.
18-
func NewWithSettings(set confmap.ProviderSettings) confmap.Provider {
19-
return configurablehttpprovider.New(configurablehttpprovider.HTTPScheme, set)
20-
}
21-
2211
// NewFactory returns a factory for a confmap.Provider that reads the configuration from a http server.
2312
//
2413
// This Provider supports "http" scheme.
2514
//
2615
// One example for HTTP URI is: http://localhost:3333/getConfig
2716
func NewFactory() confmap.ProviderFactory {
28-
return confmap.NewProviderFactory(NewWithSettings)
17+
return confmap.NewProviderFactory(newProvider)
18+
}
19+
20+
func newProvider(set confmap.ProviderSettings) confmap.Provider {
21+
return configurablehttpprovider.New(configurablehttpprovider.HTTPScheme, set)
2922
}

confmap/provider/httpsprovider/provider.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@ import (
88
"go.opentelemetry.io/collector/confmap/provider/internal/configurablehttpprovider"
99
)
1010

11-
// NewWithSettings returns a new confmap.Provider that reads the configuration from a https server.
12-
//
13-
// This Provider supports "https" scheme. One example of an HTTPS URI is: https://localhost:3333/getConfig
14-
//
15-
// To add extra CA certificates you need to install certificates in the system pool. This procedure is operating system
16-
// dependent. E.g.: on Linux please refer to the `update-ca-trust` command.
17-
//
18-
// Deprecated: [v0.99.0] Use NewFactory instead.
19-
func NewWithSettings(set confmap.ProviderSettings) confmap.Provider {
20-
return configurablehttpprovider.New(configurablehttpprovider.HTTPSScheme, set)
21-
}
22-
2311
// NewFactory returns a factory for a confmap.Provider that reads the configuration from a https server.
2412
//
2513
// This Provider supports "https" scheme. One example of an HTTPS URI is: https://localhost:3333/getConfig
2614
//
2715
// To add extra CA certificates you need to install certificates in the system pool. This procedure is operating system
2816
// dependent. E.g.: on Linux please refer to the `update-ca-trust` command.
2917
func NewFactory() confmap.ProviderFactory {
30-
return confmap.NewProviderFactory(NewWithSettings)
18+
return confmap.NewProviderFactory(newProvider)
19+
}
20+
21+
func newProvider(set confmap.ProviderSettings) confmap.Provider {
22+
return configurablehttpprovider.New(configurablehttpprovider.HTTPSScheme, set)
3123
}

confmap/provider/yamlprovider/provider.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ const schemeName = "yaml"
1616

1717
type provider struct{}
1818

19-
// NewWithSettings returns a new confmap.Provider that allows to provide yaml bytes.
20-
//
21-
// This Provider supports "yaml" scheme, and can be called with a "uri" that follows:
22-
//
23-
// bytes-uri = "yaml:" yaml-bytes
24-
//
25-
// Examples:
26-
// `yaml:processors::batch::timeout: 2s`
27-
// `yaml:processors::batch/foo::timeout: 3s`
28-
//
29-
// Deprecated: [v0.99.0] Use NewFactory instead.
30-
func NewWithSettings(confmap.ProviderSettings) confmap.Provider {
31-
return &provider{}
32-
}
33-
3419
// NewFactory returns a factory for a confmap.Provider that allows to provide yaml bytes.
3520
//
3621
// This Provider supports "yaml" scheme, and can be called with a "uri" that follows:
@@ -41,7 +26,11 @@ func NewWithSettings(confmap.ProviderSettings) confmap.Provider {
4126
// `yaml:processors::batch::timeout: 2s`
4227
// `yaml:processors::batch/foo::timeout: 3s`
4328
func NewFactory() confmap.ProviderFactory {
44-
return confmap.NewProviderFactory(NewWithSettings)
29+
return confmap.NewProviderFactory(newProvider)
30+
}
31+
32+
func newProvider(confmap.ProviderSettings) confmap.Provider {
33+
return &provider{}
4534
}
4635

4736
func (s *provider) Retrieve(_ context.Context, uri string, _ confmap.WatcherFunc) (*confmap.Retrieved, error) {

0 commit comments

Comments
 (0)