Documentation ¶
Overview ¶
Package testbed allows to easily set up a test that requires running the agent and a load generator, measure and define resource consumption expectations for the agent, fail tests automatically when expectations are exceeded.
Each test case requires a agent configuration file and (optionally) load generator spec file. Test cases are defined as regular Go tests.
Agent and load generator must be pre-built and their paths must be specified in test bed config file. The config file location must be provided in TESTBED_CONFIG env variable.
Index ¶
- Variables
- func LoadConfig() error
- func SaveResults()
- func Start() error
- type BackendType
- type GlobalConfig
- type LoadGenerator
- type LoadOptions
- type MockBackend
- func (mb *MockBackend) Context() context.Context
- func (mb *MockBackend) GetStats() string
- func (mb *MockBackend) OkToIngest() bool
- func (mb *MockBackend) ReportFatalError(err error)
- func (mb *MockBackend) SpansReceived() uint64
- func (mb *MockBackend) Start(backendType BackendType) error
- func (mb *MockBackend) Stop()
- type ResourceConsumption
- type Results
- type TestCase
- func (tc *TestCase) AgentMemoryInfo() (uint32, uint32, error)
- func (tc *TestCase) SetExpectedMaxCPU(cpuPercentage uint32)
- func (tc *TestCase) SetExpectedMaxRAM(ramMiB uint32)
- func (tc *TestCase) Sleep(d time.Duration)
- func (tc *TestCase) StartAgent(args ...string)
- func (tc *TestCase) StartBackend(backendType BackendType)
- func (tc *TestCase) StartLoad(options LoadOptions)
- func (tc *TestCase) Stop()
- func (tc *TestCase) StopAgent()
- func (tc *TestCase) StopBackend()
- func (tc *TestCase) StopLoad()
- func (tc *TestCase) ValidateData()
- func (tc *TestCase) WaitFor(cond func() bool, errMsg ...interface{}) bool
- func (tc *TestCase) WaitForN(cond func() bool, duration time.Duration, errMsg ...interface{}) bool
- type TestCaseOption
- type TestResult
Constants ¶
This section is empty.
Variables ¶
var ErrSkipTests = errors.New("skip tests")
ErrSkipTests indicates that the tests must be skipped.
Functions ¶
func SaveResults ¶
func SaveResults()
Types ¶
type GlobalConfig ¶
GlobalConfig defines test bed configuration.
type LoadGenerator ¶
type LoadGenerator struct {
// contains filtered or unexported fields
}
LoadGenerator is a simple load generator.
func NewLoadGenerator ¶
func NewLoadGenerator() (*LoadGenerator, error)
NewLoadGenerator creates a load generator.
func (*LoadGenerator) GetStats ¶
func (lg *LoadGenerator) GetStats() string
GetStats returns the stats as a printable string.
func (*LoadGenerator) SpansSent ¶
func (lg *LoadGenerator) SpansSent() uint64
type LoadOptions ¶
type LoadOptions struct { // SpansPerSecond specifies how many spans to generate each second. SpansPerSecond uint // SpansPerTrace specifies how many spans per trace to generate. Should be equal or greater than zero. // The number of traces generated per second will be SpansPerSecond/SpansPerTrace. SpansPerTrace uint // Attributes to add to each generated span. Can be empty. Attributes map[string]interface{} }
LoadOptions defines the options to use for generating the load.
type MockBackend ¶
type MockBackend struct {
// contains filtered or unexported fields
}
MockBackend is a backend that allows receiving the data locally.
func NewMockBackend ¶
func NewMockBackend(logFilePath string) *MockBackend
NewMockBackend creates a new mock backend.
func (*MockBackend) Context ¶
func (mb *MockBackend) Context() context.Context
func (*MockBackend) GetStats ¶
func (mb *MockBackend) GetStats() string
func (*MockBackend) OkToIngest ¶
func (mb *MockBackend) OkToIngest() bool
func (*MockBackend) ReportFatalError ¶
func (mb *MockBackend) ReportFatalError(err error)
func (*MockBackend) SpansReceived ¶
func (mb *MockBackend) SpansReceived() uint64
func (*MockBackend) Start ¶
func (mb *MockBackend) Start(backendType BackendType) error
Start a backend of specified type. Only one backend type can be started at a time.
type ResourceConsumption ¶
type Results ¶
type Results struct {
// contains filtered or unexported fields
}
func (*Results) Add ¶
func (r *Results) Add(testName string, result *TestResult)
Add results for one test.
type TestCase ¶
type TestCase struct { LoadGenerator *LoadGenerator MockBackend *MockBackend // ErrorSignal indicates an error in the test case execution, e.g. process execution // failure or exceeding resource consumption, etc. The actual error message is already // logged, this is only an indicator on which you can wait to be informed. ErrorSignal chan struct{} // contains filtered or unexported fields }
TestCase defines a running test case.
func NewTestCase ¶
func NewTestCase(t *testing.T, opts ...TestCaseOption) *TestCase
NewTestCase creates a new TestCase. It expected agent-config.yaml in the specified directory.
func (*TestCase) AgentMemoryInfo ¶
AgentMemoryInfo returns raw memory info struct about the agent as returned by github.com/shirou/gopsutil/process
func (*TestCase) SetExpectedMaxCPU ¶
SetExpectedMaxCPU sets the percentage of one core agent is expected to consume at most. Error is signalled if consumption during resourceCheckPeriod exceeds this number. If this function is not called the CPU consumption does not affect the test result.
func (*TestCase) SetExpectedMaxRAM ¶
SetExpectedMaxRAM sets the maximum RAM in MiB the agent is expected to consume. Error is signalled if consumption during resourceCheckPeriod exceeds this number. If this function is not called the RAM consumption does not affect the test result.
func (*TestCase) StartAgent ¶
StartAgent starts the agent and redirects its standard output and standard error to "agent.log" file located in the test directory.
func (*TestCase) StartBackend ¶
func (tc *TestCase) StartBackend(backendType BackendType)
StartBackend starts the specified backend type.
func (*TestCase) StartLoad ¶
func (tc *TestCase) StartLoad(options LoadOptions)
StartLoad starts the load generator and redirects its standard output and standard error to "load-generator.log" file located in the test directory.
func (*TestCase) Stop ¶
func (tc *TestCase) Stop()
Stop stops the load generator, the agent and the backend.
func (*TestCase) ValidateData ¶
func (tc *TestCase) ValidateData()
ValidateData validates data by comparing the number of spans sent by load generator and number of spans received by mock backend.
func (*TestCase) WaitForN ¶
WaitForN the specific condition for up to a specified duration. Records a test error if time is out and condition does not become true. If error is signalled while waiting the function will return false, but will not record additional test error (we assume that signalled error is already recorded in indicateError()).
type TestCaseOption ¶
type TestCaseOption struct {
// contains filtered or unexported fields
}
TestCaseOption defines a TestCase option.
func WithConfigFile ¶
func WithConfigFile(file string) TestCaseOption
WithConfigFile allows a custom configuration file for TestCase.
func WithSkipResults ¶
func WithSkipResults() TestCaseOption
WithSkipResults option disables writing out results file for a TestCase.
func (TestCaseOption) Apply ¶
func (o TestCaseOption) Apply(t *TestCase)
Apply takes a TestCase and runs the option function on it.
type TestResult ¶
type TestResult struct {
// contains filtered or unexported fields
}