Skip to content

Commit

Permalink
[confighttp] add confighttp.NewDefaultServerConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed May 31, 2024
1 parent 4bbb604 commit 2267d43
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
25 changes: 25 additions & 0 deletions .chloggen/newdefaultserverconfig.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: 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]
7 changes: 7 additions & 0 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Check warning on line 288 in config/confighttp/confighttp.go

View check run for this annotation

Codecov / codecov/patch

config/confighttp/confighttp.go#L287-L288

Added lines #L287 - L288 were not covered by tests
}

// ToListener creates a net.Listener.
func (hss *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) {
listener, err := net.Listen("tcp", hss.Endpoint)
Expand Down
6 changes: 3 additions & 3 deletions receiver/otlpreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions receiver/otlpreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2267d43

Please sign in to comment.