metrics

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReplacePatternUID = `[a-zA-Z0-9-]{36}`
)

Variables

This section is empty.

Functions

func Register

func Register(reg prometheus.Registerer)

Types

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

func WithMetrics

func WithMetrics(inner HttpRequestDoer, opts ...Option) HttpRequestDoer

WithMetrics wraps an HttpRequestDoer and records metrics for HTTP requests. clientName is added as a label to the metrics. pathReplacePattern is a regex pattern used to replace dynamic parts of the URL path in the metrics. e.g. `\/api\/v1\/users\/(?P<resourceId>.*)` will replace "/api/v1/users/123" with "/api/v1/users/resourceId". If no named groups are found, the original path will be used.

type Option

type Option func(o *Options)

func WithClientName

func WithClientName(name string) Option

func WithReplaceFunc

func WithReplaceFunc(replaceFunc ReplaceFunc) Option

func WithReplacePatterns

func WithReplacePatterns(patterns ...string) Option

type Options

type Options struct {
	ClientName         string
	PathReplacePattern string
	ReplaceFunc        ReplaceFunc
}

type ReplaceFunc

type ReplaceFunc func(path string) string

func NewReplacePath

func NewReplacePath(re *regexp.Regexp) ReplaceFunc

NewReplacePath replaces the named groups in the path with their corresponding names. If no named groups are found, the original path is returned. If the regex is nil, the original path is returned. The named groups are replaced with their names, and the rest of the path is preserved. For example, if the regex is `\/api\/v1\/users\/(?P<redacted>.*)` and the path is `/api/v1/users/123`, the result will be `/api/v1/users/redacted`.

Jump to

Keyboard shortcuts

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