From 696510268d477e2b39de8b0f61df9fa8e44137f6 Mon Sep 17 00:00:00 2001 From: alex boten <223565+codeboten@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:11:59 -0700 Subject: [PATCH 1/3] [service] ensure insecure config is taken into consideration This updates the function that normalizes the endpoint to consider the setting for `insecure` when prefixing the endpoint. Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com> --- service/telemetry/internal/migration/normalize.go | 9 +++++++-- service/telemetry/internal/migration/v0.2.0.go | 4 ++-- service/telemetry/internal/migration/v0.3.0.go | 10 +++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/service/telemetry/internal/migration/normalize.go b/service/telemetry/internal/migration/normalize.go index 2e1fd8b7f354..269290628edf 100644 --- a/service/telemetry/internal/migration/normalize.go +++ b/service/telemetry/internal/migration/normalize.go @@ -5,9 +5,14 @@ package migration // import "go.opentelemetry.io/collector/service/telemetry/int import "strings" -func normalizeEndpoint(endpoint string) *string { +func normalizeEndpoint(endpoint string, insecure *bool) *string { if !strings.HasPrefix(endpoint, "https://") && !strings.HasPrefix(endpoint, "http://") { - endpoint = "http://" + endpoint + if insecure != nil && *insecure { + endpoint = "http://" + endpoint + } else { + endpoint = "https://" + endpoint + } + } return &endpoint } diff --git a/service/telemetry/internal/migration/v0.2.0.go b/service/telemetry/internal/migration/v0.2.0.go index b40742315a6a..094b37a357b3 100644 --- a/service/telemetry/internal/migration/v0.2.0.go +++ b/service/telemetry/internal/migration/v0.2.0.go @@ -55,7 +55,7 @@ func otlpV02ToV03(in *configv02.OTLP) *config.OTLP { ClientCertificate: in.ClientCertificate, ClientKey: in.ClientKey, Compression: in.Compression, - Endpoint: normalizeEndpoint(in.Endpoint), + Endpoint: normalizeEndpoint(in.Endpoint, in.Insecure), Insecure: in.Insecure, Protocol: &in.Protocol, Timeout: in.Timeout, @@ -72,7 +72,7 @@ func otlpMetricV02ToV03(in *configv02.OTLPMetric) *config.OTLPMetric { ClientCertificate: in.ClientCertificate, ClientKey: in.ClientKey, Compression: in.Compression, - Endpoint: normalizeEndpoint(in.Endpoint), + Endpoint: normalizeEndpoint(in.Endpoint, in.Insecure), Insecure: in.Insecure, Protocol: &in.Protocol, Timeout: in.Timeout, diff --git a/service/telemetry/internal/migration/v0.3.0.go b/service/telemetry/internal/migration/v0.3.0.go index 56941f2ae13e..6a1415cc753e 100644 --- a/service/telemetry/internal/migration/v0.3.0.go +++ b/service/telemetry/internal/migration/v0.3.0.go @@ -46,12 +46,12 @@ func (c *TracesConfigV030) Unmarshal(conf *confmap.Conf) error { for _, r := range c.Processors { if r.Batch != nil { if r.Batch.Exporter.OTLP != nil { - r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint) + r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure) } } if r.Simple != nil { if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil { - r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint) + r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure) } } } @@ -88,7 +88,7 @@ func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error { for _, r := range c.Readers { if r.Periodic != nil { if r.Periodic.Exporter.OTLP != nil && r.Periodic.Exporter.OTLP.Endpoint != nil { - r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint) + r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint, r.Periodic.Exporter.OTLP.Insecure) } } } @@ -206,12 +206,12 @@ func (c *LogsConfigV030) Unmarshal(conf *confmap.Conf) error { for _, r := range c.Processors { if r.Batch != nil { if r.Batch.Exporter.OTLP != nil { - r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint) + r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure) } } if r.Simple != nil { if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil { - r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint) + r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure) } } } From 8053845a32afcfd2bf1429dc4dd2dbbcacac0138 Mon Sep 17 00:00:00 2001 From: alex boten <223565+codeboten@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:15:17 -0700 Subject: [PATCH 2/3] changelog Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com> --- .chloggen/codeboten_pass-insecure.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/codeboten_pass-insecure.yaml diff --git a/.chloggen/codeboten_pass-insecure.yaml b/.chloggen/codeboten_pass-insecure.yaml new file mode 100644 index 000000000000..adeb90b26473 --- /dev/null +++ b/.chloggen/codeboten_pass-insecure.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: Ensure the insecure configuration is accounted for when normalizing the endpoint. + +# One or more tracking issues or pull requests related to the change +issues: [13691] + +# (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: [] From 71ffc8a31e910cfe6a1f38ca1f21af27d9ad5781 Mon Sep 17 00:00:00 2001 From: alex boten <223565+codeboten@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:38:17 -0700 Subject: [PATCH 3/3] fix tests Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com> --- service/telemetry/internal/migration/normalize.go | 1 - service/telemetry/internal/migration/v0.2.0_test.go | 12 ++++++------ service/telemetry/internal/migration/v0.3.0_test.go | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/service/telemetry/internal/migration/normalize.go b/service/telemetry/internal/migration/normalize.go index 269290628edf..1f7ff8dfa8de 100644 --- a/service/telemetry/internal/migration/normalize.go +++ b/service/telemetry/internal/migration/normalize.go @@ -12,7 +12,6 @@ func normalizeEndpoint(endpoint string, insecure *bool) *string { } else { endpoint = "https://" + endpoint } - } return &endpoint } diff --git a/service/telemetry/internal/migration/v0.2.0_test.go b/service/telemetry/internal/migration/v0.2.0_test.go index 868becfa4fc7..2ff2ec0ffa3f 100644 --- a/service/telemetry/internal/migration/v0.2.0_test.go +++ b/service/telemetry/internal/migration/v0.2.0_test.go @@ -23,8 +23,8 @@ func TestUnmarshalLogsConfigV020(t *testing.T) { } 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/ https + require.Equal(t, "https://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 @@ -40,8 +40,8 @@ func TestUnmarshalTracesConfigV020(t *testing.T) { } 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/ https + require.Equal(t, "https://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 @@ -57,8 +57,8 @@ func TestUnmarshalMetricsConfigV020(t *testing.T) { } 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) + // check the endpoint is prefixed w/ https + require.Equal(t, "https://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) diff --git a/service/telemetry/internal/migration/v0.3.0_test.go b/service/telemetry/internal/migration/v0.3.0_test.go index 782ab6bfd642..0de420c9c780 100644 --- a/service/telemetry/internal/migration/v0.3.0_test.go +++ b/service/telemetry/internal/migration/v0.3.0_test.go @@ -19,8 +19,8 @@ func TestUnmarshalLogsConfigV030(t *testing.T) { cfg := LogsConfigV030{} 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/ https + require.Equal(t, "https://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) } @@ -32,8 +32,8 @@ func TestUnmarshalTracesConfigV030(t *testing.T) { cfg := TracesConfigV030{} 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/ https + require.Equal(t, "https://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) } @@ -46,6 +46,6 @@ func TestUnmarshalMetricsConfigV030(t *testing.T) { 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) + // check the endpoint is prefixed w/ https + require.Equal(t, "https://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint) }