Skip to content
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_pass-insecure.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: 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: []
8 changes: 6 additions & 2 deletions service/telemetry/internal/migration/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ 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
}
4 changes: 2 additions & 2 deletions service/telemetry/internal/migration/v0.2.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions service/telemetry/internal/migration/v0.2.0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions service/telemetry/internal/migration/v0.3.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions service/telemetry/internal/migration/v0.3.0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Loading