httpstat

package
v4.3.6 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package httpstat traces HTTP latency infomation (DNSLookup, TCP Connection and so on) on any golang HTTP request. It uses `httptrace` package. Inspired by https://github.com/tcnksm/go-httpstat and https://github.com/davecheney/httpstat

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithHTTPStat

func WithHTTPStat(req *http.Request, s *Stat) context.Context

WithHTTPStat is a wrapper of httptrace.WithClientTrace. It records the time of each httptrace hooks.

Types

type Stat

type Stat struct {
	// The following are duration for each phase
	// DNSLookup => TCPConnection => TLSHandshake => ServerProcessing => ContentTransfer
	DNSLookup        time.Duration
	TCPConnection    time.Duration
	TLSHandshake     time.Duration
	ServerProcessing time.Duration
	ContentTransfer  time.Duration // from the first response byte to tansfer done.

	// The followings are timeline of request
	NameLookup    time.Duration // = DNSLookup
	Connect       time.Duration // = DNSLookup + TCPConnection
	Pretransfer   time.Duration // = DNSLookup + TCPConnection + TLSHandshake
	StartTransfer time.Duration // = DNSLookup + TCPConnection + TLSHandshake + ServerProcessing
	Total         time.Duration // = DNSLookup + TCPConnection + TLSHandshake + ServerProcessing + ContentTransfer
	// contains filtered or unexported fields
}

Stat stores httpstat info.

func (*Stat) Durations

func (s *Stat) Durations() map[string]int64

Durations returns all durations and timelines of request latencies

func (*Stat) Finish

func (s *Stat) Finish()

Finish sets the time when reading response is done. This must be called after reading response body.

func (*Stat) Print

func (s *Stat) Print()

Jump to

Keyboard shortcuts

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