metrics

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 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 IncInternalResponse added in v0.2.9

func IncInternalResponse(integration string, status int, reason string)

IncInternalResponse increments the counter for proxy-generated responses with a coarse reason label to keep cardinality bounded.

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 RecordEndToEndDuration added in v0.3.0

func RecordEndToEndDuration(integration string, d time.Duration)

RecordEndToEndDuration records full request latency as observed by the AuthTranslator handler.

func RecordPreProxyDuration added in v0.3.0

func RecordPreProxyDuration(integration string, d time.Duration)

RecordPreProxyDuration records request-side processing time before AuthTranslator proxies upstream or returns a local response.

func RecordResponseProcessingDuration added in v0.3.0

func RecordResponseProcessingDuration(integration string, d time.Duration)

RecordResponseProcessingDuration records response-side processing time inside AuthTranslator after an upstream response is received and before streaming the body to the client begins.

func RecordStatus

func RecordStatus(integration string, status int)

RecordStatus records the upstream status code for the integration.

func RecordUpstreamRoundtripDuration added in v0.3.0

func RecordUpstreamRoundtripDuration(integration string, d time.Duration)

RecordUpstreamRoundtripDuration records the duration from proxy handoff until AuthTranslator receives the upstream response.

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 UpstreamRoundtripStart added in v0.3.0

func UpstreamRoundtripStart(ctx context.Context) (time.Time, bool)

UpstreamRoundtripStart retrieves the upstream handoff start time from the context if present.

func WithCaller

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

WithCaller returns a new context with the caller ID stored.

func WithUpstreamRoundtripStart added in v0.3.0

func WithUpstreamRoundtripStart(ctx context.Context, start time.Time) context.Context

WithUpstreamRoundtripStart stores the upstream handoff start time in the request context.

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