instrumentedclient

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Overview

Package instrumentedclient is a wrapper around standard http.Client that tracks basic HTTP metrics using Prometheus. It also sets some sensinble defaults to important timeout settings. All instrumentedclient instances log to the same Prometheus variables, even if created with NewClient().

Index

Constants

View Source
const (
	// Timeout for an entire HTTP transaction: sending request, reading and
	// response, redirects, etc.
	HTTPRequestResponseTimeout = 10 * time.Second
	// Timeout for establishing a TCP connection with a remote end.
	TCPConnectionTimeout = 3 * time.Second
	// TCP keepalive timeout.
	TCPKeepAliveTime = 30 * time.Second
)

Variables

View Source
var DefaultClient = &http.Client{
	Transport: roundTripper,
	Timeout:   HTTPRequestResponseTimeout,
}

DefaultClient is an instrumented http.Client with pre-set timeouts.

Functions

func Get

func Get(url string) (*http.Response, error)

Get issues a GET request using DefaultClient.

func GetMetrics

func GetMetrics() []prometheus.Collector

GetMetrics returns Prometheus all variables that track metrics. Used for registering with an HTTP handler.

func Head(url string) (*http.Response, error)

Get issues a GET request using DefaultClient.

func NewClient

func NewClient() *http.Client

NewClient returns a new instrumented http.Client with pre-set timeouts. Use it if you want to adjust default timeouts.

func Post

func Post(url string, contentType string, body io.Reader) (*http.Response, error)

Get issues a POST request using DefaultClient.

func PostForm

func PostForm(url string, data url.Values) (*http.Response, error)

Get issues a POST (application/x-www-form-urlencoded) request using DefaultClient.

Types

This section is empty.

Jump to

Keyboard shortcuts

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