Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service] fix bug in parsing service::telemetry configuration #12437

Merged
merged 4 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/codeboten_fix-12436.yaml
Original file line number Diff line number Diff line change
@@ -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: []
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
level: detailed
readers:
- periodic:
exporter:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
level: "none"
processors:
- batch:
exporter:
Expand Down
19 changes: 16 additions & 3 deletions service/telemetry/internal/migration/v0.2.0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,55 @@ import (

"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap/confmaptest"
)

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)
}
25 changes: 22 additions & 3 deletions service/telemetry/internal/migration/v0.3.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading