Skip to content

Commit 84bf8b6

Browse files
committed
[otelcol] Deprecate otelcol.ConfmapProvider
1 parent d9dbfbc commit 84bf8b6

File tree

5 files changed

+35
-50
lines changed

5 files changed

+35
-50
lines changed
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: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: otelcol
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate `otelcol.ConfmapProvider`
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: []
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: "`otelcol.Collector` will now marshal `confmap.Conf` objects from `otelcol.Config` itself."
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]

config/confighttp/confighttp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type ClientConfig struct {
5757
Headers map[string]configopaque.String `mapstructure:"headers"`
5858

5959
// Custom Round Tripper to allow for individual components to intercept HTTP requests
60-
CustomRoundTripper func(next http.RoundTripper) (http.RoundTripper, error)
60+
CustomRoundTripper func(next http.RoundTripper) (http.RoundTripper, error) `mapstructure:"-" yaml:"-"`
6161

6262
// Auth configuration for outgoing HTTP calls.
6363
Auth *configauth.Authentication `mapstructure:"auth"`

otelcol/collector.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,6 @@ func (col *Collector) Shutdown() {
173173
func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
174174
col.setCollectorState(StateStarting)
175175

176-
var conf *confmap.Conf
177-
178-
if cp, ok := col.configProvider.(ConfmapProvider); ok {
179-
var err error
180-
conf, err = cp.GetConfmap(ctx)
181-
182-
if err != nil {
183-
return fmt.Errorf("failed to resolve config: %w", err)
184-
}
185-
}
186-
187176
factories, err := col.set.Factories()
188177
if err != nil {
189178
return fmt.Errorf("failed to initialize factories: %w", err)
@@ -199,6 +188,12 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
199188

200189
col.serviceConfig = &cfg.Service
201190

191+
conf := confmap.New()
192+
193+
if err := conf.Marshal(cfg); err != nil {
194+
return fmt.Errorf("could not marshal configuration: %w", err)
195+
}
196+
202197
col.service, err = service.New(ctx, service.Settings{
203198
BuildInfo: col.set.BuildInfo,
204199
CollectorConf: conf,

otelcol/configprovider.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type ConfigProvider interface {
5656
//
5757
// The purpose of this interface is that otelcol.ConfigProvider structs do not
5858
// necessarily need to use confmap.Conf as their underlying config structure.
59+
//
60+
// Deprecated: [v0.101.0] This interface is deprecated. otelcol.Collector will now obtain
61+
// a confmap.Conf object from the unmarshaled config itself.
5962
type ConfmapProvider interface {
6063
// GetConfmap resolves the Collector's configuration and provides it as a confmap.Conf object.
6164
//
@@ -68,7 +71,6 @@ type configProvider struct {
6871
}
6972

7073
var _ ConfigProvider = &configProvider{}
71-
var _ ConfmapProvider = &configProvider{}
7274

7375
// ConfigProviderSettings are the settings to configure the behavior of the ConfigProvider.
7476
type ConfigProviderSettings struct {
@@ -122,15 +124,6 @@ func (cm *configProvider) Shutdown(ctx context.Context) error {
122124
return cm.mapResolver.Shutdown(ctx)
123125
}
124126

125-
func (cm *configProvider) GetConfmap(ctx context.Context) (*confmap.Conf, error) {
126-
conf, err := cm.mapResolver.Resolve(ctx)
127-
if err != nil {
128-
return nil, fmt.Errorf("cannot resolve the configuration: %w", err)
129-
}
130-
131-
return conf, nil
132-
}
133-
134127
func newDefaultConfigProviderSettings(uris []string) ConfigProviderSettings {
135128
return ConfigProviderSettings{
136129
ResolverSettings: confmap.ResolverSettings{

otelcol/configprovider_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,3 @@ func TestConfigProviderFile(t *testing.T) {
9696

9797
assert.EqualValues(t, configNop, cfg)
9898
}
99-
100-
func TestGetConfmap(t *testing.T) {
101-
uriLocation := "file:" + filepath.Join("testdata", "otelcol-nop.yaml")
102-
set := ConfigProviderSettings{
103-
ResolverSettings: confmap.ResolverSettings{
104-
URIs: []string{uriLocation},
105-
ProviderFactories: []confmap.ProviderFactory{fileprovider.NewFactory()},
106-
},
107-
}
108-
109-
configBytes, err := os.ReadFile(filepath.Join("testdata", "otelcol-nop.yaml"))
110-
require.NoError(t, err)
111-
112-
yamlMap := map[string]any{}
113-
err = yaml.Unmarshal(configBytes, yamlMap)
114-
require.NoError(t, err)
115-
116-
cp, err := NewConfigProvider(set)
117-
require.NoError(t, err)
118-
119-
cmp, ok := cp.(ConfmapProvider)
120-
require.True(t, ok)
121-
122-
cmap, err := cmp.GetConfmap(context.Background())
123-
require.NoError(t, err)
124-
125-
assert.EqualValues(t, yamlMap, cmap.ToStringMap())
126-
}

0 commit comments

Comments
 (0)