Skip to content

Commit f024b0d

Browse files
authored
[service] fix bug in parsing service::telemetry configuration (#12437)
Fixes #12436 --------- Signed-off-by: Alex Boten <[email protected]>
1 parent d6d07c8 commit f024b0d

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

.chloggen/codeboten_fix-12436.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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: service
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: fix bug in parsing service::telemetry configuration
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12437]
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+
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: []

service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
level: detailed
21
readers:
32
- periodic:
43
exporter:

service/telemetry/internal/migration/testdata/v0.2.0_traces.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
level: "none"
21
processors:
32
- batch:
43
exporter:

service/telemetry/internal/migration/v0.2.0_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,55 @@ import (
99

1010
"github.com/stretchr/testify/require"
1111

12+
"go.opentelemetry.io/collector/config/configtelemetry"
1213
"go.opentelemetry.io/collector/confmap/confmaptest"
1314
)
1415

1516
func TestUnmarshalLogsConfigV020(t *testing.T) {
1617
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_logs.yaml"))
1718
require.NoError(t, err)
1819

19-
cfg := LogsConfigV030{}
20+
cfg := LogsConfigV030{
21+
Encoding: "console",
22+
}
2023
require.NoError(t, cm.Unmarshal(&cfg))
2124
require.Len(t, cfg.Processors, 3)
2225
// check the endpoint is prefixed w/ http
2326
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
2427
// check the endpoint is prefixed w/ http
2528
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
29+
// ensure defaults set in the original config object are not lost
30+
require.Equal(t, "console", cfg.Encoding)
2631
}
2732

2833
func TestUnmarshalTracesConfigV020(t *testing.T) {
2934
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_traces.yaml"))
3035
require.NoError(t, err)
3136

32-
cfg := TracesConfigV030{}
37+
cfg := TracesConfigV030{
38+
Level: configtelemetry.LevelNone,
39+
}
3340
require.NoError(t, cm.Unmarshal(&cfg))
3441
require.Len(t, cfg.Processors, 3)
3542
// check the endpoint is prefixed w/ http
3643
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
3744
// check the endpoint is prefixed w/ http
3845
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
46+
// ensure defaults set in the original config object are not lost
47+
require.Equal(t, configtelemetry.LevelNone, cfg.Level)
3948
}
4049

4150
func TestUnmarshalMetricsConfigV020(t *testing.T) {
4251
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_metrics.yaml"))
4352
require.NoError(t, err)
4453

45-
cfg := MetricsConfigV030{}
54+
cfg := MetricsConfigV030{
55+
Level: configtelemetry.LevelBasic,
56+
}
4657
require.NoError(t, cm.Unmarshal(&cfg))
4758
require.Len(t, cfg.Readers, 2)
4859
// check the endpoint is prefixed w/ http
4960
require.Equal(t, "http://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
61+
// ensure defaults set in the original config object are not lost
62+
require.Equal(t, configtelemetry.LevelBasic, cfg.Level)
5063
}

service/telemetry/internal/migration/v0.3.0.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ type TracesConfigV030 struct {
2828
}
2929

3030
func (c *TracesConfigV030) Unmarshal(conf *confmap.Conf) error {
31+
unmarshaled := *c
3132
if err := conf.Unmarshal(c); err != nil {
32-
var v2TracesConfig tracesConfigV020
33+
v2TracesConfig := tracesConfigV020{
34+
Level: unmarshaled.Level,
35+
Propagators: unmarshaled.Propagators,
36+
}
3337
// try unmarshaling using v0.2.0 struct
3438
if e := conf.Unmarshal(&v2TracesConfig); e != nil {
3539
// error could not be resolved through backwards
@@ -72,8 +76,12 @@ type MetricsConfigV030 struct {
7276
}
7377

7478
func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error {
79+
unmarshaled := *c
7580
if err := conf.Unmarshal(c); err != nil {
76-
var v02 metricsConfigV020
81+
v02 := metricsConfigV020{
82+
Level: unmarshaled.Level,
83+
Address: unmarshaled.Address,
84+
}
7785
// try unmarshaling using v0.2.0 struct
7886
if e := conf.Unmarshal(&v02); e != nil {
7987
// error could not be resolved through backwards
@@ -179,8 +187,19 @@ type LogsSamplingConfig struct {
179187
}
180188

181189
func (c *LogsConfigV030) Unmarshal(conf *confmap.Conf) error {
190+
unmarshaled := *c
182191
if err := conf.Unmarshal(c); err != nil {
183-
var v02 logsConfigV020
192+
v02 := logsConfigV020{
193+
Level: unmarshaled.Level,
194+
Development: unmarshaled.Development,
195+
Encoding: unmarshaled.Encoding,
196+
DisableCaller: unmarshaled.DisableCaller,
197+
DisableStacktrace: unmarshaled.DisableStacktrace,
198+
Sampling: unmarshaled.Sampling,
199+
OutputPaths: unmarshaled.OutputPaths,
200+
ErrorOutputPaths: unmarshaled.ErrorOutputPaths,
201+
InitialFields: unmarshaled.InitialFields,
202+
}
184203
// try unmarshaling using v0.2.0 struct
185204
if e := conf.Unmarshal(&v02); e != nil {
186205
// error could not be resolved through backwards

0 commit comments

Comments
 (0)