runtime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: Apache-2.0, MIT Imports: 22 Imported by: 79

Documentation

Overview

Package runtime contains functions and types to interact with the test runtime environment, as formally defined in the system specification.

Index

Constants

View Source
const (
	EventTypeStart   = EventType("start")
	EventTypeMessage = EventType("message")
	EventTypeMetric  = EventType("metric")
	EventTypeFinish  = EventType("finish")

	EventOutcomeOK      = EventOutcome("ok")
	EventOutcomeFailed  = EventOutcome("failed")
	EventOutcomeCrashed = EventOutcome("crashed")
)
View Source
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"
)
View Source
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

View Source
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 Invoke

func Invoke(tc TestCaseFn)

Invoke runs the passed test-case and reports the result.

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

func ParseKeyValues(in []string) (res map[string]string, err error)

Copied from github.com/ipfs/testground/pkg/conv, because we don't want the SDK to depend on that package.

func StandardJSONConfig

func StandardJSONConfig() zap.Config

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 EventType

type EventType string

type Gauge

type Gauge = prometheus.Gauge

Type aliases to hide implementation details in the APIs.

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 IPNet

type IPNet struct {
	net.IPNet
}

func (IPNet) MarshalJSON

func (i IPNet) MarshalJSON() ([]byte, error)

func (*IPNet) UnmarshalJSON

func (i *IPNet) UnmarshalJSON(data []byte) error

type MetricDefinition

type MetricDefinition struct {
	Name           string `json:"name"`
	Unit           string `json:"unit"`
	ImprovementDir int    `json:"dir"`
}

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) NewGauge

func (*Metrics) NewGauge(o GaugeOpts) Gauge

func (*Metrics) NewGaugeVec

func (*Metrics) NewGaugeVec(o GaugeOpts, labels ...string) *GaugeVec

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 NewRunEnv

func NewRunEnv(params RunParams) *RunEnv

NewRunEnv constructs a runtime environment from the given runtime parameters.

func ParseRunEnv

func ParseRunEnv(env []string) (*RunEnv, error)

ParseRunEnv parses a list of environment variables into a RunEnv.

func (*RunEnv) Close

func (re *RunEnv) Close() error

func (*RunEnv) CreateRandomDirectory

func (re *RunEnv) CreateRandomDirectory(directoryPath string, depth uint) (string, error)

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

func (re *RunEnv) CreateRandomFile(directoryPath string, size int64) (string, error)

CreateRandomFile creates a file of the specified size (in bytes) within the specified directory path and returns its path.

func (*RunEnv) CreateRawAsset

func (re *RunEnv) CreateRawAsset(name string) (*os.File, error)

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

func (re *RunEnv) FloatParam(name string) float64

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) M

func (re *RunEnv) M() *Metrics

M returns an object that groups the metrics facilities.

func (*RunEnv) Message deprecated

func (r *RunEnv) Message(msg string, a ...interface{})

Message prints out an informational message.

Deprecated: use RecordMessage.

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

func ParseRunParams(env []string) (*RunParams, error)

ParseRunParams parses a list of environment variables into a RunParams.

func (*RunParams) BooleanParam

func (re *RunParams) BooleanParam(name string) bool

BooleanParam returns the Boolean value of the parameter, or false if not passed

func (*RunParams) IntParam

func (re *RunParams) IntParam(name string) int

IntParam returns an int parameter, or -1 if the parameter is not set or the conversion failed. It panics on error.

func (*RunParams) IsParamSet

func (re *RunParams) IsParamSet(name string) bool

IsParamSet checks if a certain parameter is set.

func (*RunParams) JSONParam

func (re *RunParams) JSONParam(name string, v interface{})

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

func (re *RunParams) SizeArrayParam(name string) []uint64

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) SizeParam

func (re *RunParams) SizeParam(name string) uint64

func (*RunParams) StringArrayParam

func (re *RunParams) StringArrayParam(name string) []string

StringArrayParam returns an array of string parameter, or an empty array if it does not exist. It panics on error.

func (*RunParams) StringParam

func (re *RunParams) StringParam(name string) string

StringParam returns a string parameter, or "" if the parameter is not set.

func (*RunParams) ToEnvVars

func (re *RunParams) ToEnvVars() map[string]string

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.

type TestCaseFn

type TestCaseFn func(env *RunEnv) error

Jump to

Keyboard shortcuts

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