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] remove default endpoint #23018

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions .chloggen/httpcheck-endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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: 'breaking'

# 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: Removed the default `endpoint` value of `http://localhost:80`. The `endpoint` property is now required.

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

# (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:
6 changes: 4 additions & 2 deletions receiver/httpcheckreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ 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>`)
)

const defaultEndpoint = "http://localhost:80"

// Config defines the configuration for the various elements of the receiver agent.
type Config struct {
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
Expand All @@ -34,6 +33,9 @@ type Config struct {
func (cfg *Config) Validate() error {
var err 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)
Expand Down
11 changes: 10 additions & 1 deletion receiver/httpcheckreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ func TestValidate(t *testing.T) {
cfg *Config
expectedErr error
}{
{
desc: "missing endpoint",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{},
},
expectedErr: multierr.Combine(
errMissingEndpoint,
),
},
{
desc: "invalid endpoint",
cfg: &Config{
Expand All @@ -34,7 +43,7 @@ func TestValidate(t *testing.T) {
desc: "valid config",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: defaultEndpoint,
Endpoint: "https://opentelemetry.io",
},
},
expectedErr: nil,
Expand Down
12 changes: 6 additions & 6 deletions receiver/httpcheckreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func createDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
cfg.CollectionInterval = 10 * time.Second

httpSettings := confighttp.NewDefaultHTTPClientSettings()
httpSettings.Timeout = 10 * time.Second

return &Config{
ScraperControllerSettings: cfg,
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: defaultEndpoint,
Timeout: 10 * time.Second,
},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Method: "GET",
HTTPClientSettings: httpSettings,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Method: "GET",
}
}

Expand Down
10 changes: 5 additions & 5 deletions receiver/httpcheckreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ func TestNewFactory(t *testing.T) {
},
},
{
desc: "creates a new factory with valid default config",
desc: "creates a new factory with default config",
testFunc: func(t *testing.T) {
factory := NewFactory()

httpSettings := confighttp.NewDefaultHTTPClientSettings()
httpSettings.Timeout = 10 * time.Second

var expectedCfg component.Config = &Config{
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
CollectionInterval: 10 * time.Second,
},
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: defaultEndpoint,
Timeout: 10 * time.Second,
},
HTTPClientSettings: httpSettings,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Method: "GET",
}
Expand Down
4 changes: 2 additions & 2 deletions receiver/httpcheckreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestScraperStart(t *testing.T) {
scraper: &httpcheckScraper{
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: defaultEndpoint,
Endpoint: "http://example.com",
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
CAFile: "/non/existent",
Expand All @@ -60,7 +60,7 @@ func TestScraperStart(t *testing.T) {
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
TLSSetting: configtls.TLSClientSetting{},
Endpoint: defaultEndpoint,
Endpoint: "http://example.com",
},
},
settings: componenttest.NewNopTelemetrySettings(),
Expand Down