[exporter/otlp] fix the validation of unix socket endpoint (#13831)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Unix socket endpoints do not have a host:port structure, so port validation should be skipped to prevent unnecessary errors. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #13826 --------- Co-authored-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
This commit is contained in:
parent
4b4e557b86
commit
f729e7b55a
|
|
@ -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: fix the validation of unix socket endpoints
|
||||
|
||||
# One or more tracking issues or pull requests related to the change
|
||||
issues: [13826]
|
||||
|
||||
# (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]
|
||||
|
|
@ -29,6 +29,14 @@ type Config struct {
|
|||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if strings.HasPrefix(c.ClientConfig.Endpoint, "unix://") {
|
||||
path := strings.TrimPrefix(c.ClientConfig.Endpoint, "unix://")
|
||||
if path == "" {
|
||||
return errors.New("unix socket path cannot be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
endpoint := c.sanitizedEndpoint()
|
||||
if endpoint == "" {
|
||||
return errors.New(`requires a non-empty "endpoint"`)
|
||||
|
|
|
|||
|
|
@ -129,6 +129,10 @@ func TestUnmarshalInvalidConfig(t *testing.T) {
|
|||
name: "invalid_port",
|
||||
errorMsg: `invalid port "port"`,
|
||||
},
|
||||
{
|
||||
name: "invalid_unix_socket",
|
||||
errorMsg: "unix socket path cannot be empty",
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := factory.CreateDefaultConfig()
|
||||
|
|
@ -147,6 +151,13 @@ func TestValidDNSEndpoint(t *testing.T) {
|
|||
assert.NoError(t, cfg.Validate())
|
||||
}
|
||||
|
||||
func TestValidUnixSocketEndpoint(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig().(*Config)
|
||||
cfg.ClientConfig.Endpoint = "unix:///my/unix/socket.sock"
|
||||
assert.NoError(t, cfg.Validate())
|
||||
}
|
||||
|
||||
func TestSanitizeEndpoint(t *testing.T) {
|
||||
factory := NewFactory()
|
||||
cfg := factory.CreateDefaultConfig().(*Config)
|
||||
|
|
|
|||
|
|
@ -99,5 +99,17 @@ invalid_port:
|
|||
multiplier: 1.3
|
||||
max_interval: 60s
|
||||
max_elapsed_time: 10m
|
||||
|
||||
|
||||
invalid_unix_socket:
|
||||
endpoint: unix://
|
||||
timeout: 10s
|
||||
sending_queue:
|
||||
enabled: true
|
||||
num_consumers: 2
|
||||
queue_size: 10
|
||||
retry_on_failure:
|
||||
enabled: true
|
||||
initial_interval: 10s
|
||||
randomization_factor: 0.7
|
||||
multiplier: 1.3
|
||||
max_interval: 60s
|
||||
max_elapsed_time: 10m
|
||||
Loading…
Reference in New Issue