Skip to content

Commit

Permalink
[otlpexporter] support validation for dns:// and dns:/// (#10450)
Browse files Browse the repository at this point in the history
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>
Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
  • Loading branch information
codeboten and TylerHelmuth authored Jul 1, 2024
1 parent ee4eb85 commit fd36d05
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .chloggen/codeboten_remove-additional-slash.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: 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:///

# 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]
6 changes: 4 additions & 2 deletions exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"net"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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://authority/backend.example.com:4317"
assert.NoError(t, cfg.Validate())
}

func TestSanitizeEndpoint(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
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"
assert.Equal(t, "/backend.example.com:4317", cfg.sanitizedEndpoint())
}

0 comments on commit fd36d05

Please sign in to comment.