middleware

package
Version: v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 76

Documentation

Overview

Package middleware will measure metrics of different http handler types using a `metrics.Recorder`.

The metrics measured are based on RED and/or Four golden signals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Recorder is the way the metrics will be recorder in the different backends.
	Recorder metrics.Recorder
	// Service is an optional identifier for the metrics, this can be useful if
	// a same service has multiple servers (e.g API, metrics and healthchecks).
	Service string
	// GroupedStatus will group the status label in the form of `\dxx`, for example,
	// 200, 201, and 203 will have the label `code="2xx"`. This impacts on the cardinality
	// of the metrics and also improves the performance of queries that are grouped by
	// status code because there are already aggregated in the metric.
	// By default will be false.
	GroupedStatus bool
	// DisableMeasureSize will disable the recording metrics about the response size,
	// by default measuring size is enabled (`DisableMeasureSize` is false).
	DisableMeasureSize bool
	// DisableMeasureInflight will disable the recording metrics about the inflight requests number,
	// by default measuring inflights is enabled (`DisableMeasureInflight` is false).
	DisableMeasureInflight bool
}

Config is the configuration for the middleware factory.

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware is a service that knows how to measure an HTTP handler by wrapping another handler.

Depending on the framework/library we want to measure, this can change a lot, to abstract the way how we measure on the different libraries, Middleware will recieve a `Reporter` that knows how to get the data the Middleware service needs to measure.

func New

func New(cfg Config) Middleware

New returns the a Middleware service.

func (Middleware) Measure added in v0.7.0

func (m Middleware) Measure(handlerID string, reporter Reporter, next func())

Measure abstracts the HTTP handler implementation by only requesting a reporter, this reporter will return the required data to be measured. it accepts a next function that will be called as the wrapped logic before and after measurement actions.

type Reporter added in v0.7.0

type Reporter interface {
	Method() string
	Context() context.Context
	URLPath() string
	StatusCode() int
	BytesWritten() int64
}

Reporter knows how to report the data to the Middleware so it can measure the different framework/libraries.

Source Files

Directories

Path Synopsis
Package echo is a helper package to get an echo compatible middleware
Package echo is a helper package to get an echo compatible middleware
Package fasthttp is a helper package to get a fasthttp compatible middleware.
Package fasthttp is a helper package to get a fasthttp compatible middleware.
Package gin is a helper package to get a gin compatible middleware.
Package gin is a helper package to get a gin compatible middleware.
Package goji is a helper package to get a goji compatible middleware.
Package goji is a helper package to get a goji compatible middleware.
Package gorestful is a helper package to get a gorestful compatible middleware.
Package gorestful is a helper package to get a gorestful compatible middleware.
Package httprouter is a helper package to get a httprouter compatible middleware.
Package httprouter is a helper package to get a httprouter compatible middleware.
Package negroni is a helper package to get a negroni compatible middleware.
Package negroni is a helper package to get a negroni compatible middleware.
Package std is a helper package to get a standard `http.Handler` compatible middleware.
Package std is a helper package to get a standard `http.Handler` compatible middleware.

Jump to

Keyboard shortcuts

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