recorder

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Config

type Config struct {
	// Requests is the number of requests to send.
	Requests int
	// Concurrency is the maximum number of concurrent requests.
	Concurrency int
	// Interval is the minimum duration between two non-concurrent requests.
	Interval time.Duration
	// RequestTimeout is the timeout for each request sent.
	RequestTimeout time.Duration
	// GlobalTimeout is the timeout for the whole run.
	GlobalTimeout time.Duration
	// OnProgress is called each time the requester Progress is updated.
	// The requester Progress is updated each time a request is done,
	// and every second concurrently.
	OnProgress func(Progress)
}

A Config determines the behavior of a Requester.

type Event

type Event struct {
	Name string
	Time time.Duration
}

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

type Progress

type Progress struct {
	Done                bool
	Error               error
	DoneCount, MaxCount int
	Timeout, Elapsed    time.Duration
}

Progress represents the progression of a recording at a given time.

func (Progress) JSON

func (s Progress) JSON() ([]byte, error)

func (Progress) Percent

func (s Progress) Percent() int

percentDone returns the progression of the run as a percentage. It is based on the ratio requests done / max requests if it's finite (not -1), else on the ratio elapsed time / global timeout.

func (Progress) Status

func (s Progress) Status() Status

status returns a string representing the status, depending on whether the run is done or not and the value of the context error.

type Record

type Record struct {
	Time   time.Duration
	Code   int
	Bytes  int
	Error  string
	Events []Event
}

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 Recorder

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

Recorder sends requests and records the results via the method Run. It must be initialized with New: it won't work otherwise.

func New

func New(cfg Config) *Recorder

New returns a Requester initialized with the given Config.

func (*Recorder) Progress

func (r *Recorder) Progress() Progress

Progress returns the current Progress of the recording.

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, req *http.Request) ([]Record, error)

Record clones and sends req n times, or until ctx is done or the global timeout is reached. It gathers the collected results into a Benchmark.

type Status

type Status string
const (
	StatusRunning  Status = "RUNNING"
	StatusCanceled Status = "CANCELED"
	StatusTimeout  Status = "TIMEOUT"
	StatusDone     Status = "DONE"
)

Jump to

Keyboard shortcuts

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