Skip to content

Commit cc66b6d

Browse files
authored
otelcol: remove default telemetry factory (#14062)
#### Description Remove the default telemetry factory, and require callers to specify one, to keep things maintainable. #### Link to tracking issue Fixes #14003 #### Testing <!--Describe the documentation added.--> #### Documentation N/A
1 parent 3b5e790 commit cc66b6d

File tree

8 files changed

+63
-39
lines changed

8 files changed

+63
-39
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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: pkg/otelcol
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: The `otelcol.Factories.Telemetry` field is now required
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14003]
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: |
19+
Previously if this field was not set, then it would default to an otelconftelemetry factory.
20+
Callers of the otelcol package must now set the field explicitly.
21+
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

otelcol/collector.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"go.opentelemetry.io/collector/confmap/xconfmap"
2626
"go.opentelemetry.io/collector/otelcol/internal/grpclog"
2727
"go.opentelemetry.io/collector/service"
28-
"go.opentelemetry.io/collector/service/telemetry/otelconftelemetry"
2928
)
3029

3130
// State defines Collector's state.
@@ -179,9 +178,6 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
179178
if err != nil {
180179
return fmt.Errorf("failed to initialize factories: %w", err)
181180
}
182-
if factories.Telemetry == nil {
183-
factories.Telemetry = otelconftelemetry.NewFactory()
184-
}
185181

