middleware

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package middleware contains HTTP middleware functions.

Index

Constants

This section is empty.

Variables

View Source
var WithNoResponseLogging = func(opts Options) Options {
	opts.Logging.Disabled = true
	return opts
}

WithNoResponseLogging disables response logging for a route.

Functions

func Compression

func Compression() mux.MiddlewareFunc

Compression adds suitable response compression based on the client's Accept-Encoding headers.

func Cors

func Cors() mux.MiddlewareFunc

Cors adds CORS headers will be added to all responses.

func Default

func Default(opts Options) []mux.MiddlewareFunc

Default is the default list of middleware functions applied if no middleware functions are set in the HandlerOptions.

func Panic

func Panic(iOpts instrument.Options) mux.MiddlewareFunc

Panic recovers from panics and logs the error/stacktrace if possible.

func PrometheusRangeRewrite

func PrometheusRangeRewrite(opts Options) mux.MiddlewareFunc

PrometheusRangeRewrite is middleware that, when enabled, will rewrite the query parameter on the request (url and body, if present) if it's determined that the query contains a range duration that is less than the resolution that will be used to serve the request. With this middleware disabled, queries like this will return no data. When enabled, the range is updated to be the namespace resolution * a configurable multiple which should allow for data to be returned.

func RequestID

func RequestID(iOpts instrument.Options) mux.MiddlewareFunc

RequestID populates the request scoped logger with a unique request ID.

func ResponseLogging

func ResponseLogging(opts Options) mux.MiddlewareFunc

ResponseLogging logs the response time if the request took longer than the configured threshold.

func ResponseMetrics

func ResponseMetrics(opts Options) mux.MiddlewareFunc

ResponseMetrics records metrics for the http response.

func Source

func Source(opts Options) mux.MiddlewareFunc

Source adds the headers.SourceHeader value to the request context. Installing this middleware function allows application code to access the typed source value using FromContext. Additionally a source log field is added to the request scope logger.

func Tracing

func Tracing(tracer opentracing.Tracer, iOpts instrument.Options) mux.MiddlewareFunc

Tracing applies OpenTracing compatible middleware, which will start a span for each incoming request. Additionally if iOpts is non-nil the trace_id and span_id are added as fields to the request scoped logger.

Types

type Fields

type Fields func(r *http.Request, start time.Time) []zap.Field

Fields returns additional logging fields to add to the response log message.

func (Fields) Append

func (f Fields) Append(other Fields) Fields

Append the provided Fields to these Fields.

type LoggingOptions

type LoggingOptions struct {
	Threshold time.Duration
	Disabled  bool
	Fields    Fields
}

LoggingOptions are the options for the logging middleware.

func NewLoggingOptions

NewLoggingOptions returns new options from the config.

type MetricsOptions

type MetricsOptions struct {
	Config           config.MetricsMiddlewareConfiguration
	ParseQueryParams ParseQueryParams
	ParseOptions     promql.ParseOptions
}

MetricsOptions are the options for the metrics middleware.

type Options

type Options struct {
	// Common options for all middleware functions.
	InstrumentOpts instrument.Options
	Clock          clockwork.Clock
	Route          *mux.Route

	// Specific options for middleware functions.
	Logging                LoggingOptions
	Metrics                MetricsOptions
	Source                 SourceOptions
	PrometheusRangeRewrite PrometheusRangeRewriteOptions
}

Options is the set of parameters passed to the Register function.

type OverrideOptions

type OverrideOptions func(opts Options) Options

OverrideOptions is a function that returns new Options from the provided Options.

type ParseQueryParams

type ParseQueryParams func(r *http.Request, requestStart time.Time) (QueryParams, error)

ParseQueryParams parses the query parameters from the request.

type PrometheusRangeRewriteOptions

type PrometheusRangeRewriteOptions struct {
	Enabled              bool
	FetchOptionsBuilder  handleroptions.FetchOptionsBuilder
	Instant              bool
	ResolutionMultiplier int
	Storage              storage.Storage
}

PrometheusRangeRewriteOptions are the options for the prometheus range rewriting middleware.

type QueryParams

type QueryParams struct {
	Query string
	Start time.Time
	End   time.Time
}

QueryParams are the query request parameters.

func (QueryParams) Range

func (p QueryParams) Range() time.Duration

Range is the time range of the query.

type Register

type Register func(opts Options) []mux.MiddlewareFunc

Register is a func to build the set of middleware functions.

type SourceOptions

type SourceOptions struct {
	Deserializer source.Deserializer
}

SourceOptions are the options for the source middleware.

Jump to

Keyboard shortcuts

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