Documentation ¶
Overview ¶
Package middleware contains HTTP middleware functions.
Index ¶
- Variables
- func Compression() mux.MiddlewareFunc
- func Cors() mux.MiddlewareFunc
- func Default(opts Options) []mux.MiddlewareFunc
- func Panic(iOpts instrument.Options) mux.MiddlewareFunc
- func PrometheusRangeRewrite(opts Options) mux.MiddlewareFunc
- func RequestID(iOpts instrument.Options) mux.MiddlewareFunc
- func ResponseLogging(opts Options) mux.MiddlewareFunc
- func ResponseMetrics(opts Options) mux.MiddlewareFunc
- func RewriteRangeDuration(r *http.Request, opts PrometheusRangeRewriteOptions, logger *zap.Logger) error
- func Source(opts Options) mux.MiddlewareFunc
- func Tracing(tracer opentracing.Tracer, iOpts instrument.Options) mux.MiddlewareFunc
- type Fields
- type LoggingOptions
- type MetricsOptions
- type Options
- type OverrideOptions
- type ParseQueryParams
- type PrometheusRangeRewriteOptions
- type QueryParams
- type Register
- type SourceOptions
Constants ¶
This section is empty.
Variables ¶
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 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 RewriteRangeDuration ¶ added in v1.4.0
func RewriteRangeDuration( r *http.Request, opts PrometheusRangeRewriteOptions, logger *zap.Logger, ) error
RewriteRangeDuration is the driver function for the PrometheusRangeRewrite middleware
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 LoggingOptions ¶
LoggingOptions are the options for the logging middleware.
func NewLoggingOptions ¶
func NewLoggingOptions(c config.LoggingMiddlewareConfiguration) LoggingOptions
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 ¶
OverrideOptions is a function that returns new Options from the provided Options.
type ParseQueryParams ¶
ParseQueryParams parses the query parameters from the request.
type PrometheusRangeRewriteOptions ¶
type PrometheusRangeRewriteOptions struct { Enabled bool FetchOptionsBuilder handleroptions.FetchOptionsBuilder Instant bool ResolutionMultiplier int DefaultLookback time.Duration Storage storage.Storage // TODO(marcus): There's a conversation with Prometheus about supporting dynamic lookback. // We can replace this with a single engine reference if that work is ever completed. // https://groups.google.com/g/prometheus-developers/c/9wzuobfLMV8 PrometheusEngineFn func(time.Duration) (*promql.Engine, error) }
PrometheusRangeRewriteOptions are the options for the prometheus range rewriting middleware.
type QueryParams ¶
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.