Documentation ¶
Index ¶
Constants ¶
const ConstraintsHelp = ` Constraints follow the syntax: Constraint ::= <Aggregator>(<Metric>)<Cmp><Threshold> Aggregator ::= "MIN" | "MAX" Metric ::= <string> Cmp ::= "<" | ">" Threshold ::= <float> Constraints examples: MIN(metric) < 20.5 MAX(metric) > 0.45 MIN(metric) < 123 ` + GrowthHelp
ConstraintsHelp is an help message on how to use constraints.
const ExponentialGrowthPrefix = "^"
ExponentialGrowthPrefix prefix used in exponential growth string representation.
const GrowthHelp = `` /* 480-byte string literal not displayed */
GrowthHelp provides usage help about the growth.
const LinearGrowthPrefix = "+"
LinearGrowthPrefix prefix used in linear growth string representation.
const PercentageGrowthPrefix = "%"
PercentageGrowthPrefix prefix used in percentage growth string representation.
Variables ¶
var Aggregators = map[string]Aggregator{ MinimumAggregator.Name(): MinimumAggregator, MaximumAggregator.Name(): MaximumAggregator, AverageAggregator.Name(): AverageAggregator, }
Aggregators is a map of aggregators representation to the actual aggregator.
var Comparators = map[string]Comparator{ LessThan.Name(): LessThan, GreaterThan.Name(): GreaterThan, }
Comparators is a map of comparators representation to the actual comparator.
var ErrInvalidAggregator = errors.New("invalid aggregator")
ErrInvalidAggregator is returned when a metric aggregator cannot be found.
var ErrInvalidComparator = errors.New("invalid comparator")
ErrInvalidComparator is returned when a comparator cannot be found.
var ErrInvalidFormat = errors.New("invalid constraint format")
ErrInvalidFormat is raised when the constraint format is not correct.
var ErrInvalidGrowth = errors.New("unknown growth, want +int, %%flaot, ^int")
ErrInvalidGrowth is returned when a growth cannot be found.
var ErrInvalidOptions = errors.New("invalid options")
ErrInvalidOptions is thrown when options don't implement the required interface.
var ErrNoDataPoints = errors.New("no data points")
ErrNoDataPoints is raised when no data points are found.
var ErrNotParsed = errors.New("constraint could not be parsed")
ErrNotParsed should be returned when a parser did not parse a constraint.
var ErrNotSatisfied = errors.New("unsatisfied condition")
ErrNotSatisfied is raised when a condition is not met.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator interface { // Aggregate calculates a single value for a metric datapoints. Aggregate([]DataPoint) float64 // Name is used to serialize metrics. Name() string }
Aggregator provides a function to aggregate data points.
var AverageAggregator Aggregator = &metricAggregator{ repr: "AVG", aggr: func(points []DataPoint) float64 { if len(points) == 0 { return 0. } sum := 0. for _, point := range points { sum = sum + point.Value } return sum / float64(len(points)) }, }
AverageAggregator returns the average data point value.
var MaximumAggregator Aggregator = &metricAggregator{ repr: "MAX", aggr: func(points []DataPoint) float64 { if len(points) == 0 { return 0. } x := points[0].Value for _, point := range points { if point.Value > x { x = point.Value } } return x }, }
MaximumAggregator returns the smallest datapoint value.
var MinimumAggregator Aggregator = &metricAggregator{ repr: "MIN", aggr: func(points []DataPoint) float64 { if len(points) == 0 { return 0. } x := points[0].Value for _, point := range points { if point.Value < x { x = point.Value } } return x }, }
MinimumAggregator returns the smallest datapoint value.
func ParseAggregator ¶
func ParseAggregator(name string) (Aggregator, error)
ParseAggregator returns metric aggregator from its name.
type Comparator ¶
Comparator allows to compare given values.
var ( LessThan Comparator = &comparator{repr: "<", cmp: func(x, y float64) bool { return x < y }} GreaterThan = &comparator{repr: ">", cmp: func(x, y float64) bool { return x > y }} )
Available comparators.
func ParseComparator ¶
func ParseComparator(name string) (Comparator, error)
ParseComparator returns a comparator based on the given string.
type ConcurrencyRunner ¶
type ConcurrencyRunner interface { // Before is called before running a test. Before(workers Workers, options interface{}) error // After is called after test finishes. This should be used to clean up // everything that was ser up in the Before. After(workers Workers, options interface{}) // Protocol tester. Tester() Tester // Params used by LoadTestConcurrency function. WorkerSemaphore() *bender.WorkerSemaphore Requests() chan interface{} Recorder() chan interface{} Recorders() []bender.Recorder }
ConcurrencyRunner is used to setup concurrency test execution.
type Constraint ¶
type Constraint struct { Metric Metric Aggregator Aggregator Comparator Comparator Threshold float64 }
Constraint represents a constraint tests should meet to be considered successful.
func ParseConstraint ¶
func ParseConstraint(s string, parsers ...MetricParser) (*Constraint, error)
ParseConstraint creates a constraint from a string representation.
func (*Constraint) String ¶
func (c *Constraint) String() string
type ExponentialGrowth ¶
type ExponentialGrowth struct { Precision int // contains filtered or unexported fields }
ExponentialGrowth performs binary search up to a given precision.
func (*ExponentialGrowth) OnFail ¶
func (g *ExponentialGrowth) OnFail(test int) int
OnFail sets the upper bound to the last test and returns (left+right) / 2 unless the precision has been achieved.
func (*ExponentialGrowth) OnSuccess ¶
func (g *ExponentialGrowth) OnSuccess(test int) int
OnSuccess sets the lower bound to the last test and returns (left+right) / 2 unless the precision has been achieved.
func (*ExponentialGrowth) String ¶
func (g *ExponentialGrowth) String() string
type Growth ¶
Growth is used to determine what test should be ran next.
func ParseGrowth ¶
ParseGrowth creates a growth from its string representation.
type LinearGrowth ¶
type LinearGrowth struct {
Increase int
}
LinearGrowth increases test by a specified amount with every successful test.
func (*LinearGrowth) OnSuccess ¶
func (g *LinearGrowth) OnSuccess(test int) int
OnSuccess increases test by a specified amount.
func (*LinearGrowth) String ¶
func (g *LinearGrowth) String() string
type Metric ¶
type Metric interface { // Setup is used to setup the metric before the test Setup(options interface{}) error // Fetch is used to get metric measures. Fetch(start time.Time, duration time.Duration) ([]DataPoint, error) // Name is used to serialize metrics. Name() string }
Metric provides a function to get data points of this metric.
type MetricParser ¶
MetricParser is used to parse string values to a metric. Parsers should return a metric and error if it successfully parsed a metric string, or a fatal error occurred. Otherwise it should return ErrNotParsed which will result in trying next parser from the list.
type PercentageGrowth ¶
type PercentageGrowth struct {
Increase float64
}
PercentageGrowth increases test by a specified percentage with every successful test.
func (*PercentageGrowth) OnFail ¶
func (g *PercentageGrowth) OnFail(test int) int
OnFail stops the tests.
func (*PercentageGrowth) OnSuccess ¶
func (g *PercentageGrowth) OnSuccess(test int) int
OnSuccess increases test by a specified percentage.
func (*PercentageGrowth) String ¶
func (g *PercentageGrowth) String() string
type Tester ¶
type Tester interface { // Before is called once, before any tests. Before(options interface{}) error // After is called once, after all tests (or after some of them if a test fails). // This should be used to cleanup everything that was set up in the Before. After(options interface{}) // BeforeEach is called before every test. BeforeEach(options interface{}) error // AfterEach is called after every test, even if the test fails. This should // be used to cleanup everything that was set up in the BeforeEach. AfterEach(options interface{}) // RequestExecutor is called every time a test is to be ran to get an executor. RequestExecutor(options interface{}) (bender.RequestExecutor, error) }
Tester is used to setup the test for a specific endpoint.
type ThroughputRunner ¶
type ThroughputRunner interface { // Before is called before running a test. Before(qps QPS, options interface{}) error // After is called after test finishes. This should be used to clean up // everything that was ser up in the Before. After(qps QPS, options interface{}) // Protocol tester. Tester() Tester // Params used by LoadTestThroughput function. Intervals() bender.IntervalGenerator Requests() chan interface{} Recorder() chan interface{} Recorders() []bender.Recorder }
ThroughputRunner is used to setup the test execution.