middle

package
v1.25.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MetricsPrefix for metrics namespace
	MetricsPrefix = "bkbcs_storage"
)

Variables

This section is empty.

Functions

func MetricsMiddleHandler

func MetricsMiddleHandler(m Middleware) gorestful.FilterFunction

MetricsMiddleHandler returns a go-restful metrics report middleware.

Types

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.

func New

func New(cfg Options) Middleware

New returns the a Middleware service.

func (Middleware) Measure

func (m Middleware) Measure(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 Options

type Options struct {
	// Recorder is the way the metrics will be recorder in the different backends.
	Recorder metrics.Recorder

	// GroupedStatus will group the status label in the form of `\dxx`. default will be false.
	GroupedStatus bool
	// DisableMeasureSize will disable the recording metrics about the response size.
	DisableMeasureSize bool
	// DisableMeasureInflight will disable the recording metrics about the inflight requests number.
	DisableMeasureInflight bool
}

Options is the configuration for the middleware factory.

type Reporter

type Reporter interface {
	// Method() return request method(POST、PUT、DELETE、GET)
	Method() string
	// Context() get request context for context values
	Context() context.Context
	// URLPath() return url path
	URLPath() string
	// StatusCode() return response status code
	StatusCode() int
	// BytesWritten() return resp body length
	BytesWritten() int64
	// GetReq() get gorestful request
	GetReq() *gorestful.Request
	// RoutePath() return router url
	RoutePath() string
}

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

Jump to

Keyboard shortcuts

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