From 7fded3a5bd7584e33d8ab7d242b49539dcbf2d2a Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:34:41 -0700 Subject: [PATCH 1/5] [configgrpc] support validation for dns:// and dns:/// This allows users to continue using the recommended dns://authority/host:port notation when needing to specify a custom authority. Fixes #10449 Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- exporter/otlpexporter/config.go | 6 ++++-- exporter/otlpexporter/config_test.go | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/exporter/otlpexporter/config.go b/exporter/otlpexporter/config.go index 62956f293ed..f1d5b668e54 100644 --- a/exporter/otlpexporter/config.go +++ b/exporter/otlpexporter/config.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "net" + "regexp" "strconv" "strings" @@ -49,8 +50,9 @@ func (c *Config) sanitizedEndpoint() string { return strings.TrimPrefix(c.Endpoint, "http://") case strings.HasPrefix(c.Endpoint, "https://"): return strings.TrimPrefix(c.Endpoint, "https://") - case strings.HasPrefix(c.Endpoint, "dns:///"): - return strings.TrimPrefix(c.Endpoint, "dns:///") + case strings.HasPrefix(c.Endpoint, "dns://"): + r := regexp.MustCompile("^dns://[/]?") + return r.ReplaceAllString(c.Endpoint, "") default: return c.Endpoint } diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index 2167f803ef3..a4609ccd3e6 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -134,6 +134,17 @@ func TestUnmarshalInvalidConfig(t *testing.T) { func TestValidDNSEndpoint(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) - cfg.Endpoint = "dns:///backend.example.com:4317" + cfg.Endpoint = "dns://backend.example.com:4317" assert.NoError(t, cfg.Validate()) } + +func TestSanitizeEndpoint(t *testing.T) { + factory := NewFactory() + cfg := factory.CreateDefaultConfig().(*Config) + cfg.Endpoint = "dns://backend.example.com:4317" + assert.Equal(t, "backend.example.com:4317", cfg.sanitizedEndpoint()) + cfg.Endpoint = "dns:///backend.example.com:4317" + assert.Equal(t, "backend.example.com:4317", cfg.sanitizedEndpoint()) + cfg.Endpoint = "dns:////backend.example.com:4317" + assert.Equal(t, "/backend.example.com:4317", cfg.sanitizedEndpoint()) +} From cb90763e3c6c315d19d34a6777336eae9edbf0e1 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:36:46 -0700 Subject: [PATCH 2/5] changelog Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- .../codeboten_remove-additional-slash.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/codeboten_remove-additional-slash.yaml diff --git a/.chloggen/codeboten_remove-additional-slash.yaml b/.chloggen/codeboten_remove-additional-slash.yaml new file mode 100644 index 00000000000..47fe656793e --- /dev/null +++ b/.chloggen/codeboten_remove-additional-slash.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: configgrpc + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Update validation to support both dns:// and dns:/// + +# One or more tracking issues or pull requests related to the change +issues: [10449] + +# (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: [user] From f00600daa59a82e649ff736c6ff85b216a1c61a0 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:50:30 -0700 Subject: [PATCH 3/5] update test Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- exporter/otlpexporter/config_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index a4609ccd3e6..ce51a466e00 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -141,8 +141,8 @@ func TestValidDNSEndpoint(t *testing.T) { func TestSanitizeEndpoint(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) - cfg.Endpoint = "dns://backend.example.com:4317" - assert.Equal(t, "backend.example.com:4317", cfg.sanitizedEndpoint()) + cfg.Endpoint = "dns://authority/backend.example.com:4317" + assert.Equal(t, "authority/backend.example.com:4317", cfg.sanitizedEndpoint()) cfg.Endpoint = "dns:///backend.example.com:4317" assert.Equal(t, "backend.example.com:4317", cfg.sanitizedEndpoint()) cfg.Endpoint = "dns:////backend.example.com:4317" From 2b4d8da7b65dfddad06c41dbc2201ee424102a28 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:00:48 -0700 Subject: [PATCH 4/5] update changelog Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- .chloggen/codeboten_remove-additional-slash.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/codeboten_remove-additional-slash.yaml b/.chloggen/codeboten_remove-additional-slash.yaml index 47fe656793e..72fbe623fdb 100644 --- a/.chloggen/codeboten_remove-additional-slash.yaml +++ b/.chloggen/codeboten_remove-additional-slash.yaml @@ -4,7 +4,7 @@ change_type: bug_fix # The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) -component: configgrpc +component: otlpexporter # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). note: Update validation to support both dns:// and dns:/// From 28f74321273a7acc3a6863aed49855a208819912 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:11:14 -0600 Subject: [PATCH 5/5] Update exporter/otlpexporter/config_test.go --- exporter/otlpexporter/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index ce51a466e00..a29d0182860 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -134,7 +134,7 @@ func TestUnmarshalInvalidConfig(t *testing.T) { func TestValidDNSEndpoint(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig().(*Config) - cfg.Endpoint = "dns://backend.example.com:4317" + cfg.Endpoint = "dns://authority/backend.example.com:4317" assert.NoError(t, cfg.Validate()) }