Skip to content

Commit

Permalink
Add validation to the otlp exporter config to fail fast if no port is…
Browse files Browse the repository at this point in the history
… defeined in the endpoint. Add additional unit test data for this case.
  • Loading branch information
atmask committed Feb 27, 2024
1 parent 62beec3 commit f3c3672
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .chloggen/validate-otlpexporter-port.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: enhancement

# 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: Checks for port in the config validation for the otlpexporter

# One or more tracking issues or pull requests related to the change
issues: [9505]

# (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: []
11 changes: 10 additions & 1 deletion exporter/otlpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexpor

import (
"errors"
"net"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
Expand All @@ -22,9 +23,17 @@ type Config struct {
}

func (c *Config) Validate() error {
if c.SanitizedEndpoint() == "" {
endpoint := c.SanitizedEndpoint()
if endpoint == "" {
return errors.New(`requires a non-empty "endpoint"`)
}

// Validate that the port is in the address
_, _, err := net.SplitHostPort(endpoint)
if err != nil {
return err
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func TestUnmarshalInvalidConfig(t *testing.T) {
name: "invalid_retry",
errorMsg: `'randomization_factor' must be within [0, 1]`,
},
{
name: "missing_port",
errorMsg: `missing port in address`,
},
} {
t.Run(test.name, func(t *testing.T) {
cfg := factory.CreateDefaultConfig()
Expand Down
16 changes: 16 additions & 0 deletions exporter/otlpexporter/testdata/invalid_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ invalid_retry:
multiplier: 1.3
max_interval: 60s
max_elapsed_time: 10m
missing_port:
endpoint: example.com
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


0 comments on commit f3c3672

Please sign in to comment.