Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[otlpexporter] support validation for dns:https:// and dns:https:/// #10450

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[configgrpc] support validation for dns:https:// and dns:https:///
This allows users to continue using the recommended dns:https://authority/host:port notation
when needing to specify a custom authority.

Fixes #10449

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten committed Jun 20, 2024
commit 7fded3a5bd7584e33d8ab7d242b49539dcbf2d2a
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:https://")
case strings.HasPrefix(c.Endpoint, "https://"):
return strings.TrimPrefix(c.Endpoint, "https://")
case strings.HasPrefix(c.Endpoint, "dns:https:///"):
return strings.TrimPrefix(c.Endpoint, "dns:https:///")
case strings.HasPrefix(c.Endpoint, "dns:https://"):
r := regexp.MustCompile("^dns:https://[/]?")
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:https:///backend.example.com:4317"
cfg.Endpoint = "dns:https://backend.example.com:4317"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid dns endpoint? I though it would need either /// in a row or another / somewhere to separate the authority and the path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a good point, according to the grpc docs, the following is valid:

dns:[//authority/]host[:port] -- DNS (default)

I don't know how much more validation we should be introducing here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new string looks invalid to me, I'm surprised an error is not returned. I'm interpreting the regex as "if // is present, there must be a third /". What am I missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me add a test for this case. i agree that it should return an error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see how this test works now. Currently the validation only checks that there is a port and that it is a valid integer, nothing else. We should add full dns endpoint validation, but since the current functionality breaks users ability to use authorities in their dns endpoint I think we should add that later and merge this now.

For the sake of having a proper endpoint:

Suggested change
cfg.Endpoint = "dns:https://backend.example.com:4317"
cfg.Endpoint = "dns:https://authority/backend.example.com:4317"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created #10488

assert.NoError(t, cfg.Validate())
}

func TestSanitizeEndpoint(t *testing.T) {
codeboten marked this conversation as resolved.
Show resolved Hide resolved
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)
cfg.Endpoint = "dns:https://backend.example.com:4317"
assert.Equal(t, "backend.example.com:4317", cfg.sanitizedEndpoint())
cfg.Endpoint = "dns:https:///backend.example.com:4317"
assert.Equal(t, "backend.example.com:4317", cfg.sanitizedEndpoint())
cfg.Endpoint = "dns:https:////backend.example.com:4317"
assert.Equal(t, "/backend.example.com:4317", cfg.sanitizedEndpoint())
}