Documentation
¶
Overview ¶
Package instrumented_http provides a drop-in metrics-enabled replacement for any http.Client or http.RoundTripper.
Index ¶
Constants ¶
View Source
const (
BogusStatusCode = 999
)
Variables ¶
View Source
var ( // RequestDurationSeconds is a Prometheus summary to collect request times. RequestDurationSeconds = prometheus.NewSummaryVec( prometheus.SummaryOpts{ Name: "request_duration_seconds", Help: "The HTTP request latencies in seconds.", Subsystem: "http", ConstLabels: prometheus.Labels{"handler": handlerName}, Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, }, []string{"scheme", "host", "path", "query", "method", "status"}, ) // EliminatingProcessor is a callback that returns a blank string on any input. EliminatingProcessor = func(_ string) string { return "" } // IdentityProcessor is callback that returns whatever is passed to it. IdentityProcessor = func(input string) string { return input } // LastPathElementProcessor is callback that returns the last element of a URL path. LastPathElementProcessor = func(path string) string { parts := strings.Split(path, "/") return parts[len(parts)-1] } // IntToStringProcessor converts an integer value to its string representation. IntToStringProcessor = func(input int) string { return fmt.Sprintf("%d", input) } // ServerErrorCodeProcessor exports all failed responses (5xx, timeouts, ...) as status=failure ServerErrorCodeProcessor = func(code int) string { if code >= http.StatusInternalServerError { return "failure" } return "success" } )
Functions ¶
func NewClient ¶
NewClient takes a *http.Client and returns a *http.Client that has its RoundTripper wrapped with instrumentation. Optionally, It can receive a collection of callbacks that process request path and query into a suitable label value.
func NewTransport ¶
func NewTransport(next http.RoundTripper, cbs *Callbacks) http.RoundTripper
NewTransport takes a http.RoundTripper, wraps it with instrumentation and returns it as a new http.RoundTripper. Optionally, It can receive a collection of callbacks that process request path and query into a suitable label value.
Types ¶
type Callbacks ¶
type Callbacks struct {
PathProcessor func(string) string
QueryProcessor func(string) string
CodeProcessor func(int) string
}
Callbacks is a collection of callbacks passed to Transport.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
custom-transport
command
|
|
|
default-client
command
|
|
|
gentleman
command
|
|
|
googledns
command
|
|
|
gorilla
command
|
|
|
hashicorp
command
|
|
|
kubernetes
command
|
|
|
resty
command
|
|
|
route53
command
|
|
|
sling
command
|
|
|
status-code
command
|
Click to show internal directories.
Click to hide internal directories.