Skip to content

Commit

Permalink
[confighttp] Deprecate HTTPServerSettings, use HTTPServerConfig inste…
Browse files Browse the repository at this point in the history
…ad (#9405)

**Description:**
Deprecate HTTPServerSettings, use HTTPServerConfig instead

**Link to tracking Issue:**
#6767
  • Loading branch information
atoulme committed Jan 26, 2024
1 parent 9082cb1 commit 8b95295
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 41 deletions.
25 changes: 25 additions & 0 deletions .chloggen/httpserversettings_httpserverconfig.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: deprecation

# 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: Deprecate HTTPServerSettings, use HTTPServerConfig instead

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

# (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]
14 changes: 9 additions & 5 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ func (interceptor *headerRoundTripper) RoundTrip(req *http.Request) (*http.Respo
}

// HTTPServerSettings defines settings for creating an HTTP server.
type HTTPServerSettings struct {
// Deprecated: [v0.94.0] Use HTTPServerConfig instead
type HTTPServerSettings = HTTPServerConfig

// HTTPServerConfig defines settings for creating an HTTP server.
type HTTPServerConfig struct {
// Endpoint configures the listening address for the server.
Endpoint string `mapstructure:"endpoint"`

Expand All @@ -270,7 +274,7 @@ type HTTPServerSettings struct {
}

// ToListener creates a net.Listener.
func (hss *HTTPServerSettings) ToListener() (net.Listener, error) {
func (hss *HTTPServerConfig) ToListener() (net.Listener, error) {
listener, err := net.Listen("tcp", hss.Endpoint)
if err != nil {
return nil, err
Expand All @@ -289,14 +293,14 @@ func (hss *HTTPServerSettings) ToListener() (net.Listener, error) {
}

// toServerOptions has options that change the behavior of the HTTP server
// returned by HTTPServerSettings.ToServer().
// returned by HTTPServerConfig.ToServer().
type toServerOptions struct {
errHandler func(w http.ResponseWriter, r *http.Request, errorMsg string, statusCode int)
decoders map[string]func(body io.ReadCloser) (io.ReadCloser, error)
}

// ToServerOption is an option to change the behavior of the HTTP server
// returned by HTTPServerSettings.ToServer().
// returned by HTTPServerConfig.ToServer().
type ToServerOption func(opts *toServerOptions)

// WithErrorHandler overrides the HTTP error handler that gets invoked
Expand All @@ -319,7 +323,7 @@ func WithDecoder(key string, dec func(body io.ReadCloser) (io.ReadCloser, error)
}

// ToServer creates an http.Server from settings object.
func (hss *HTTPServerSettings) ToServer(host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) {
func (hss *HTTPServerConfig) ToServer(host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) {
internal.WarnOnUnspecifiedHost(settings.Logger, hss.Endpoint)

serverOpts := &toServerOptions{}
Expand Down
38 changes: 19 additions & 19 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {

func TestHTTPServerSettingsError(t *testing.T) {
tests := []struct {
settings HTTPServerSettings
settings HTTPServerConfig
err string
}{
{
err: "^failed to load TLS config: failed to load CA CertPool File: failed to load cert /doesnt/exist:",
settings: HTTPServerSettings{
settings: HTTPServerConfig{
Endpoint: "localhost:0",
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Expand All @@ -495,7 +495,7 @@ func TestHTTPServerSettingsError(t *testing.T) {
},
{
err: "^failed to load TLS config: failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither",
settings: HTTPServerSettings{
settings: HTTPServerConfig{
Endpoint: "localhost:0",
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Expand All @@ -506,7 +506,7 @@ func TestHTTPServerSettingsError(t *testing.T) {
},
{
err: "failed to load client CA CertPool: failed to load CA /doesnt/exist:",
settings: HTTPServerSettings{
settings: HTTPServerConfig{
Endpoint: "localhost:0",
TLSSetting: &configtls.TLSServerSetting{
ClientCAFile: "/doesnt/exist",
Expand All @@ -525,17 +525,17 @@ func TestHTTPServerSettingsError(t *testing.T) {
func TestHTTPServerWarning(t *testing.T) {
tests := []struct {
name string
settings HTTPServerSettings
settings HTTPServerConfig
len int
}{
{
settings: HTTPServerSettings{
settings: HTTPServerConfig{
Endpoint: "0.0.0.0:0",
},
len: 1,
},
{
settings: HTTPServerSettings{
settings: HTTPServerConfig{
Endpoint: "127.0.0.1:0",
},
len: 0,
Expand Down Expand Up @@ -686,7 +686,7 @@ func TestHttpReception(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
hss := &HTTPServerSettings{
hss := &HTTPServerConfig{
Endpoint: "localhost:0",
TLSSetting: tt.tlsServerCreds,
}
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestHttpCors(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
hss := &HTTPServerSettings{
hss := &HTTPServerConfig{
Endpoint: "localhost:0",
CORS: tt.CORSConfig,
}
Expand Down Expand Up @@ -840,7 +840,7 @@ func TestHttpCors(t *testing.T) {
}

func TestHttpCorsInvalidSettings(t *testing.T) {
hss := &HTTPServerSettings{
hss := &HTTPServerConfig{
Endpoint: "localhost:0",
CORS: &CORSConfig{AllowedHeaders: []string{"some-header"}},
}
Expand All @@ -856,7 +856,7 @@ func TestHttpCorsInvalidSettings(t *testing.T) {
}

func TestHttpCorsWithSettings(t *testing.T) {
hss := &HTTPServerSettings{
hss := &HTTPServerConfig{
Endpoint: "localhost:0",
CORS: &CORSConfig{
AllowedOrigins: []string{"*"},
Expand Down Expand Up @@ -914,7 +914,7 @@ func TestHttpServerHeaders(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
hss := &HTTPServerSettings{
hss := &HTTPServerConfig{
Endpoint: "localhost:0",
ResponseHeaders: tt.headers,
}
Expand Down Expand Up @@ -1002,7 +1002,7 @@ func verifyHeadersResp(t *testing.T, url string, expected map[string]configopaqu
}

func ExampleHTTPServerSettings() {
settings := HTTPServerSettings{
settings := HTTPServerConfig{
Endpoint: "localhost:443",
}
s, err := settings.ToServer(
Expand Down Expand Up @@ -1125,7 +1125,7 @@ func TestContextWithClient(t *testing.T) {
func TestServerAuth(t *testing.T) {
// prepare
authCalled := false
hss := HTTPServerSettings{
hss := HTTPServerConfig{
Endpoint: "localhost:0",
Auth: &configauth.Authentication{
AuthenticatorID: component.NewID("mock"),
Expand Down Expand Up @@ -1160,7 +1160,7 @@ func TestServerAuth(t *testing.T) {
}

func TestInvalidServerAuth(t *testing.T) {
hss := HTTPServerSettings{
hss := HTTPServerConfig{
Auth: &configauth.Authentication{
AuthenticatorID: component.NewID("non-existing"),
},
Expand All @@ -1173,7 +1173,7 @@ func TestInvalidServerAuth(t *testing.T) {

func TestFailedServerAuth(t *testing.T) {
// prepare
hss := HTTPServerSettings{
hss := HTTPServerConfig{
Endpoint: "localhost:0",
Auth: &configauth.Authentication{
AuthenticatorID: component.NewID("mock"),
Expand Down Expand Up @@ -1203,7 +1203,7 @@ func TestFailedServerAuth(t *testing.T) {

func TestServerWithErrorHandler(t *testing.T) {
// prepare
hss := HTTPServerSettings{
hss := HTTPServerConfig{
Endpoint: "localhost:0",
}
eh := func(w http.ResponseWriter, r *http.Request, errorMsg string, statusCode int) {
Expand Down Expand Up @@ -1234,7 +1234,7 @@ func TestServerWithErrorHandler(t *testing.T) {

func TestServerWithDecoder(t *testing.T) {
// prepare
hss := HTTPServerSettings{
hss := HTTPServerConfig{
Endpoint: "localhost:0",
}
decoder := func(body io.ReadCloser) (io.ReadCloser, error) {
Expand Down Expand Up @@ -1312,7 +1312,7 @@ func BenchmarkHttpRequest(b *testing.B) {
ServerName: "localhost",
}

hss := &HTTPServerSettings{
hss := &HTTPServerConfig{
Endpoint: "localhost:0",
TLSSetting: tlsServerCreds,
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
)

type HTTPConfig struct {
*confighttp.HTTPServerSettings `mapstructure:",squash"`
*confighttp.HTTPServerConfig `mapstructure:",squash"`

// The URL path to receive traces on. If omitted "/v1/traces" will be used.
TracesURLPath string `mapstructure:"traces_url_path,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestUnmarshalConfig(t *testing.T) {
},
},
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "0.0.0.0:4318",
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestUnmarshalConfigUnix(t *testing.T) {
ReadBufferSize: 512 * 1024,
},
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "/tmp/http_otlp.sock",
},
TracesURLPath: defaultTracesURLPath,
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func createDefaultConfig() component.Config {
ReadBufferSize: 512 * 1024,
},
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: localhostgate.EndpointForPort(httpPort),
},
TracesURLPath: defaultTracesURLPath,
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 @@ -59,7 +59,7 @@ func TestCreateTracesReceiver(t *testing.T) {
},
}
defaultHTTPSettings := &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: testutil.GetAvailableLocalAddress(t),
},
TracesURLPath: defaultTracesURLPath,
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestCreateTracesReceiver(t *testing.T) {
Protocols: Protocols{
GRPC: defaultGRPCSettings,
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "localhost:112233",
},
TracesURLPath: defaultTracesURLPath,
Expand All @@ -122,7 +122,7 @@ func TestCreateTracesReceiver(t *testing.T) {
Protocols: Protocols{
GRPC: defaultGRPCSettings,
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "127.0.0.1:1122",
},
},
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestCreateMetricReceiver(t *testing.T) {
},
}
defaultHTTPSettings := &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: testutil.GetAvailableLocalAddress(t),
},
TracesURLPath: defaultTracesURLPath,
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestCreateMetricReceiver(t *testing.T) {
Protocols: Protocols{
GRPC: defaultGRPCSettings,
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "327.0.0.1:1122",
},
MetricsURLPath: defaultMetricsURLPath,
Expand All @@ -232,7 +232,7 @@ func TestCreateMetricReceiver(t *testing.T) {
Protocols: Protocols{
GRPC: defaultGRPCSettings,
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "127.0.0.1:1122",
},
},
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestCreateLogReceiver(t *testing.T) {
},
}
defaultHTTPSettings := &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: testutil.GetAvailableLocalAddress(t),
},
TracesURLPath: defaultTracesURLPath,
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestCreateLogReceiver(t *testing.T) {
Protocols: Protocols{
GRPC: defaultGRPCSettings,
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "327.0.0.1:1122",
},
LogsURLPath: defaultLogsURLPath,
Expand All @@ -341,7 +341,7 @@ func TestCreateLogReceiver(t *testing.T) {
Protocols: Protocols{
GRPC: defaultGRPCSettings,
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: "127.0.0.1:1122",
},
},
Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func (r *otlpReceiver) startHTTPServer(host component.Host) error {
return err
}

r.settings.Logger.Info("Starting HTTP server", zap.String("endpoint", r.cfg.HTTP.HTTPServerSettings.Endpoint))
r.settings.Logger.Info("Starting HTTP server", zap.String("endpoint", r.cfg.HTTP.HTTPServerConfig.Endpoint))
var hln net.Listener
if hln, err = r.cfg.HTTP.HTTPServerSettings.ToListener(); err != nil {
if hln, err = r.cfg.HTTP.HTTPServerConfig.ToListener(); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func TestHTTPInvalidTLSCredentials(t *testing.T) {
cfg := &Config{
Protocols: Protocols{
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: testutil.GetAvailableLocalAddress(t),
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Expand Down Expand Up @@ -732,7 +732,7 @@ func testHTTPMaxRequestBodySize(t *testing.T, path string, contentType string, p
cfg := &Config{
Protocols: Protocols{
HTTP: &HTTPConfig{
HTTPServerSettings: &confighttp.HTTPServerSettings{
HTTPServerConfig: &confighttp.HTTPServerConfig{
Endpoint: addr,
MaxRequestBodySize: int64(size),
},
Expand Down

0 comments on commit 8b95295

Please sign in to comment.