instrumented_http

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: MIT Imports: 5 Imported by: 117

README

instrumented_http

A Go http.RoundTripper that exports request statistics via Prometheus.

Documentation

Overview

Package instrumented_http provides a drop-in metrics-enabled replacement for any http.Client or http.RoundTripper.

Index

Constants

This section is empty.

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]
	}
)

Functions

func NewClient

func NewClient(next *http.Client, cbs *Callbacks) *http.Client

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
}

Callbacks is a collection of callbacks passed to Transport.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport is a http.RoundTripper that collects Prometheus metrics of every request it processes. It allows to be configured with callbacks that process request path and query into a suitable label value.

func (*Transport) RoundTrip

func (it *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. It forwards the request to the next RoundTripper and measures the time it took in Prometheus summary.

Directories

Path Synopsis
examples
default-client command
googledns command
kubernetes command
route53 command

Jump to

Keyboard shortcuts

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