Documentation
¶
Overview ¶
Package runtime contains functions and types to interact with the test runtime environment, as formally defined in the system specification.
Index ¶
- Constants
- Variables
- func Invoke(tc TestCaseFn)
- func InvokeMap(cases map[string]TestCaseFn)
- func ParseKeyValues(in []string) (res map[string]string, err error)
- func StandardJSONConfig() zap.Config
- type Counter
- type CounterOpts
- type CounterVec
- type Event
- type EventOutcome
- type EventType
- type Gauge
- type GaugeOpts
- type GaugeVec
- type Histogram
- type HistogramOpts
- type HistogramVec
- type IPNet
- type MetricDefinition
- type MetricValue
- type Metrics
- func (*Metrics) NewCounter(o CounterOpts) Counter
- func (*Metrics) NewCounterVec(o CounterOpts, labels ...string) *CounterVec
- func (*Metrics) NewGauge(o GaugeOpts) Gauge
- func (*Metrics) NewGaugeVec(o GaugeOpts, labels ...string) *GaugeVec
- func (*Metrics) NewHistogram(o HistogramOpts) Histogram
- func (*Metrics) NewHistogramVec(o HistogramOpts, labels ...string) *HistogramVec
- func (*Metrics) NewSummary(o SummaryOpts) Summary
- func (*Metrics) NewSummaryVec(o SummaryOpts, labels ...string) *SummaryVec
- type RunEnv
- func (re *RunEnv) Close() error
- func (re *RunEnv) CreateRandomDirectory(directoryPath string, depth uint) (string, error)
- func (re *RunEnv) CreateRandomFile(directoryPath string, size int64) (string, error)
- func (re *RunEnv) CreateRawAsset(name string) (*os.File, error)
- func (re *RunEnv) CreateStructuredAsset(name string, config zap.Config) (*zap.Logger, *zap.SugaredLogger, error)
- func (r *RunEnv) EmitMetric(metric *MetricDefinition, value float64)deprecated
- func (re *RunEnv) FloatParam(name string) float64
- func (re *RunEnv) HTTPPeriodicSnapshots(ctx context.Context, addr string, dur time.Duration, outDir string) error
- func (l RunEnv) Loggers() (*zap.Logger, *zap.SugaredLogger)
- func (re *RunEnv) M() *Metrics
- func (r *RunEnv) Message(msg string, a ...interface{})deprecated
- func (l RunEnv) RecordCrash(err interface{})
- func (l RunEnv) RecordFailure(err error)
- func (l RunEnv) RecordMessage(msg string, a ...interface{})
- func (l RunEnv) RecordMetric(metric *MetricDefinition, value float64)
- func (l RunEnv) RecordStart()
- func (l RunEnv) RecordSuccess()
- func (l RunEnv) SLogger() *zap.SugaredLogger
- type RunParams
- func (re *RunParams) BooleanParam(name string) bool
- func (re *RunParams) IntParam(name string) int
- func (re *RunParams) IsParamSet(name string) bool
- func (re *RunParams) JSONParam(name string, v interface{})
- func (r *RunParams) MarshalLogObject(oe zapcore.ObjectEncoder) error
- func (re *RunParams) SizeArrayParam(name string) []uint64
- func (re *RunParams) SizeParam(name string) uint64
- func (re *RunParams) StringArrayParam(name string) []string
- func (re *RunParams) StringParam(name string) string
- func (re *RunParams) ToEnvVars() map[string]string
- type Summary
- type SummaryOpts
- type SummaryVec
- type TestCaseFn
Constants ¶
const ( EventTypeStart = EventType("start") EventTypeMessage = EventType("message") EventTypeMetric = EventType("metric") EventTypeFinish = EventType("finish") EventOutcomeOK = EventOutcome("ok") EventOutcomeFailed = EventOutcome("failed") EventOutcomeCrashed = EventOutcome("crashed") )
const ( EnvTestBranch = "TEST_BRANCH" EnvTestCase = "TEST_CASE" EnvTestGroupID = "TEST_GROUP_ID" EnvTestGroupInstanceCount = "TEST_GROUP_INSTANCE_COUNT" EnvTestInstanceCount = "TEST_INSTANCE_COUNT" EnvTestInstanceParams = "TEST_INSTANCE_PARAMS" EnvTestInstanceRole = "TEST_INSTANCE_ROLE" EnvTestOutputsPath = "TEST_OUTPUTS_PATH" EnvTestPlan = "TEST_PLAN" EnvTestRepo = "TEST_REPO" EnvTestRun = "TEST_RUN" EnvTestSidecar = "TEST_SIDECAR" EnvTestStartTime = "TEST_START_TIME" EnvTestSubnet = "TEST_SUBNET" EnvTestTag = "TEST_TAG" )
const ( // These ports are the HTTP ports we'll attempt to bind to. If this instance // is running in a Docker container, binding to 6060 is safe. If it's a // local:exec run, these ports belong to the host, so starting more than one // instance will lead to a collision. Therefore we fallback to 0. HTTPPort = 6060 HTTPPortFallback = 0 )
Variables ¶
var HTTPListenAddr string
HTTPListenAddr will be set to the listener address _before_ the test case is invoked. If we were unable to start the listener, this value will be "".
Functions ¶
func InvokeMap ¶
func InvokeMap(cases map[string]TestCaseFn)
InvokeMap takes a map of test case names and their functions, and calls the matched test case, or panics if the name is unrecognised.
func ParseKeyValues ¶
Copied from github.com/ipfs/testground/pkg/conv, because we don't want the SDK to depend on that package.
func StandardJSONConfig ¶
StandardJSONConfig returns a zap.Config with JSON encoding, debug verbosity, caller and stacktraces disabled, and with timestamps encoded as nanos after epoch.
Types ¶
type Counter ¶
type Counter = prometheus.Counter
Type aliases to hide implementation details in the APIs.
type CounterOpts ¶
type CounterOpts = prometheus.CounterOpts
Type aliases to hide implementation details in the APIs.
type CounterVec ¶
type CounterVec = prometheus.CounterVec
Type aliases to hide implementation details in the APIs.
type Event ¶
type Event struct {
Type EventType `json:"type"`
Outcome EventOutcome `json:"outcome,omitempty"`
Error string `json:"error,omitempty"`
Stacktrace string `json:"stacktrace,omitempty"`
Message string `json:"message,omitempty"`
Metric *MetricValue `json:"metric,omitempty"`
Runenv *RunParams `json:"runenv,omitempty"`
}
func (Event) MarshalLogObject ¶
func (e Event) MarshalLogObject(oe zapcore.ObjectEncoder) error
type EventOutcome ¶
type EventOutcome string
type GaugeOpts ¶
type GaugeOpts = prometheus.GaugeOpts
Type aliases to hide implementation details in the APIs.
type GaugeVec ¶
type GaugeVec = prometheus.GaugeVec
Type aliases to hide implementation details in the APIs.
type Histogram ¶
type Histogram = prometheus.Histogram
Type aliases to hide implementation details in the APIs.
type HistogramOpts ¶
type HistogramOpts = prometheus.HistogramOpts
Type aliases to hide implementation details in the APIs.
type HistogramVec ¶
type HistogramVec = prometheus.HistogramVec
Type aliases to hide implementation details in the APIs.
type MetricDefinition ¶
type MetricValue ¶
type MetricValue struct {
MetricDefinition
Value float64 `json:"value"`
}
func (MetricValue) MarshalLogObject ¶
func (m MetricValue) MarshalLogObject(oe zapcore.ObjectEncoder) error
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func (*Metrics) NewCounter ¶
func (*Metrics) NewCounter(o CounterOpts) Counter
func (*Metrics) NewCounterVec ¶
func (*Metrics) NewCounterVec(o CounterOpts, labels ...string) *CounterVec
func (*Metrics) NewHistogram ¶
func (*Metrics) NewHistogram(o HistogramOpts) Histogram
func (*Metrics) NewHistogramVec ¶
func (*Metrics) NewHistogramVec(o HistogramOpts, labels ...string) *HistogramVec
func (*Metrics) NewSummary ¶
func (*Metrics) NewSummary(o SummaryOpts) Summary
func (*Metrics) NewSummaryVec ¶
func (*Metrics) NewSummaryVec(o SummaryOpts, labels ...string) *SummaryVec
type RunEnv ¶
type RunEnv struct {
RunParams
// contains filtered or unexported fields
}
RunEnv encapsulates the context for this test run.
func CurrentRunEnv ¶
func CurrentRunEnv() *RunEnv
CurrentRunEnv populates a test context from environment vars.
func ParseRunEnv ¶
ParseRunEnv parses a list of environment variables into a RunEnv.
func (*RunEnv) CreateRandomDirectory ¶
CreateRandomDirectory creates a nested directory with the specified depth within the specified directory path. If depth is zero, the directory path is returned.
func (*RunEnv) CreateRandomFile ¶
CreateRandomFile creates a file of the specified size (in bytes) within the specified directory path and returns its path.
func (*RunEnv) CreateRawAsset ¶
CreateRawAsset creates an output asset.
Output assets will be saved when the test terminates and available for further investigation. You can also manually create output assets/directories under re.TestOutputsPath.
func (*RunEnv) CreateStructuredAsset ¶
func (re *RunEnv) CreateStructuredAsset(name string, config zap.Config) (*zap.Logger, *zap.SugaredLogger, error)
CreateStructuredAsset creates an output asset and wraps it in zap loggers.
func (*RunEnv) EmitMetric
deprecated
func (r *RunEnv) EmitMetric(metric *MetricDefinition, value float64)
EmitMetric outputs a metric event associated with the provided metric definition, giving it value `value`.
Deprecated: use RecordMetric.
func (*RunEnv) FloatParam ¶
FloatParam returns a float64 parameter, or -1.0 if the parameter is not set or the conversion failed. It panics on error.
func (*RunEnv) HTTPPeriodicSnapshots ¶
func (re *RunEnv) HTTPPeriodicSnapshots(ctx context.Context, addr string, dur time.Duration, outDir string) error
HTTPPeriodicSnapshots periodically fetches the snapshots from the given address and outputs them to the out directory. Every file will be in the format timestamp.out.
func (RunEnv) Loggers ¶
func (l RunEnv) Loggers() (*zap.Logger, *zap.SugaredLogger)
Loggers returns the loggers populated from this runenv.
func (RunEnv) RecordCrash ¶
func (l RunEnv) RecordCrash(err interface{})
RecordCrash records that the calling instance crashed/panicked with the supplied error.
func (RunEnv) RecordFailure ¶
func (l RunEnv) RecordFailure(err error)
RecordFailure records that the calling instance failed with the supplied error.
func (RunEnv) RecordMessage ¶
func (l RunEnv) RecordMessage(msg string, a ...interface{})
RecordMessage records an informational message.
func (RunEnv) RecordMetric ¶
func (l RunEnv) RecordMetric(metric *MetricDefinition, value float64)
RecordMetric records a metric event associated with the provided metric definition, giving it value `value`.
func (RunEnv) RecordStart ¶
func (l RunEnv) RecordStart()
func (RunEnv) RecordSuccess ¶
func (l RunEnv) RecordSuccess()
RecordSuccess records that the calling instance succeeded.
func (RunEnv) SLogger ¶
func (l RunEnv) SLogger() *zap.SugaredLogger
type RunParams ¶
type RunParams struct {
TestPlan string `json:"plan"`
TestCase string `json:"case"`
TestRun string `json:"run"`
TestRepo string `json:"repo,omitempty"`
TestCommit string `json:"commit,omitempty"`
TestBranch string `json:"branch,omitempty"`
TestTag string `json:"tag,omitempty"`
TestOutputsPath string `json:"outputs_path,omitempty"`
TestInstanceCount int `json:"instances"`
TestInstanceRole string `json:"role,omitempty"`
TestInstanceParams map[string]string `json:"params,omitempty"`
TestGroupID string `json:"group,omitempty"`
TestGroupInstanceCount int `json:"group_instances,omitempty"`
// true if the test has access to the sidecar.
TestSidecar bool `json:"test_sidecar,omitempty"`
// The subnet on which this test is running.
//
// The test instance can use this to pick an IP address and/or determine
// the "data" network interface.
//
// This will be 127.1.0.0/16 when using the local exec runner.
TestSubnet *IPNet `json:"network,omitempty"`
TestStartTime time.Time `json:"start_time,omitempty"`
}
RunParams encapsulates the runtime parameters for this test.
func ParseRunParams ¶
ParseRunParams parses a list of environment variables into a RunParams.
func (*RunParams) BooleanParam ¶
BooleanParam returns the Boolean value of the parameter, or false if not passed
func (*RunParams) IntParam ¶
IntParam returns an int parameter, or -1 if the parameter is not set or the conversion failed. It panics on error.
func (*RunParams) IsParamSet ¶
IsParamSet checks if a certain parameter is set.
func (*RunParams) JSONParam ¶
JSONParam unmarshals a JSON parameter in an arbitrary interface. It panics on error.
func (*RunParams) MarshalLogObject ¶
func (r *RunParams) MarshalLogObject(oe zapcore.ObjectEncoder) error
func (*RunParams) SizeArrayParam ¶
SizeArrayParam returns an array of uint64 elements which represent sizes, in bytes. If the response is nil, then there was an error parsing the input. It panics on error.
func (*RunParams) StringArrayParam ¶
StringArrayParam returns an array of string parameter, or an empty array if it does not exist. It panics on error.
func (*RunParams) StringParam ¶
StringParam returns a string parameter, or "" if the parameter is not set.
type Summary ¶
type Summary = prometheus.Summary
Type aliases to hide implementation details in the APIs.
type SummaryOpts ¶
type SummaryOpts = prometheus.SummaryOpts
Type aliases to hide implementation details in the APIs.
type SummaryVec ¶
type SummaryVec = prometheus.SummaryVec
Type aliases to hide implementation details in the APIs.