metrics

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LastReloadTime = expvar.NewString("authtranslator_last_reload")
)

Functions

func Caller

func Caller(ctx context.Context) string

Caller retrieves the caller ID from the context if present.

func GetResponseBody added in v0.2.0

func GetResponseBody(resp *http.Response) ([]byte, error)

GetResponseBody returns the response body bytes and resets resp.Body so it can be read again. It closes the original body to allow connection reuse.

func Handler

func Handler(w http.ResponseWriter, r *http.Request, user, pass string)

Handler writes Prometheus metrics to w enforcing optional basic auth.

func IncAuthFailure

func IncAuthFailure(integration string)

IncAuthFailure increments the auth failure counter for the integration.

func IncRateLimit

func IncRateLimit(integration string)

IncRateLimit increments the rate limit counter for the integration.

func IncRequest

func IncRequest(integration string)

IncRequest increments the request counter for the integration.

func OnRequest

func OnRequest(integration string, r *http.Request)

OnRequest triggers all registered plugins for a new request.

func OnResponse

func OnResponse(integration, caller string, r *http.Request, resp *http.Response)

OnResponse triggers all registered plugins for a completed response.

func RecordDuration

func RecordDuration(integration string, d time.Duration)

RecordDuration records the upstream request duration.

func RecordStatus

func RecordStatus(integration string, status int)

RecordStatus records the upstream status code for the integration.

func Register

func Register(p Plugin)

Register adds a metrics plugin.

func Reset

func Reset()

Reset removes all registered plugins. Primarily used in tests.

func WithCaller

func WithCaller(ctx context.Context, caller string) context.Context

WithCaller returns a new context with the caller ID stored.

func WriteProm

func WriteProm(w http.ResponseWriter)

WriteProm emits all Prometheus metrics to w in text format.

Types

type Plugin

type Plugin interface {
	OnRequest(integration string, r *http.Request)
	OnResponse(integration, caller string, r *http.Request, resp *http.Response)
	WriteProm(w http.ResponseWriter)
}

Plugin can record custom metrics for each request and response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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