Documentation
¶
Index ¶
- Variables
- func GetTaskMetadataProvider(ctx context.Context) *taskMetadata
- func NewLogger(level slog.Level) (*slog.Logger, error)
- func RootContext(logger StructuredLogger) (context.Context, func())
- type ConfigUpdate
- type DoRetryChecker
- type DoRetryer
- type Doer
- type Loadtest
- type LoadtestOption
- type LoadtestOptions
- func (LoadtestOptions) FlushRetriesOnShutdown(b bool) LoadtestOption
- func (LoadtestOptions) FlushRetriesTimeout(d time.Duration) LoadtestOption
- func (LoadtestOptions) Interval(d time.Duration) LoadtestOption
- func (LoadtestOptions) Logger(logger StructuredLogger) LoadtestOption
- func (LoadtestOptions) MaxIntervalTasks(n int) LoadtestOption
- func (LoadtestOptions) MaxTasks(max int) LoadtestOption
- func (LoadtestOptions) MaxWorkers(max int) LoadtestOption
- func (LoadtestOptions) MetadataProviderEnabled(b bool) LoadtestOption
- func (LoadtestOptions) MetricsCsv(b bool) LoadtestOption
- func (LoadtestOptions) MetricsCsvFilename(s string) LoadtestOption
- func (LoadtestOptions) MetricsCsvFlushInterval(d time.Duration) LoadtestOption
- func (LoadtestOptions) MetricsLatencyPercentile(b bool) LoadtestOption
- func (LoadtestOptions) MetricsLatencyVariance(b bool) LoadtestOption
- func (LoadtestOptions) NumIntervalTasks(n int) LoadtestOption
- func (LoadtestOptions) NumWorkers(n int) LoadtestOption
- func (LoadtestOptions) OutputBufferingFactor(factor int) LoadtestOption
- func (LoadtestOptions) Retry(b bool) LoadtestOption
- func (LoadtestOptions) TaskReader(taskReader TaskReader) LoadtestOption
- type RetryChecker
- type Retryer
- type StructuredLogger
- type TaskReader
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadReadTasksImpl = errors.New("bad ReadTasks implementation: returned a value less than zero or larger than the input slice length") ErrRetriesFailedToFlush = errors.New("failed to flush all retries") )
Functions ¶
func GetTaskMetadataProvider ¶ added in v5.0.1
GetTaskMetadataProvider returns a possibly nil value that implements:
- `IntervalID() time.Time`
- `EnqueueTime() time.Time`
- `DequeueTime() time.Time`
- `SampleSize() int`
- `NumIntervalTasks() int`
- `Lag() time.Duration`
func NewLogger ¶
NewLogger should likely be followed by a call to slog.SetDefault with the logger returned by this function if called in the program's main context.
func RootContext ¶
func RootContext(logger StructuredLogger) (context.Context, func())
RootContext returns a context that is canceled when the system process receives an interrupt, sigint, or sigterm
Also returns a function that can be used to cancel the context.
Types ¶
type ConfigUpdate ¶
type ConfigUpdate struct {
// contains filtered or unexported fields
}
func (*ConfigUpdate) SetInterval ¶
func (cu *ConfigUpdate) SetInterval(d time.Duration)
func (*ConfigUpdate) SetNumIntervalTasks ¶
func (cu *ConfigUpdate) SetNumIntervalTasks(n int)
func (*ConfigUpdate) SetNumWorkers ¶
func (cu *ConfigUpdate) SetNumWorkers(n int)
type DoRetryChecker ¶
type DoRetryChecker interface { DoRetryer RetryChecker }
type DoRetryer ¶
DoRetryer interface is useful for tasks that have no retry count upper bound
If you need to have a retry upper bound, then have your task implement DoRetryChecker
type Doer ¶
Doer is a basic task unit
If your Doer also implements Retryer then note that Doer can be run again in a different thread if your worker size is greater than one.
If you want your task to have a retry upper bound then implement DoRetryChecker
type Loadtest ¶
type Loadtest struct {
// contains filtered or unexported fields
}
func NewLoadtest ¶
func NewLoadtest(options ...LoadtestOption) (*Loadtest, error)
func (*Loadtest) NewHttpTransport ¶
HttpTransport returns a new configured *http.Transport which implements http.RoundTripper that can be used in tasks which have http clients
Note, you may need to increase the value of MaxIdleConns if your tasks target multiple hosts. MaxIdleConnsPerHost does not override the limit established by MaxIdleConns and if the tasks are expected to communicate to multiple hosts you probably need to apply some scaling factor to it to let connections go idle for a time and still be reusable.
Note that if you are not connecting to a load balancer which preserves connections to a client much of the intent we're trying to establish here is not applicable.
Also if the load balancer does not have "max connection lifespan" behavior nor a "round robin" or "connection balancing" feature without forcing the loadtesting client to reconnect then as you increase load your established connections may prevent the spread of load to newly scaled-out recipients of that load.
By default golang's http standard lib does not expose a way for us to attempt to address this. The problem is also worse if your load balancer ( or number of exposed ips for a dns record ) increase.
Rectifying this issue requires a fix like/option like https://github.com/golang/go/pull/46714 to be accepted by the go maintainers.
func (*Loadtest) UpdateConfig ¶
func (lt *Loadtest) UpdateConfig(cu ConfigUpdate) (handled bool)
UpdateConfig only returns false if the loadtest's run method has exited
This call can potentially block the caller on loadtest shutdown phase.
type LoadtestOption ¶
type LoadtestOption func(*loadtestConfig)
type LoadtestOptions ¶ added in v5.0.3
type LoadtestOptions struct{}
LoadtestOptions should never be instantiated manually
Instead call NewOpts()
This is only exported to allow godocs to discover the exported methods.
LoadtestOptions will never have exported data members, just stateless exported functions.
func NewOpts ¶
func NewOpts() LoadtestOptions
func (LoadtestOptions) FlushRetriesOnShutdown ¶ added in v5.0.3
func (LoadtestOptions) FlushRetriesOnShutdown(b bool) LoadtestOption
FlushRetriesOnShutdown is useful when your loadtest is more like a smoke test that must have all tasks flush and be successful
func (LoadtestOptions) FlushRetriesTimeout ¶ added in v5.0.3
func (LoadtestOptions) FlushRetriesTimeout(d time.Duration) LoadtestOption
FlushRetriesTimeout is only relevant when FlushRetriesOnShutdown(true) is used
func (LoadtestOptions) Interval ¶ added in v5.0.3
func (LoadtestOptions) Interval(d time.Duration) LoadtestOption
func (LoadtestOptions) Logger ¶ added in v5.0.3
func (LoadtestOptions) Logger(logger StructuredLogger) LoadtestOption
func (LoadtestOptions) MaxIntervalTasks ¶ added in v5.0.3
func (LoadtestOptions) MaxIntervalTasks(n int) LoadtestOption
func (LoadtestOptions) MaxTasks ¶ added in v5.0.3
func (LoadtestOptions) MaxTasks(max int) LoadtestOption
MaxTasks sets an upper bound on the number of tasks the loadtest could perform
func (LoadtestOptions) MaxWorkers ¶ added in v5.0.3
func (LoadtestOptions) MaxWorkers(max int) LoadtestOption
func (LoadtestOptions) MetadataProviderEnabled ¶ added in v5.0.3
func (LoadtestOptions) MetadataProviderEnabled(b bool) LoadtestOption
MetadataProviderEnabled sets wether the context provided to a task's Do, CanRetry, and Retry methods returns a non-nil value when passed to GetTaskMetadataProvider(...)
Use GetTaskMetadataProvider to instrument result reporting as you may see fit with far more granularity than the high level metrics.csv.
off == false (default)
func (LoadtestOptions) MetricsCsv ¶ added in v5.0.3
func (LoadtestOptions) MetricsCsv(b bool) LoadtestOption
func (LoadtestOptions) MetricsCsvFilename ¶ added in v5.0.3
func (LoadtestOptions) MetricsCsvFilename(s string) LoadtestOption
func (LoadtestOptions) MetricsCsvFlushInterval ¶ added in v5.0.3
func (LoadtestOptions) MetricsCsvFlushInterval(d time.Duration) LoadtestOption
func (LoadtestOptions) MetricsLatencyPercentile ¶ added in v5.0.3
func (LoadtestOptions) MetricsLatencyPercentile(b bool) LoadtestOption
MetricsLatencyPercentile can greatly increase the amount of memory used and create additional delay while processing results.
Make sure MaxIntervalTasks is either not set or if it must be set make sure it is not too large for the hosts's ram availability.
func (LoadtestOptions) MetricsLatencyVariance ¶ added in v5.0.3
func (LoadtestOptions) MetricsLatencyVariance(b bool) LoadtestOption
MetricsLatencyVariance can create additional delay while processing results.
func (LoadtestOptions) NumIntervalTasks ¶ added in v5.0.3
func (LoadtestOptions) NumIntervalTasks(n int) LoadtestOption
func (LoadtestOptions) NumWorkers ¶ added in v5.0.3
func (LoadtestOptions) NumWorkers(n int) LoadtestOption
func (LoadtestOptions) OutputBufferingFactor ¶ added in v5.0.3
func (LoadtestOptions) OutputBufferingFactor(factor int) LoadtestOption
func (LoadtestOptions) Retry ¶ added in v5.0.3
func (LoadtestOptions) Retry(b bool) LoadtestOption
Retry sets wether the loadtester has retry support on or off.
on == true (default)
func (LoadtestOptions) TaskReader ¶ added in v5.0.3
func (LoadtestOptions) TaskReader(taskReader TaskReader) LoadtestOption
type RetryChecker ¶
type StructuredLogger ¶
type TaskReader ¶
type TaskReader interface { // ReadTasks fills the provided slice up to slice length starting at index 0 and returns how many records have been inserted // // Failing to fill the whole slice will signal the end of the loadtest. // // Note in general you should not use this behavior to signal loadtests to stop // if your loadtest needs to be time-bound. For that case you should signal a stop // via the context. This stop on failure to fill behavior only exists for cases // where the author wants to exhaustively run a set of tasks and not bound the // loadtest to a timespan but rather completeness of the tasks space. // // Note that if you have only partially filled the slice, those filled task slots // will still be run before termination of the loadtest. // // It is important to remember that if your loadtest loops around and you keep a large slice of // tasks in memory just to place small chunks of that list into the passed in slice of this function // that you could have a task executed by two separate goroutines at the same time under the right circumstances. // Therefore, it's really important that the tasks either be stateless or concrete copies of the original task object are // created when saved to the passed in slice of this function. ReadTasks([]Doer) int }
TaskReader describes how to read tasks into a loadtest