Back to

Package hazana

Latest Go to latest
Published: Jun 25, 2020 | License: Apache-2.0 | Module:


Package Files


var RequesLabelSeparator = ","

RequesLabelSeparator is what it says

func GetEnv

func GetEnv(key, absentValue string) string

GetEnv returns the environment variable value or absentValue if it is missing

func PrintCSVReport

func PrintCSVReport(r *RunReport, filename string)

PrintCSVReport writes the metrics in CSV format

func PrintReport

func PrintReport(r *RunReport)

PrintReport writes report - JSON report to a file - CSV report to a file - stdout depending on the configuration.

func PrintSummary

func PrintSummary(r *RunReport)

PrintSummary logs a subset of the report for each metric label

func Printf

func Printf(format string, args ...interface{})

Printf prefixes the line with relative time indicator

func ReadFile

func ReadFile(name, absentValue string) string

ReadFile returns the text contents of a file or absentValue if it errored

type AfterRunner

type AfterRunner interface {
	AfterRun(r *RunReport) error

AfterRunner can be implemented by an Attacker and its method is called after a test or run. The report is passed to compute the Failed field and/or store values in Output.

type Attack

type Attack interface {
	// Setup should establish the connection to the service
	// It may want to access the config of the runner.
	Setup(c Config) error
	// Do performs one request and is executed in a separate goroutine.
	// The context is used to cancel the request on timeout.
	Do(ctx context.Context) DoResult
	// Teardown can be used to close the connection to the service
	Teardown() error
	// Clone should return a fresh new Attack
	// Make sure the new Attack has values for shared struct fields initialized at Setup.
	Clone() Attack

Attack must be implemented by a service client.

type BeforeRunner

type BeforeRunner interface {
	BeforeRun(c Config) error

BeforeRunner can be implemented by an Attacker and its method is called before a test or run.

type Config

type Config struct {
	RPS               int               `json:"rps"`
	AttackTimeSec     int               `json:"attackTimeSec"`
	RampupTimeSec     int               `json:"rampupTimeSec"`
	RampupStrategy    string            `json:"rampupStrategy"`
	MaxAttackers      int               `json:"maxAttackers"`
	OutputFilename    string            `json:"outputFilename,omitempty"`
	CSVOutputFilename string            `json:"csvOutputFilename,omitempty"`
	Verbose           bool              `json:"verbose"` // for output activity
	Debug             bool              `json:"debug"`   // for inspecting requests and response, useable by attack
	Metadata          map[string]string `json:"metadata,omitempty"`
	DoTimeoutSec      int               `json:"doTimeoutSec"`

Config holds settings for a Runner.

func ConfigFromFile

func ConfigFromFile(named string) Config

ConfigFromFile loads a Config for use in a runner.

func ConfigFromFlags

func ConfigFromFlags() Config

ConfigFromFlags creates a Config for use in a runner.

func (Config) String

func (c Config) String() string

func (Config) Validate

func (c Config) Validate() (list []string)

Validate checks all settings and returns a list of strings with problems.

type DoResult

type DoResult struct {
	// Label identifying the request that was send which is only used for reporting the metrics.
	// Use the RequesLabelSeparator to have multiple labels.
	RequestLabel string
	// The error that happened when sending the request or receiving the response.
	Error error
	// The HTTP status code.
	StatusCode int
	// Number of bytes transferred when sending the request.
	BytesIn int64
	// Number of bytes transferred when receiving the response.
	BytesOut int64

DoResult is the return value of a Do call on an Attack.

func (DoResult) String

func (d DoResult) String() string

func (DoResult) WithLabels

func (d DoResult) WithLabels(labels ...string) DoResult

WithLabels return a copy with multiple Request labels set.

type LatencyMetrics

type LatencyMetrics struct {
	// Total is the total latency sum of all requests in an attack.
	Total time.Duration `json:"total"`
	// Mean is the mean request latency.
	Mean time.Duration `json:"mean"`
	// P50 is the 50th percentile request latency.
	P50 time.Duration `json:"50th"`
	// P95 is the 95th percentile request latency.
	P95 time.Duration `json:"95th"`
	// P99 is the 99th percentile request latency.
	P99 time.Duration `json:"99th"`
	// Max is the maximum observed request latency.
	Max time.Duration `json:"max"`

LatencyMetrics holds computed request latency metrics.

type Metrics

type Metrics struct {
	// Latencies holds computed request latency metrics.
	Latencies LatencyMetrics `json:"latencies"`
	// First is the earliest timestamp in a Result set.
	Earliest time.Time `json:"earliest"`
	// Latest is the latest timestamp in a Result set.
	Latest time.Time `json:"latest"`
	// End is the latest timestamp in a Result set plus its latency.
	End time.Time `json:"end"`
	// Duration is the duration of the attack.
	Duration time.Duration `json:"duration"`
	// Wait is the extra time waiting for responses from targets.
	Wait time.Duration `json:"wait"`
	// Requests is the total number of requests executed.
	Requests uint64 `json:"requests"`
	// Rate is the rate of requests per second.
	Rate float64 `json:"rate"`
	// Success is the percentage of non-error responses.
	Success float64 `json:"success"`
	// StatusCodes is a histogram of the responses' status codes.
	StatusCodes map[string]int `json:"status_codes"`
	// Errors is a set of unique errors returned by the targets during the attack.
	Errors []string `json:"errors"`

	// BytesIn
	BytesIn uint64 `json:"bytes_in"`
	// BytesOut
	BytesOut uint64 `json:"bytes_out"`
	// contains filtered or unexported fields

Metrics holds metrics computed out of a slice of Results which are used in some of the Reporters

type RunReport

type RunReport struct {
	StartedAt     time.Time `json:"startedAt"`
	FinishedAt    time.Time `json:"finishedAt"`
	Configuration Config    `json:"configuration"`
	// RunError is set when a Run could not be called or executed.
	RunError string              `json:"runError"`
	Metrics  map[string]*Metrics `json:"metrics"`
	// Failed can be set by your load test program to indicate that the results are not acceptable.
	Failed bool `json:"failed"`
	// Output is used to publish any custom output in the report.
	Output map[string]interface{} `json:"output"`

RunReport is a composition of configuration, measurements and custom output from a load run.

func NewErrorReport

func NewErrorReport(err error, config Config) *RunReport

NewErrorReport returns a report when a Run could not be called or executed.

func Run

func Run(a Attack, c Config) *RunReport

Run starts attacking a service using an Attack implementation and a configuration. Return a report with statistics per sample and the configuration used.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier