diff --git a/.chloggen/codeboten_fix-12436.yaml b/.chloggen/codeboten_fix-12436.yaml new file mode 100644 index 00000000000..a6132fd03d3 --- /dev/null +++ b/.chloggen/codeboten_fix-12436.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: fix bug in parsing service::telemetry configuration + +# One or more tracking issues or pull requests related to the change +issues: [12437] + +# (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: + +# 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: [] diff --git a/service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml b/service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml index 2a26102400b..e072601f0c4 100644 --- a/service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml +++ b/service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml @@ -1,4 +1,3 @@ -level: detailed readers: - periodic: exporter: diff --git a/service/telemetry/internal/migration/testdata/v0.2.0_traces.yaml b/service/telemetry/internal/migration/testdata/v0.2.0_traces.yaml index 3fef18525df..e5fb7d64188 100644 --- a/service/telemetry/internal/migration/testdata/v0.2.0_traces.yaml +++ b/service/telemetry/internal/migration/testdata/v0.2.0_traces.yaml @@ -1,4 +1,3 @@ -level: "none" processors: - batch: exporter: diff --git a/service/telemetry/internal/migration/v0.2.0_test.go b/service/telemetry/internal/migration/v0.2.0_test.go index 07bdbac4abc..7a296e0d1e6 100644 --- a/service/telemetry/internal/migration/v0.2.0_test.go +++ b/service/telemetry/internal/migration/v0.2.0_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap/confmaptest" ) @@ -16,35 +17,47 @@ func TestUnmarshalLogsConfigV020(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_logs.yaml")) require.NoError(t, err) - cfg := LogsConfigV030{} + cfg := LogsConfigV030{ + Encoding: "console", + } require.NoError(t, cm.Unmarshal(&cfg)) require.Len(t, cfg.Processors, 3) // check the endpoint is prefixed w/ http require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint) // check the endpoint is prefixed w/ http require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint) + // ensure defaults set in the original config object are not lost + require.Equal(t, "console", cfg.Encoding) } func TestUnmarshalTracesConfigV020(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_traces.yaml")) require.NoError(t, err) - cfg := TracesConfigV030{} + cfg := TracesConfigV030{ + Level: configtelemetry.LevelNone, + } require.NoError(t, cm.Unmarshal(&cfg)) require.Len(t, cfg.Processors, 3) // check the endpoint is prefixed w/ http require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint) // check the endpoint is prefixed w/ http require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint) + // ensure defaults set in the original config object are not lost + require.Equal(t, configtelemetry.LevelNone, cfg.Level) } func TestUnmarshalMetricsConfigV020(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_metrics.yaml")) require.NoError(t, err) - cfg := MetricsConfigV030{} + cfg := MetricsConfigV030{ + Level: configtelemetry.LevelBasic, + } require.NoError(t, cm.Unmarshal(&cfg)) require.Len(t, cfg.Readers, 2) // check the endpoint is prefixed w/ http require.Equal(t, "http://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint) + // ensure defaults set in the original config object are not lost + require.Equal(t, configtelemetry.LevelBasic, cfg.Level) } diff --git a/service/telemetry/internal/migration/v0.3.0.go b/service/telemetry/internal/migration/v0.3.0.go index 1b1b0d11442..bf71ea91843 100644 --- a/service/telemetry/internal/migration/v0.3.0.go +++ b/service/telemetry/internal/migration/v0.3.0.go @@ -28,8 +28,12 @@ type TracesConfigV030 struct { } func (c *TracesConfigV030) Unmarshal(conf *confmap.Conf) error { + unmarshaled := *c if err := conf.Unmarshal(c); err != nil { - var v2TracesConfig tracesConfigV020 + v2TracesConfig := tracesConfigV020{ + Level: unmarshaled.Level, + Propagators: unmarshaled.Propagators, + } // try unmarshaling using v0.2.0 struct if e := conf.Unmarshal(&v2TracesConfig); e != nil { // error could not be resolved through backwards @@ -72,8 +76,12 @@ type MetricsConfigV030 struct { } func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error { + unmarshaled := *c if err := conf.Unmarshal(c); err != nil { - var v02 metricsConfigV020 + v02 := metricsConfigV020{ + Level: unmarshaled.Level, + Address: unmarshaled.Address, + } // try unmarshaling using v0.2.0 struct if e := conf.Unmarshal(&v02); e != nil { // error could not be resolved through backwards @@ -179,8 +187,19 @@ type LogsSamplingConfig struct { } func (c *LogsConfigV030) Unmarshal(conf *confmap.Conf) error { + unmarshaled := *c if err := conf.Unmarshal(c); err != nil { - var v02 logsConfigV020 + v02 := logsConfigV020{ + Level: unmarshaled.Level, + Development: unmarshaled.Development, + Encoding: unmarshaled.Encoding, + DisableCaller: unmarshaled.DisableCaller, + DisableStacktrace: unmarshaled.DisableStacktrace, + Sampling: unmarshaled.Sampling, + OutputPaths: unmarshaled.OutputPaths, + ErrorOutputPaths: unmarshaled.ErrorOutputPaths, + InitialFields: unmarshaled.InitialFields, + } // try unmarshaling using v0.2.0 struct if e := conf.Unmarshal(&v02); e != nil { // error could not be resolved through backwards