186182
cfg, err := col.configProvider.Get(ctx, factories)
187183
if err != nil {
@@ -274,9 +270,6 @@ func (col *Collector) DryRun(ctx context.Context) error {
274270
if err != nil {
275271
return fmt.Errorf("failed to initialize factories: %w", err)
276272
}
277-
if factories.Telemetry == nil {
278-
factories.Telemetry = otelconftelemetry.NewFactory()
279-
}
280273

281274
cfg, err := col.configProvider.Get(ctx, factories)
282275
if err != nil {

otelcol/collector_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,6 @@ func TestCollectorRun(t *testing.T) {
397397
factories: nopFactories,
398398
configFile: "otelcol-nop.yaml",
399399
},
400-
"defaul_telemetry_factory": {
401-
factories: func() (Factories, error) {
402-
factories, err := nopFactories()
403-
if err != nil {
404-
return Factories{}, err
405-
}
406-
factories.Telemetry = nil
407-
return factories, nil
408-
},
409-
configFile: "otelcol-otelconftelemetry.yaml",
410-
},
411400
}
412401

413402
for name, test := range tests {
@@ -477,6 +466,18 @@ func TestCollectorRun_Errors(t *testing.T) {
477466
},
478467
expectedErr: "failed to get config: cannot unmarshal the configuration: decoding failed due to the following error(s):\n\n'service.telemetry' has invalid keys: unknown",
479468
},
469+
"missing_telemetry_factory": {
470+
settings: CollectorSettings{
471+
BuildInfo: component.NewDefaultBuildInfo(),
472+
Factories: func() (Factories, error) {
473+
factories, _ := nopFactories()
474+
factories.Telemetry = nil
475+
return factories, nil
476+
},
477+
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-otelconftelemetry.yaml")}),
478+
},
479+
expectedErr: "failed to get config: cannot unmarshal the configuration: otelcol.Factories.Telemetry must not be nil. For example, you can use otelconftelemetry.NewFactory to build a telemetry factory",
480+
},
480481
}
481482

482483
for name, test := range tests {
@@ -548,19 +549,17 @@ func TestCollectorDryRun(t *testing.T) {
548549
},
549550
expectedErr: "failed to get config: cannot unmarshal the configuration: decoding failed due to the following error(s):\n\n'service.telemetry' has invalid keys: unknown",
550551
},
551-
"default_telemetry_factory": {
552+
"missing_telemetry_factory": {
552553
settings: CollectorSettings{
553554
BuildInfo: component.NewDefaultBuildInfo(),
554555
Factories: func() (Factories, error) {
555-
factories, err := nopFactories()
556-
if err != nil {
557-
return Factories{}, err
558-
}
556+
factories, _ := nopFactories()
559557
factories.Telemetry = nil
560558
return factories, nil
561559
},
562560
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-otelconftelemetry.yaml")}),
563561
},
562+
expectedErr: "failed to get config: cannot unmarshal the configuration: otelcol.Factories.Telemetry must not be nil. For example, you can use otelconftelemetry.NewFactory to build a telemetry factory",
564563
},
565564
}
566565

otelcol/factories.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ type Factories struct {
3434
Connectors map[component.Type]connector.Factory
3535

3636
// Telemetry is the factory to create the telemetry providers for the service.
37-
//
38-
// If Telemetry is nil, otelconftelemetry will be used by default.
39-
// TODO remove the backwards compatibility and require a non-nil factory
40-
// https://github.com/open-telemetry/opentelemetry-collector/issues/14003
4137
Telemetry telemetry.Factory
4238

4339
// ReceiverModules maps receiver types to their respective go modules.

otelcol/otelcoltest/config.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ import (
1313
"go.opentelemetry.io/collector/confmap/provider/yamlprovider"
1414
"go.opentelemetry.io/collector/confmap/xconfmap"
1515
"go.opentelemetry.io/collector/otelcol"
16-
"go.opentelemetry.io/collector/service/telemetry/otelconftelemetry"
1716
)
1817

19-
// LoadConfig loads a config.Config from file, and does NOT validate the configuration.
18+
// LoadConfig loads a config.Config from file, and does NOT validate the configuration.
2019
//
21-
// If factories.Telemetry is nil, otelconftelemetry will be used by default.
22-
// TODO remove the backwards compatibility and require a non-nil factory
23-
// https://github.com/open-telemetry/opentelemetry-collector/issues/14003
20+
// If factories.Telemetry is nil, a no-op telemetry factory will be used. This
21+
// factory does not support any telemetry configuration.
2422
func LoadConfig(fileName string, factories otelcol.Factories) (*otelcol.Config, error) {
2523
if factories.Telemetry == nil {
26-
factories.Telemetry = otelconftelemetry.NewFactory()
24+
factories.Telemetry = nopTelemetryFactory()
2725
}
2826
provider, err := otelcol.NewConfigProvider(otelcol.ConfigProviderSettings{
2927
ResolverSettings: confmap.ResolverSettings{

otelcol/otelcoltest/config_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"go.opentelemetry.io/collector/component"
1414
"go.opentelemetry.io/collector/pipeline"
1515
"go.opentelemetry.io/collector/service/pipelines"
16-
"go.opentelemetry.io/collector/service/telemetry/otelconftelemetry"
1716
)
1817

1918
func TestLoadConfig(t *testing.T) {
@@ -64,15 +63,15 @@ func TestLoadConfig(t *testing.T) {
6463
assert.Equal(t, struct{}{}, cfg.Service.Telemetry)
6564
}
6665

67-
func TestLoadConfig_DefaultTelemetry(t *testing.T) {
66+
func TestLoadConfig_DefaultNopTelemetry(t *testing.T) {
6867
factories, err := NopFactories()
6968
require.NoError(t, err)
7069
factories.Telemetry = nil
7170

7271
cfg, err := LoadConfig(filepath.Join("testdata", "config.yaml"), factories)
7372
require.NoError(t, err)
7473

75-
assert.Equal(t, otelconftelemetry.NewFactory().CreateDefaultConfig(), cfg.Service.Telemetry)
74+
assert.Equal(t, struct{}{}, cfg.Service.Telemetry)
7675
}
7776

7877
func TestLoadConfigAndValidate(t *testing.T) {

otelcol/otelcoltest/nop_factories.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ func NopFactories() (otelcol.Factories, error) {
2424
factories.Exporters, _ = otelcol.MakeFactoryMap(exportertest.NewNopFactory())
2525
factories.Processors, _ = otelcol.MakeFactoryMap(processortest.NewNopFactory())
2626
factories.Connectors, _ = otelcol.MakeFactoryMap(connectortest.NewNopFactory())
27-
factories.Telemetry = telemetry.NewFactory(
28-
func() component.Config { return struct{}{} },
29-
)
27+
factories.Telemetry = nopTelemetryFactory()
3028

3129
return factories, nil
3230
}
31+
32+
func nopTelemetryFactory() telemetry.Factory {
33+
return telemetry.NewFactory(
34+
func() component.Config { return struct{}{} },
35+
)
36+
}

otelcol/unmarshaler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package otelcol // import "go.opentelemetry.io/collector/otelcol"
55

66
import (
7+
"errors"
8+
79
"go.opentelemetry.io/collector/confmap"
810
"go.opentelemetry.io/collector/connector"
911
"go.opentelemetry.io/collector/exporter"
@@ -14,6 +16,8 @@ import (
1416
"go.opentelemetry.io/collector/service"
1517
)
1618

19+
var errNilTelemetryFactory = errors.New("otelcol.Factories.Telemetry must not be nil. For example, you can use otelconftelemetry.NewFactory to build a telemetry factory")
20+
1721
type configSettings struct {
1822
Receivers *configunmarshaler.Configs[receiver.Factory] `mapstructure:"receivers"`
1923
Processors *configunmarshaler.Configs[processor.Factory] `mapstructure:"processors"`
@@ -26,6 +30,10 @@ type configSettings struct {
2630
// unmarshal the configSettings from a confmap.Conf.
2731
// After the config is unmarshalled, `Validate()` must be called to validate.
2832
func unmarshal(v *confmap.Conf, factories Factories) (*configSettings, error) {
33+
if factories.Telemetry == nil {
34+
return nil, errNilTelemetryFactory
35+
}
36+
2937
// Unmarshal top level sections and validate.
3038
cfg := &configSettings{
3139
Receivers: configunmarshaler.NewConfigs(factories.Receivers),

0 commit comments

Comments
 (0)