Skip to content

Commit 4b5e356

Browse files
authored
[service] ensure insecure config is taken into consideration (#13691)
This updates the function that normalizes the endpoint to consider the setting for `insecure` when prefixing the endpoint. Fixes #13690 --------- Signed-off-by: alex boten <[email protected]>
1 parent 8475824 commit 4b5e356

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed
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: Ensure the insecure configuration is accounted for when normalizing the endpoint.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [13691]
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/normalize.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ package migration // import "go.opentelemetry.io/collector/service/telemetry/int
55

66
import "strings"
77

8-
func normalizeEndpoint(endpoint string) *string {
8+
func normalizeEndpoint(endpoint string, insecure *bool) *string {
99
if !strings.HasPrefix(endpoint, "https://") && !strings.HasPrefix(endpoint, "http://") {
10-
endpoint = "http://" + endpoint
10+
if insecure != nil && *insecure {
11+
endpoint = "http://" + endpoint
12+
} else {
13+
endpoint = "https://" + endpoint
14+
}
1115
}
1216
return &endpoint
1317
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func otlpV02ToV03(in *configv02.OTLP) *config.OTLP {
5555
ClientCertificate: in.ClientCertificate,
5656
ClientKey: in.ClientKey,
5757
Compression: in.Compression,
58-
Endpoint: normalizeEndpoint(in.Endpoint),
58+
Endpoint: normalizeEndpoint(in.Endpoint, in.Insecure),
5959
Insecure: in.Insecure,
6060
Protocol: &in.Protocol,
6161
Timeout: in.Timeout,
@@ -72,7 +72,7 @@ func otlpMetricV02ToV03(in *configv02.OTLPMetric) *config.OTLPMetric {
7272
ClientCertificate: in.ClientCertificate,
7373
ClientKey: in.ClientKey,
7474
Compression: in.Compression,
75-
Endpoint: normalizeEndpoint(in.Endpoint),
75+
Endpoint: normalizeEndpoint(in.Endpoint, in.Insecure),
7676
Insecure: in.Insecure,
7777
Protocol: &in.Protocol,
7878
Timeout: in.Timeout,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestUnmarshalLogsConfigV020(t *testing.T) {
2323
}
2424
require.NoError(t, cm.Unmarshal(&cfg))
2525
require.Len(t, cfg.Processors, 3)
26-
// check the endpoint is prefixed w/ http
27-
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
26+
// check the endpoint is prefixed w/ https
27+
require.Equal(t, "https://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
2828
// check the endpoint is prefixed w/ http
2929
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
3030
// ensure defaults set in the original config object are not lost
@@ -40,8 +40,8 @@ func TestUnmarshalTracesConfigV020(t *testing.T) {
4040
}
4141
require.NoError(t, cm.Unmarshal(&cfg))
4242
require.Len(t, cfg.Processors, 3)
43-
// check the endpoint is prefixed w/ http
44-
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
43+
// check the endpoint is prefixed w/ https
44+
require.Equal(t, "https://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
4545
// check the endpoint is prefixed w/ http
4646
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
4747
// ensure defaults set in the original config object are not lost
@@ -57,8 +57,8 @@ func TestUnmarshalMetricsConfigV020(t *testing.T) {
5757
}
5858
require.NoError(t, cm.Unmarshal(&cfg))
5959
require.Len(t, cfg.Readers, 2)
60-
// check the endpoint is prefixed w/ http
61-
require.Equal(t, "http://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
60+
// check the endpoint is prefixed w/ https
61+
require.Equal(t, "https://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
6262
require.ElementsMatch(t, []config.NameStringValuePair{{Name: "key1", Value: ptr("value1")}, {Name: "key2", Value: ptr("value2")}}, cfg.Readers[0].Periodic.Exporter.OTLP.Headers)
6363
// ensure defaults set in the original config object are not lost
6464
require.Equal(t, configtelemetry.LevelBasic, cfg.Level)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func (c *TracesConfigV030) Unmarshal(conf *confmap.Conf) error {
4646
for _, r := range c.Processors {
4747
if r.Batch != nil {
4848
if r.Batch.Exporter.OTLP != nil {
49-
r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint)
49+
r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure)
5050
}
5151
}
5252
if r.Simple != nil {
5353
if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil {
54-
r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint)
54+
r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure)
5555
}
5656
}
5757
}
@@ -88,7 +88,7 @@ func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error {
8888
for _, r := range c.Readers {
8989
if r.Periodic != nil {
9090
if r.Periodic.Exporter.OTLP != nil && r.Periodic.Exporter.OTLP.Endpoint != nil {
91-
r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint)
91+
r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint, r.Periodic.Exporter.OTLP.Insecure)
9292
}
9393
}
9494
}
@@ -206,12 +206,12 @@ func (c *LogsConfigV030) Unmarshal(conf *confmap.Conf) error {
206206
for _, r := range c.Processors {
207207
if r.Batch != nil {
208208
if r.Batch.Exporter.OTLP != nil {
209-
r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint)
209+
r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure)
210210
}
211211
}
212212
if r.Simple != nil {
213213
if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil {
214-
r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint)
214+
r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure)
215215
}
216216
}
217217
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestUnmarshalLogsConfigV030(t *testing.T) {
1919
cfg := LogsConfigV030{}
2020
require.NoError(t, cm.Unmarshal(&cfg))
2121
require.Len(t, cfg.Processors, 3)
22-
// check the endpoint is prefixed w/ http
23-
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
22+
// check the endpoint is prefixed w/ https
23+
require.Equal(t, "https://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
2424
// check the endpoint is prefixed w/ http
2525
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
2626
}
@@ -32,8 +32,8 @@ func TestUnmarshalTracesConfigV030(t *testing.T) {
3232
cfg := TracesConfigV030{}
3333
require.NoError(t, cm.Unmarshal(&cfg))
3434
require.Len(t, cfg.Processors, 3)
35-
// check the endpoint is prefixed w/ http
36-
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
35+
// check the endpoint is prefixed w/ https
36+
require.Equal(t, "https://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
3737
// check the endpoint is prefixed w/ http
3838
require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
3939
}
@@ -46,6 +46,6 @@ func TestUnmarshalMetricsConfigV030(t *testing.T) {
4646
require.NoError(t, cm.Unmarshal(&cfg))
4747
require.Len(t, cfg.Readers, 2)
4848

49-
// check the endpoint is prefixed w/ http
50-
require.Equal(t, "http://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
49+
// check the endpoint is prefixed w/ https
50+
require.Equal(t, "https://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
5151
}

0 commit comments

Comments
 (0)