metrics

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 10 Imported by: 1

README

metrics

A package that provides reusable metrics accross Aukilabs Go projects.

Install

go get -u github.com/aukilabs/go-tooling/pkg/metrics

HTTP

Server
var h http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	// A standard http handler.
})

h = metrics.HTTPHandler(h)
http.Handle("/", h)
Client
client := http.Client{
	Transport: HTTPTransport(http.DefaultTransport),
}

res, err := client.Get("https://ted.wushu")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPathFormater

func DefaultPathFormater(_ int, path string) string

The default path formater used when none is specified.

The formater returns the first element of the path suffixed with a / when there are multiple elements.

func HTTPHandler

func HTTPHandler(h http.Handler, pathFormatters ...PathFormater) http.Handler

Returns an HTTP handler that generates metrics for the given handler.

func HTTPTransport

func HTTPTransport(t http.RoundTripper, pathFormatters ...PathFormater) http.RoundTripper

Return an HTTP transport that generates metrics for the given transport.

func Middleware

func Middleware(pathFormatters ...PathFormater) func(h http.Handler) http.Handler

Middleware return middleware for go-chi like http router

Types

type PathFormater

type PathFormater func(statusCode int, path string) string

A function that formats a path.

When dealing with metrics, each different path adds a dimension that has a toll on metrics size and aggregation performances.

This is to prevent paths like the ones which include identifiers to over create metrics dimensions.

Jump to

Keyboard shortcuts

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