confighttp

package
v0.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2021 License: Apache-2.0 Imports: 13 Imported by: 149

README

HTTP Configuration Settings

HTTP exposes a variety of settings. Several of these settings are available for configuration within individual receivers or exporters.

Client Configuration

Exporters leverage client configuration.

Note that client configuration supports TLS configuration, however configuration parameters are not defined under tls_settings like server configuration. For more information, see configtls README.

Example:

exporter:
  otlp:
    endpoint: otelcol2:55690
    headers:
      test1: "value1"
      "test 2": "value 2"

Server Configuration

Receivers leverage server configuration.

  • cors_allowed_origins: An empty list means that CORS is not enabled at all. A wildcard can be used to match any origin or one or more characters of an origin.
  • cors_allowed_headers: When CORS is enabled, can be used to specify an optional list of allowed headers. By default, it includes Accept, Content-Type, X-Requested-With. Origin is also always added to the list. A wildcard (*) can be used to match any header.
  • endpoint: Valid value syntax available here
  • tls_settings

Example:

receivers:
  otlp:
    cors_allowed_origins:
    - https://foo.bar.com
    - https://*.test.com
    cors_allowed_headers:
    - ExampleHeader
    endpoint: 0.0.0.0:55690
    protocols:
      http:

Documentation

Overview

Package confighttp defines the configuration settings for creating an HTTP client and server.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClientSettings

type HTTPClientSettings struct {
	// The target URL to send data to (e.g.: http://some.url:9411/v1/traces).
	Endpoint string `mapstructure:"endpoint"`

	// TLSSetting struct exposes TLS client configuration.
	TLSSetting configtls.TLSClientSetting `mapstructure:",squash"`

	// ReadBufferSize for HTTP client. See http.Transport.ReadBufferSize.
	ReadBufferSize int `mapstructure:"read_buffer_size"`

	// WriteBufferSize for HTTP client. See http.Transport.WriteBufferSize.
	WriteBufferSize int `mapstructure:"write_buffer_size"`

	// Timeout parameter configures `http.Client.Timeout`.
	Timeout time.Duration `mapstructure:"timeout,omitempty"`

	// Additional headers attached to each HTTP request sent by the client.
	// Existing header values are overwritten if collision happens.
	Headers map[string]string `mapstructure:"headers,omitempty"`

	// Custom Round Tripper to allow for individual components to intercept HTTP requests
	CustomRoundTripper func(next http.RoundTripper) (http.RoundTripper, error)

	// Auth configuration for outgoing HTTP calls.
	Auth *configauth.Authentication `mapstructure:"auth,omitempty"`
}

HTTPClientSettings defines settings for creating an HTTP client.

func (*HTTPClientSettings) ToClient

ToClient creates an HTTP client.

type HTTPServerSettings

type HTTPServerSettings struct {
	// Endpoint configures the listening address for the server.
	Endpoint string `mapstructure:"endpoint"`

	// TLSSetting struct exposes TLS client configuration.
	TLSSetting *configtls.TLSServerSetting `mapstructure:"tls_settings, omitempty"`

	// CorsOrigins are the allowed CORS origins for HTTP/JSON requests to grpc-gateway adapter
	// for the OTLP receiver. See github.com/rs/cors
	// An empty list means that CORS is not enabled at all. A wildcard (*) can be
	// used to match any origin or one or more characters of an origin.
	CorsOrigins []string `mapstructure:"cors_allowed_origins"`

	// CorsHeaders are the allowed CORS headers for HTTP/JSON requests to grpc-gateway adapter
	// for the OTLP receiver. See github.com/rs/cors
	// CORS needs to be enabled first by providing a non-empty list in CorsOrigins
	// A wildcard (*) can be used to match any header.
	CorsHeaders []string `mapstructure:"cors_allowed_headers"`
}

HTTPServerSettings defines settings for creating an HTTP server.

Example
settings := HTTPServerSettings{
	Endpoint: ":443",
}
s := settings.ToServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
l, err := settings.ToListener()
if err != nil {
	panic(err)
}
if err = s.Serve(l); err != nil {
	panic(err)
}
Output:

func (*HTTPServerSettings) ToListener

func (hss *HTTPServerSettings) ToListener() (net.Listener, error)

ToListener creates a net.Listener.

func (*HTTPServerSettings) ToServer

func (hss *HTTPServerSettings) ToServer(handler http.Handler, opts ...ToServerOption) *http.Server

ToServer creates an http.Server from settings object.

type ToServerOption added in v0.11.0

type ToServerOption func(opts *toServerOptions)

ToServerOption is an option to change the behavior of the HTTP server returned by HTTPServerSettings.ToServer().

func WithErrorHandler added in v0.11.0

func WithErrorHandler(e middleware.ErrorHandler) ToServerOption

WithErrorHandler overrides the HTTP error handler that gets invoked when there is a failure inside middleware.HTTPContentDecompressor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL