loadtest

package
v1.13.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserControllerSimple     userControllerType = "simple"
	UserControllerSimulative                    = "simulative"
	UserControllerNoop                          = "noop"
	UserControllerGenerative                    = "generative"
	UserControllerCluster                       = "cluster"
)

Available UserController implementations.

Variables

View Source
var (
	ErrNotRunning      = errors.New("LoadTester is not running")
	ErrNotStopped      = errors.New("LoadTester has not stopped")
	ErrNoUsersLeft     = errors.New("no active users left")
	ErrMaxUsersReached = errors.New("max active users limit reached")
	ErrInvalidNumUsers = errors.New("numUsers should be > 0")
)
View Source
var ErrInvalidState = errors.New("unknown state")

ErrInvalidState is returned when an unknown state variable is encoded/decoded.

Functions

func MaxHTTPConns added in v1.2.0

func MaxHTTPConns(maxUsers int) int

MaxHTTPConns returns the maximum number of HTTP connections to be used for the given number of users.

func PromoteToAdmin added in v1.3.0

func PromoteToAdmin(admin, userForPromotion *userentity.UserEntity) error

PromoteToAdmin promotes user to a sysadmin role

Types

type Config

type Config struct {
	ConnectionConfiguration     ConnectionConfiguration
	UserControllerConfiguration UserControllerConfiguration
	InstanceConfiguration       InstanceConfiguration
	UsersConfiguration          UsersConfiguration
	LogSettings                 logger.Settings
}

Config holds information needed to create and initialize a new load-test agent.

func ReadConfig

func ReadConfig(configFilePath string) (*Config, error)

ReadConfig reads the configuration file from the given string. If the string is empty, it will return a config with default values.

func (*Config) IsValid added in v1.2.0

func (c *Config) IsValid() error

IsValid reports whether a given Config is valid or not. Returns an error if the validation fails.

type ConnectionConfiguration

type ConnectionConfiguration struct {
	// URL of the instance to connect to.
	ServerURL string `default:"http://localhost:8065" validate:"url"`
	// WebSocket URL of the instance to connect to.
	WebSocketURL string `default:"ws://localhost:8065" validate:"url"`
	// Email of the system admin.
	AdminEmail string `default:"sysadmin@sample.mattermost.com" validate:"email"`
	// Password of the system admin.
	AdminPassword string `default:"Sys@dmin-sample1" validate:"notempty"`
}

ConnectionConfiguration holds information needed to connect to the instance.

type InstanceConfiguration

type InstanceConfiguration struct {
	// The target number of teams to be created.
	NumTeams int64 `default:"2" validate:"range:[0,]"`
	// The target number of channels to be created.
	NumChannels int64 `default:"10" validate:"range:[0,]"`
	// The target number of posts to be created.
	NumPosts int64 `default:"0" validate:"range:[0,]"`
	// The target number of reactions to be created.
	NumReactions int64 `default:"0" validate:"range:[0,]"`
	// The target number of admin users to be created.
	NumAdmins int64 `default:"0" validate:"range:[0,]"`

	// The percentage of replies to be created.
	PercentReplies float64 `default:"0.5" validate:"range:[0,1]"`
	// The percentage of replies that should be in long threads
	PercentRepliesInLongThreads float64 `default:"0.05" validate:"range:[0,1]"`
	// The percentage of post that are marked as urgent
	PercentUrgentPosts float64 `default:"0.001" validate:"range:[0,1]"`

	// The percentage of public channels to be created.
	PercentPublicChannels float64 `default:"0.2" validate:"range:[0,1]"`
	// The percentage of private channels to be created.
	PercentPrivateChannels float64 `default:"0.1" validate:"range:[0,1]"`
	// The percentage of direct channels to be created.
	PercentDirectChannels float64 `default:"0.6" validate:"range:[0,1]"`
	// The percentage of group channels to be created.
	PercentGroupChannels float64 `default:"0.1" validate:"range:[0,1]"`
}

InstanceConfiguration holds information about the data to be populated during the init process.

func (*InstanceConfiguration) IsValid

func (c *InstanceConfiguration) IsValid() error

IsValid reports whether a given InstanceConfiguration is valid or not. Returns an error if the validation fails.

type LoadTester

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

LoadTester is a structure holding all the state needed to run a load-test.

func New

func New(config *Config, nc NewController, log *mlog.Logger) (*LoadTester, error)

New creates and initializes a new LoadTester with given config. A factory function is also given to enable the creation of UserController values from within the loadtest package.

func (*LoadTester) AddUsers

func (lt *LoadTester) AddUsers(numUsers int) (int, error)

AddUsers attempts to increment by numUsers the number of concurrently active users. Returns the number of users successfully added.

func (*LoadTester) InjectAction added in v1.10.0

func (lt *LoadTester) InjectAction(action string) error

func (*LoadTester) RemoveUsers

func (lt *LoadTester) RemoveUsers(numUsers int) (int, error)

RemoveUsers attempts to decrement by numUsers the number of concurrently active users. Returns the number of users successfully removed.

func (*LoadTester) Run

func (lt *LoadTester) Run() error

Run starts the execution of a new load-test. It returns an error if called again without stopping the test first.

func (*LoadTester) Status

func (lt *LoadTester) Status() *Status

Status returns information regarding the current state of the load-test.

func (*LoadTester) Stop

func (lt *LoadTester) Stop() error

Stop terminates the current load-test. It returns an error if it is called when the load test has not started.

type NewController

type NewController func(int, chan<- control.UserStatus) (control.UserController, error)

NewController is a factory function that returns a new control.UserController given an id and a channel of control.UserStatus It is passed during LoadTester initialization to provide a way to create concrete UserController values from within the loadtest package without the need of those being passed from the upper layer (the user of this API).

type RatesDistribution

type RatesDistribution struct {
	Rate       float64 `default:"1.0" validate:"range:[0,)"`
	Percentage float64 `default:"1.0" validate:"range:[0,1]"`
}

RatesDistribution maps a rate to a percentage of controllers that should run at that rate.

type State

type State int

State determines which state a loadtester is in.

const (
	Stopped State = iota
	Starting
	Running
	Stopping
)

Different possible states of a loadtester.

func (State) MarshalJSON

func (s State) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation from a State variable.

func (*State) UnmarshalJSON

func (s *State) UnmarshalJSON(b []byte) error

UnmarshalJSON constructs the state from a JSON string.

type Status

type Status struct {
	State           State     // State of the load test.
	NumUsers        int64     // Number of active users.
	NumUsersAdded   int64     // Number of users added since the start of the test.
	NumUsersRemoved int64     // Number of users removed since the start of the test.
	NumUsersStopped int64     // Number of users that stopped running.
	NumErrors       int64     // Number of errors that have occurred.
	StartTime       time.Time // Time when the load test was started. This only logs the time when the load test was first started, and does not get reset if it was subsequently restarted.
}

Status contains various information about the load test.

type UserControllerConfiguration

type UserControllerConfiguration struct {
	// The type of the UserController to run.
	// Possible values:
	//   UserControllerSimple - A simple version of a controller.
	//   UserControllerSimulative - A more realistic controller.
	//   UserControllerNoop
	//   UserControllerGenerative - A controller used to generate data.
	Type userControllerType `default:"simulative" validate:"oneof:{simple,simulative,noop,cluster,generative}"`
	// A distribution of rate multipliers that will affect the speed at which user actions are
	// executed by the UserController.
	// A Rate of < 1.0 will run actions at a faster pace.
	// A Rate of 1.0 will run actions at the default pace.
	// A Rate > 1.0 will run actions at a slower pace.
	RatesDistribution []RatesDistribution `default_len:"1"`
	// An optional MM server version to use when running actions (e.g. `5.30.0`).
	// This value overrides the actual server version. If left empty,
	// the one returned by the server is used instead.
	ServerVersion string
}

UserControllerConfiguration holds information about the UserController to run during a load-test.

func (*UserControllerConfiguration) IsValid

func (ucc *UserControllerConfiguration) IsValid() error

IsValid reports whether a given UserControllerConfiguration is valid or not. Returns an error if the validation fails.

type UsersConfiguration

type UsersConfiguration struct {
	// The file which contains the user emails and passwords in case the operator
	// wants to login using a different set of credentials. This is helpful during
	// LDAP logins.
	UsersFilePath string
	// The number of initial users the load-test should start with.
	InitialActiveUsers int `default:"0" validate:"range:[0,$MaxActiveUsers]"`
	// The maximum number of users that can be simulated by a single load-test
	// agent.
	MaxActiveUsers int `default:"2000" validate:"range:(0,]"`
	// The average number of sessions per user.
	AvgSessionsPerUser int `default:"1" validate:"range:[1,]"`
	// The percentage of users generated that will be system admins
	PercentOfUsersAreAdmin float64 `default:"0.02" validate:"range:[0,1]"`
}

UsersConfiguration holds information about the users of the load-test.

Directories

Path Synopsis
websocket
Package websocket is a tiny websocket client purpose-built for load-testing.
Package websocket is a tiny websocket client purpose-built for load-testing.

Jump to

Keyboard shortcuts

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