requester

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnection is returned when the Requester fails to connect to
	// the requested URL.
	ErrConnection = errors.New("connection error")
	// ErrCanceled is returned when the Requester.Run context is canceled.
	ErrCanceled = errors.New("canceled")
)

Functions

This section is empty.

Types

type Benchmark added in v1.0.0

type Benchmark struct {
	Records  []Record      `json:"records"`
	Length   int           `json:"length"`
	Success  int           `json:"success"`
	Fail     int           `json:"fail"`
	Duration time.Duration `json:"duration"`
}

Benchmark represents the collected results of a benchmark test.

func (Benchmark) Stats added in v1.0.0

func (bk Benchmark) Stats() (min, max, mean time.Duration)

Stats returns basic stats about the Benchmark's records: min duration, max duration, and mean duration. It does not replace the remote computing and should only be used when a local reporting is needed.

func (Benchmark) String added in v1.0.0

func (bk Benchmark) String() string

String returns an indented JSON representation of the Benchmark.

type Config

type Config struct {
	Requests       int
	Concurrency    int
	Interval       time.Duration
	RequestTimeout time.Duration
	GlobalTimeout  time.Duration
	Silent         bool
}

Config is the requester config that determines its behavior.

type Event

type Event struct {
	Name string        `json:"name"`
	Time time.Duration `json:"time"`
}

Event is a stage of an outgoing HTTP request associated with a timestamp.

type Record

type Record struct {
	Time   time.Duration `json:"time"`
	Code   int           `json:"code"`
	Bytes  int           `json:"bytes"`
	Error  string        `json:"error,omitempty"`
	Events []Event       `json:"events"`
}

Record is the summary of a HTTP response. If Record.Error is not empty string, the HTTP call failed somewhere between sending the request to decoding the response body. In that cas invalidating the entire response, as it is not a remote server error.

type Requester

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

Requester executes the benchmark. It wraps http.Client.

func New

func New(cfg Config) *Requester

New returns a Requester initialized with cfg. cfg is assumed valid: it is the caller's responsibility to ensure cfg is valid using cfg.Validate.

func (*Requester) Run

func (r *Requester) Run(ctx context.Context, req *http.Request) (Benchmark, error)

Run starts the benchmark test and pipelines the results inside a Report. Returns the Report when the test ended and all results have been collected.

Jump to

Keyboard shortcuts

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