Skip to content

Commit

Permalink
[chore] Update httpconfig API to not include HTTP prefix (#9453)
Browse files Browse the repository at this point in the history
Following discussion
#9403 (comment)
  • Loading branch information
dmitryax authored Feb 2, 2024
1 parent 26c157e commit 7abb962
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change_type: breaking
component: otlphttpexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: otlphttpexporter.Config embeds the struct confighttp.HTTPClientConfig instead of confighttp.HTTPClientSettings
note: otlphttpexporter.Config embeds the struct confighttp.ClientConfig instead of confighttp.HTTPClientSettings

# One or more tracking issues or pull requests related to the change
issues: [6767]
Expand Down
2 changes: 1 addition & 1 deletion .chloggen/httpclientsettings_httpclientconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change_type: deprecation
component: confighttp

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate HTTPClientSettings, use HTTPClientConfig instead
note: Deprecate HTTPClientSettings, use ClientConfig instead

# One or more tracking issues or pull requests related to the change
issues: [6767]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change_type: breaking
component: otlpreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: HTTPConfig struct is moving from embedding the deprecated HTTPServerSettings struct to using HTTPServerConfig instead.
note: HTTPConfig struct is moving from embedding the deprecated ServerSettings struct to using HTTPServerConfig instead.

# One or more tracking issues or pull requests related to the change
issues: [6767]
Expand Down
2 changes: 1 addition & 1 deletion .chloggen/httpserversettings_httpserverconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change_type: deprecation
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
note: Deprecate HTTPServerSettings, use ServerConfig instead

# One or more tracking issues or pull requests related to the change
issues: [6767]
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestHTTPClientCompression(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, srv.URL, reqBody)
require.NoError(t, err, "failed to create request to test handler")

clientSettings := HTTPClientConfig{
clientSettings := ClientConfig{
Endpoint: srv.URL,
Compression: tt.encoding,
}
Expand Down
40 changes: 20 additions & 20 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
const headerContentEncoding = "Content-Encoding"

// HTTPClientSettings defines settings for creating an HTTP client.
// Deprecated: [v0.94.0] Use HTTPClientConfig instead
type HTTPClientSettings = HTTPClientConfig
// Deprecated: [v0.94.0] Use ClientConfig instead
type HTTPClientSettings = ClientConfig

// HTTPClientConfig defines settings for creating an HTTP client.
type HTTPClientConfig struct {
// ClientConfig defines settings for creating an HTTP client.
type ClientConfig struct {
// The target URL to send data to (e.g.: http://some.url:9411/v1/traces).
Endpoint string `mapstructure:"endpoint"`

Expand Down Expand Up @@ -107,28 +107,28 @@ type HTTPClientConfig struct {
// the default values of 'MaxIdleConns' and 'IdleConnTimeout'.
// Other 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 HTTPClientSettings.
// Deprecated: [v0.94.0] Use NewDefaultHTTPClientConfig instead
func NewDefaultHTTPClientSettings() HTTPClientConfig {
return NewDefaultHTTPClientConfig()
// Deprecated: [v0.94.0] Use NewDefaultClientConfig instead
func NewDefaultHTTPClientSettings() ClientConfig {
return NewDefaultClientConfig()
}

// NewDefaultHTTPClientConfig returns HTTPClientConfig type object with
// NewDefaultClientConfig returns ClientConfig type object with
// the default values of 'MaxIdleConns' and 'IdleConnTimeout'.
// Other 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 HTTPClientConfig.
func NewDefaultHTTPClientConfig() HTTPClientConfig {
// We encourage to use this function to create an object of ClientConfig.
func NewDefaultClientConfig() ClientConfig {
// The default values are taken from the values of 'DefaultTransport' of 'http' package.
maxIdleConns := 100
idleConnTimeout := 90 * time.Second

return HTTPClientConfig{
return ClientConfig{
MaxIdleConns: &maxIdleConns,
IdleConnTimeout: &idleConnTimeout,
}
}

// ToClient creates an HTTP client.
func (hcs *HTTPClientConfig) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
func (hcs *ClientConfig) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig()
if err != nil {
return nil, err
Expand Down Expand Up @@ -257,11 +257,11 @@ func (interceptor *headerRoundTripper) RoundTrip(req *http.Request) (*http.Respo
}

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

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

Expand All @@ -287,7 +287,7 @@ type HTTPServerConfig struct {
}

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

// toServerOptions has options that change the behavior of the HTTP server
// returned by HTTPServerConfig.ToServer().
// returned by ServerConfig.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 HTTPServerConfig.ToServer().
// returned by ServerConfig.ToServer().
type ToServerOption func(opts *toServerOptions)

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

// ToServer creates an http.Server from settings object.
func (hss *HTTPServerConfig) ToServer(host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) {
func (hss *ServerConfig) 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
Loading

0 comments on commit 7abb962

Please sign in to comment.