metricsmiddleware

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustNew

func MustNew(c Config) endpoint.Middleware

MustNew returns a new metrics middleware but panics in case of error.

func New

func New(c Config) (endpoint.Middleware, error)

New returns a new metrics middleware.

Types

type Config

type Config struct {
	// Metrifier is the metrifier configuration
	Metrifier metrifier.Config

	// LabelsDecoder extracts labels from the request, response or error.
	// This is optional, can be nil
	LabelsDecoder LabelsDecoder

	// ExternalMetrics is executed after the main metrifier is called.
	// This is intended to calculate custom metrics.
	// This is optional, can be nil.
	ExternalMetrics ExternalMetrics
}

Config is used to configure a metrics middleware.

func NewDefaultConfig

func NewDefaultConfig(system, subsystem string) Config

NewDefaultConfig returns a new Config with sane defaults.

func (Config) WithExternalMetrics

func (c Config) WithExternalMetrics(m ExternalMetrics) Config

WithExternalMetrics adds ExternalMetrics to the metrics middleware.

func (Config) WithLabelsDecoder

func (c Config) WithLabelsDecoder(d LabelsDecoder) Config

WithLabelsDecoder adds a LabelsDecoder to the metrics middleware.

type ExternalMetrics

type ExternalMetrics func(ctx context.Context, req, resp interface{}, err error)

ExternalMetrics is called after the internal metrifier is called. This functions should compute other metrics that are not computed by the internal metrifier (request latency and count).

type LabelsDecoder

type LabelsDecoder interface {
	// Labels return the complete list of all available labels that will be
	// returned by the Decoder. This is called once during setup of the middleware.
	Labels() []string
	// Decode extracts a map of labels considering the request, response and error.
	// The map returned must contain only labels returned by the Labels() function.
	Decode(ctx context.Context, req, resp interface{}, err error) map[string]string
}

LabelsDecoder defines an interface to decode labels for the internal metrifier.

Directories

Path Synopsis
This is a simple example that shows how to setup the metrics middleware.
This is a simple example that shows how to setup the metrics middleware.

Jump to

Keyboard shortcuts

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