diff --git a/.chloggen/codeboten_bump-config-pkg.yaml b/.chloggen/codeboten_bump-config-pkg.yaml new file mode 100644 index 00000000000..92dbaad0a27 --- /dev/null +++ b/.chloggen/codeboten_bump-config-pkg.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 crash at startup when converting from v0.2.0 to v0.3.0 + +# One or more tracking issues or pull requests related to the change +issues: [12438] + +# (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/otelcol/collector_test.go b/otelcol/collector_test.go index 86855a3c86d..d9559074c0e 100644 --- a/otelcol/collector_test.go +++ b/otelcol/collector_test.go @@ -391,6 +391,7 @@ func TestCollectorRun(t *testing.T) { }{ {file: "otelcol-noreaders.yaml"}, {file: "otelcol-emptyreaders.yaml"}, + {file: "otelcol-multipleheaders.yaml"}, } for _, tt := range tests { diff --git a/otelcol/testdata/otelcol-multipleheaders.yaml b/otelcol/testdata/otelcol-multipleheaders.yaml new file mode 100644 index 00000000000..6247f38318d --- /dev/null +++ b/otelcol/testdata/otelcol-multipleheaders.yaml @@ -0,0 +1,24 @@ +receivers: + nop: + +exporters: + nop: + +service: + telemetry: + metrics: + level: none + traces: + processors: + - batch: + exporter: + otlp: + endpoint: localhost:4318 + headers: + first: val1 + second: val2 + protocol: http/protobuf + pipelines: + metrics: + receivers: [nop] + exporters: [nop] 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 e072601f0c4..9c4e2ae2d7c 100644 --- a/service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml +++ b/service/telemetry/internal/migration/testdata/v0.2.0_metrics.yaml @@ -6,6 +6,7 @@ readers: endpoint: 127.0.0.1:4317 headers: "key1": "value1" + "key2": "value2" - pull: exporter: prometheus: diff --git a/service/telemetry/internal/migration/v0.2.0.go b/service/telemetry/internal/migration/v0.2.0.go index e38a1902bb4..2f1203e4ae9 100644 --- a/service/telemetry/internal/migration/v0.2.0.go +++ b/service/telemetry/internal/migration/v0.2.0.go @@ -37,13 +37,12 @@ type logsConfigV020 struct { } func headersV02ToV03(in configv02.Headers) []config.NameStringValuePair { - headers := make([]config.NameStringValuePair, len(in)) - idx := 0 + headers := make([]config.NameStringValuePair, 0, len(in)) for k, v := range in { - headers[idx] = config.NameStringValuePair{ + headers = append(headers, config.NameStringValuePair{ Name: k, Value: &v, - } + }) } return headers } diff --git a/service/telemetry/internal/migration/v0.2.0_test.go b/service/telemetry/internal/migration/v0.2.0_test.go index 7a296e0d1e6..1d4626444dc 100644 --- a/service/telemetry/internal/migration/v0.2.0_test.go +++ b/service/telemetry/internal/migration/v0.2.0_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" + config "go.opentelemetry.io/contrib/config/v0.3.0" "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/confmap/confmaptest" @@ -58,6 +59,11 @@ func TestUnmarshalMetricsConfigV020(t *testing.T) { 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) + require.ElementsMatch(t, []config.NameStringValuePair{{Name: "key1", Value: ptr("value1")}, {Name: "key2", Value: ptr("value2")}}, cfg.Readers[0].Periodic.Exporter.OTLP.Headers) // ensure defaults set in the original config object are not lost require.Equal(t, configtelemetry.LevelBasic, cfg.Level) } + +func ptr[T any](v T) *T { + return &v +}