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

[receiver/httpcheck] fail fast on endpoint missing scheme #23808

Merged
merged 6 commits into from
Jul 11, 2023
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
24 changes: 24 additions & 0 deletions .chloggen/httpcheck-parse-scheme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix
andrzej-stencel marked this conversation as resolved.
Show resolved Hide resolved

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: receiver/httpcheck

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fail fast on endpoint missing scheme

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [23020]

# (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: |
Previously, when configured with an endpoint without HTTP/HTTPS scheme like "opentelemetry.io",
the receiver would start correctly, but fail to check the endpoint, producing the `httpcheck.error`
metric on every collection interval. After this change, the receiver fails to start, writing
an error log saying that you need to provide a scheme in the endpoint.
12 changes: 6 additions & 6 deletions receiver/httpcheckreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Predefined error responses for configuration validation failures
var (
errMissingEndpoint = errors.New(`"endpoint" must be specified`)
errInvalidEndpoint = errors.New(`"endpoint" must be in the form of <scheme>://<hostname>:<port>`)
errInvalidEndpoint = errors.New(`"endpoint" must be in the form of <scheme>://<hostname>[:<port>]`)
)

// Config defines the configuration for the various elements of the receiver agent.
Expand All @@ -35,11 +35,11 @@ func (cfg *Config) Validate() error {

if cfg.Endpoint == "" {
err = multierr.Append(err, errMissingEndpoint)
}
_, parseErr := url.Parse(cfg.Endpoint)
if parseErr != nil {
wrappedErr := fmt.Errorf("%s: %w", errInvalidEndpoint.Error(), parseErr)
err = multierr.Append(err, wrappedErr)
} else {
_, parseErr := url.ParseRequestURI(cfg.Endpoint)
if parseErr != nil {
err = multierr.Append(err, fmt.Errorf("%s: %w", errInvalidEndpoint.Error(), parseErr))
}
}

return err
Expand Down
13 changes: 12 additions & 1 deletion receiver/httpcheckreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ func TestValidate(t *testing.T) {
fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "invalid://endpoint: 12efg": invalid port ": 12efg" after host`),
),
},
{
desc: "missing scheme",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "www.opentelemetry.io/docs",
},
},
expectedErr: multierr.Combine(
fmt.Errorf("%w: %s", errInvalidEndpoint, `parse "www.opentelemetry.io/docs": invalid URI for request`),
),
},
{
desc: "valid config",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://opentelemetry.io",
Endpoint: "https://opentelemetry.io:80/docs",
andrzej-stencel marked this conversation as resolved.
Show resolved Hide resolved
},
},
expectedErr: nil,
Expand Down