diff --git a/.chloggen/newdefaultserverconfig.yaml b/.chloggen/newdefaultserverconfig.yaml new file mode 100644 index 000000000000..2effa96730e8 --- /dev/null +++ b/.chloggen/newdefaultserverconfig.yaml @@ -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: confighttp + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add `confighttp.NewDefaultServerConfig()` to instantiate the default HTTP server configuration + +# One or more tracking issues or pull requests related to the change +issues: [9655] + +# (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: [api] diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index b210fa0dd8df..d594a1d33559 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -281,6 +281,13 @@ type ServerConfig struct { ResponseHeaders map[string]configopaque.String `mapstructure:"response_headers"` } +// NewDefaultServerConfig returns ServerConfig type object with default values. +// Currently, config options are not added as they are initialized with 'zero value' by GoLang as default. +// We encourage to use this function to create an object of ServerConfig. +func NewDefaultServerConfig() ServerConfig { + return ServerConfig{} +} + // ToListener creates a net.Listener. func (hss *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) { listener, err := net.Listen("tcp", hss.Endpoint) diff --git a/receiver/otlpreceiver/factory.go b/receiver/otlpreceiver/factory.go index 4b148c40be31..a3c9f1d5f749 100644 --- a/receiver/otlpreceiver/factory.go +++ b/receiver/otlpreceiver/factory.go @@ -39,6 +39,8 @@ func NewFactory() receiver.Factory { // createDefaultConfig creates the default configuration for receiver. func createDefaultConfig() component.Config { + serverConfig := confighttp.NewDefaultServerConfig() + serverConfig.Endpoint = localhostgate.EndpointForPort(httpPort) return &Config{ Protocols: Protocols{ GRPC: &configgrpc.ServerConfig{ @@ -50,9 +52,7 @@ func createDefaultConfig() component.Config { ReadBufferSize: 512 * 1024, }, HTTP: &HTTPConfig{ - ServerConfig: &confighttp.ServerConfig{ - Endpoint: localhostgate.EndpointForPort(httpPort), - }, + ServerConfig: &serverConfig, TracesURLPath: defaultTracesURLPath, MetricsURLPath: defaultMetricsURLPath, LogsURLPath: defaultLogsURLPath, diff --git a/receiver/otlpreceiver/factory_test.go b/receiver/otlpreceiver/factory_test.go index d844760947f7..4e59c7f17577 100644 --- a/receiver/otlpreceiver/factory_test.go +++ b/receiver/otlpreceiver/factory_test.go @@ -58,10 +58,10 @@ func TestCreateTracesReceiver(t *testing.T) { Transport: confignet.TransportTypeTCP, }, } + defaultServerConfig := confighttp.NewDefaultServerConfig() + defaultServerConfig.Endpoint = testutil.GetAvailableLocalAddress(t) defaultHTTPSettings := &HTTPConfig{ - ServerConfig: &confighttp.ServerConfig{ - Endpoint: testutil.GetAvailableLocalAddress(t), - }, + ServerConfig: &defaultServerConfig, TracesURLPath: defaultTracesURLPath, MetricsURLPath: defaultMetricsURLPath, LogsURLPath: defaultLogsURLPath, @@ -152,10 +152,10 @@ func TestCreateMetricReceiver(t *testing.T) { Transport: confignet.TransportTypeTCP, }, } + defaultServerConfig := confighttp.NewDefaultServerConfig() + defaultServerConfig.Endpoint = testutil.GetAvailableLocalAddress(t) defaultHTTPSettings := &HTTPConfig{ - ServerConfig: &confighttp.ServerConfig{ - Endpoint: testutil.GetAvailableLocalAddress(t), - }, + ServerConfig: &defaultServerConfig, TracesURLPath: defaultTracesURLPath, MetricsURLPath: defaultMetricsURLPath, LogsURLPath: defaultLogsURLPath, @@ -246,10 +246,10 @@ func TestCreateLogReceiver(t *testing.T) { Transport: confignet.TransportTypeTCP, }, } + defaultServerConfig := confighttp.NewDefaultServerConfig() + defaultServerConfig.Endpoint = testutil.GetAvailableLocalAddress(t) defaultHTTPSettings := &HTTPConfig{ - ServerConfig: &confighttp.ServerConfig{ - Endpoint: testutil.GetAvailableLocalAddress(t), - }, + ServerConfig: &defaultServerConfig, TracesURLPath: defaultTracesURLPath, MetricsURLPath: defaultMetricsURLPath, LogsURLPath: defaultLogsURLPath,