e2e

package
v1.3.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ContainerSharedDir = "/shared"
)

Variables

View Source
var (
	DefaultMetricsOptions = MetricsOptions{
		GetValue:           getMetricValue,
		WaitMissingMetrics: false,
	}
)

Functions

func BuildArgs

func BuildArgs(flags map[string]string) []string

func EmptyFlags

func EmptyFlags() map[string]string

func Equals

func Equals(value float64) func(sums ...float64) bool

Equals is an isExpected function for WaitSumMetrics that returns true if given single sum is equals to given value.

func EqualsAmongTwo

func EqualsAmongTwo(sums ...float64) bool

EqualsAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is equal to the second. NOTE: Be careful on scrapes in between of process that changes two metrics. Those are usually not atomic.

func EqualsSingle added in v1.0.0

func EqualsSingle(expected float64) func(float64) bool

func GenerateSeries

func GenerateSeries(name string, ts time.Time, additionalLabels ...prompb.Label) (series []prompb.TimeSeries, vector model.Vector)

func GetRequest

func GetRequest(url string) (*http.Response, error)

func Greater

func Greater(value float64) func(sums ...float64) bool

Greater is an isExpected function for WaitSumMetrics that returns true if given single sum is greater than given value.

func GreaterAmongTwo

func GreaterAmongTwo(sums ...float64) bool

GreaterAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is greater than second. NOTE: Be careful on scrapes in between of process that changes two metrics. Those are usually not atomic.

func Less

func Less(value float64) func(sums ...float64) bool

Less is an isExpected function for WaitSumMetrics that returns true if given single sum is less than given value.

func LessAmongTwo

func LessAmongTwo(sums ...float64) bool

LessAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is smaller than second. NOTE: Be careful on scrapes in between of process that changes two metrics. Those are usually not atomic.

func MergeFlags

func MergeFlags(inputs ...map[string]string) map[string]string

func MergeFlagsWithoutRemovingEmpty added in v1.1.0

func MergeFlagsWithoutRemovingEmpty(inputs ...map[string]string) map[string]string

func RunCommandAndGetOutput

func RunCommandAndGetOutput(name string, args ...string) ([]byte, error)

func TimeToMilliseconds

func TimeToMilliseconds(t time.Time) int64

timeToMilliseconds returns the input time as milliseconds, using the same formula used by Prometheus in order to get the same timestamp when asserting on query results.

func WaitMissingMetrics added in v1.3.0

func WaitMissingMetrics(opts *MetricsOptions)

WithWaitMissingMetrics is an option to wait whenever an expected metric is missing. If this option is not enabled, will return error on missing metrics.

func WithMetricCount added in v1.3.0

func WithMetricCount(opts *MetricsOptions)

WithMetricCount is an option to get the histogram/summary count as metric value.

Types

type CmdReadinessProbe added in v1.0.0

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

CmdReadinessProbe checks readiness by `Exec`ing a command (within container) which returns 0 to consider status being ready

func NewCmdReadinessProbe added in v1.0.0

func NewCmdReadinessProbe(cmd *Command) *CmdReadinessProbe

func (*CmdReadinessProbe) Ready added in v1.0.0

func (p *CmdReadinessProbe) Ready(service *ConcreteService) error

type Command

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

func NewCommand

func NewCommand(cmd string, args ...string) *Command

func NewCommandWithoutEntrypoint

func NewCommandWithoutEntrypoint(cmd string, args ...string) *Command

type CompositeHTTPService added in v1.1.0

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

CompositeHTTPService abstract an higher-level service composed, under the hood, by 2+ HTTPService.

func NewCompositeHTTPService added in v1.1.0

func NewCompositeHTTPService(services ...*HTTPService) *CompositeHTTPService

func (*CompositeHTTPService) Instances added in v1.1.0

func (s *CompositeHTTPService) Instances() []*HTTPService

func (*CompositeHTTPService) NumInstances added in v1.1.0

func (s *CompositeHTTPService) NumInstances() int

func (*CompositeHTTPService) SumMetrics added in v1.1.0

func (s *CompositeHTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error)

SumMetrics returns the sum of the values of each given metric names.

func (*CompositeHTTPService) WaitSumMetrics added in v1.1.0

func (s *CompositeHTTPService) WaitSumMetrics(isExpected func(sums ...float64) bool, metricNames ...string) error

WaitSumMetrics waits for at least one instance of each given metric names to be present and their sums, returning true when passed to given isExpected(...).

func (*CompositeHTTPService) WaitSumMetricsWithOptions added in v1.3.0

func (s *CompositeHTTPService) WaitSumMetricsWithOptions(isExpected func(sums ...float64) bool, metricNames []string, opts ...MetricsOption) error

type ConcreteService

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

ConcreteService represents microservice with optional ports which will be discoverable from docker with <name>:<port>. For connecting from test, use `Endpoint` method.

ConcreteService can be reused (started and stopped many time), but it can represent only one running container at the time.

func NewConcreteService

func NewConcreteService(
	name string,
	image string,
	command *Command,
	readiness ReadinessProbe,
	networkPorts ...int,
) *ConcreteService

func (*ConcreteService) Endpoint

func (s *ConcreteService) Endpoint(port int) string

Endpoint returns external (from host perspective) service endpoint (host:port) for given internal port. External means that it will be accessible only from host, but not from docker containers.

If your service is not running, this method returns incorrect `stopped` endpoint.

func (*ConcreteService) Exec added in v1.0.0

func (s *ConcreteService) Exec(command *Command) (string, error)

func (*ConcreteService) Kill

func (s *ConcreteService) Kill() error

func (*ConcreteService) Name

func (s *ConcreteService) Name() string

func (*ConcreteService) NetworkEndpoint

func (s *ConcreteService) NetworkEndpoint(port int) string

NetworkEndpoint returns internal service endpoint (host:port) for given internal port. Internal means that it will be accessible only from docker containers within the network that this service is running in. If you configure your local resolver with docker DNS namespace you can access it from host as well. Use `Endpoint` for host access.

If your service is not running, use `NetworkEndpointFor` instead.

func (*ConcreteService) NetworkEndpointFor

func (s *ConcreteService) NetworkEndpointFor(networkName string, port int) string

NetworkEndpointFor returns internal service endpoint (host:port) for given internal port and network. Internal means that it will be accessible only from docker containers within the given network. If you configure your local resolver with docker DNS namespace you can access it from host as well.

This method return correct endpoint for the service in any state.

func (*ConcreteService) Ready

func (s *ConcreteService) Ready() error

func (*ConcreteService) SetBackoff

func (s *ConcreteService) SetBackoff(cfg util.BackoffConfig)

func (*ConcreteService) SetEnvVars

func (s *ConcreteService) SetEnvVars(env map[string]string)

func (*ConcreteService) SetReadinessProbe

func (s *ConcreteService) SetReadinessProbe(probe ReadinessProbe)

func (*ConcreteService) SetUser

func (s *ConcreteService) SetUser(user string)

func (*ConcreteService) Start

func (s *ConcreteService) Start(networkName, sharedDir string) (err error)

func (*ConcreteService) Stop

func (s *ConcreteService) Stop() error

func (*ConcreteService) WaitReady

func (s *ConcreteService) WaitReady() (err error)

func (*ConcreteService) WaitStarted

func (s *ConcreteService) WaitStarted() (err error)

type GetMetricValueFunc added in v1.3.0

type GetMetricValueFunc func(m *io_prometheus_client.Metric) float64

GetMetricValueFunc defined the signature of a function used to get the metric value.

type HTTPReadinessProbe added in v1.0.0

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

HTTPReadinessProbe checks readiness by making HTTP call and checking for expected HTTP status code

func NewHTTPReadinessProbe added in v1.0.0

func NewHTTPReadinessProbe(port int, path string, expectedStatusRangeStart, expectedStatusRangeEnd int) *HTTPReadinessProbe

func (*HTTPReadinessProbe) Ready added in v1.0.0

func (p *HTTPReadinessProbe) Ready(service *ConcreteService) (err error)

type HTTPService

type HTTPService struct {
	*ConcreteService
	// contains filtered or unexported fields
}

HTTPService represents opinionated microservice with at least HTTP port that as mandatory requirement, serves metrics.

func NewHTTPService

func NewHTTPService(
	name string,
	image string,
	command *Command,
	readiness ReadinessProbe,
	httpPort int,
	otherPorts ...int,
) *HTTPService

func (*HTTPService) HTTPEndpoint

func (s *HTTPService) HTTPEndpoint() string

func (*HTTPService) HTTPPort

func (s *HTTPService) HTTPPort() int

func (*HTTPService) Metrics

func (s *HTTPService) Metrics() (_ string, err error)

func (*HTTPService) NetworkHTTPEndpoint

func (s *HTTPService) NetworkHTTPEndpoint() string

func (*HTTPService) NetworkHTTPEndpointFor

func (s *HTTPService) NetworkHTTPEndpointFor(networkName string) string

func (*HTTPService) SumMetrics added in v1.1.0

func (s *HTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error)

SumMetrics returns the sum of the values of each given metric names.

func (*HTTPService) WaitRemovedMetric added in v1.3.0

func (s *HTTPService) WaitRemovedMetric(metricName string, opts ...MetricsOption) error

WaitRemovedMetric waits until a metric disappear from the list of metrics exported by the service.

func (*HTTPService) WaitSumMetrics

func (s *HTTPService) WaitSumMetrics(isExpected func(sums ...float64) bool, metricNames ...string) error

WaitSumMetrics waits for at least one instance of each given metric names to be present and their sums, returning true when passed to given isExpected(...).

func (*HTTPService) WaitSumMetricsWithOptions added in v1.3.0

func (s *HTTPService) WaitSumMetricsWithOptions(isExpected func(sums ...float64) bool, metricNames []string, opts ...MetricsOption) error

type LinePrefixLogger added in v1.0.0

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

func (*LinePrefixLogger) Write added in v1.0.0

func (w *LinePrefixLogger) Write(p []byte) (n int, err error)

type Logger added in v1.0.0

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

func NewLogger added in v1.0.0

func NewLogger(w io.Writer) *Logger

func (*Logger) Log added in v1.0.0

func (l *Logger) Log(keyvals ...interface{}) error

type MetricsOption added in v1.3.0

type MetricsOption func(*MetricsOptions)

MetricsOption defined the signature of a function used to manipulate options.

func WithLabelMatchers added in v1.3.0

func WithLabelMatchers(matchers ...*labels.Matcher) MetricsOption

WithLabelMatchers is an option to filter only matching series.

type MetricsOptions added in v1.3.0

type MetricsOptions struct {
	GetValue           GetMetricValueFunc
	LabelMatchers      []*labels.Matcher
	WaitMissingMetrics bool
}

MetricsOptions is the structure holding all options.

type ReadinessProbe

type ReadinessProbe interface {
	Ready(service *ConcreteService) (err error)
}

type Scenario

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

func NewScenario

func NewScenario(networkName string) (*Scenario, error)

func (*Scenario) Close

func (s *Scenario) Close()

func (*Scenario) NetworkName

func (s *Scenario) NetworkName() string

NetworkName returns the network name that scenario is responsible for.

func (*Scenario) SharedDir

func (s *Scenario) SharedDir() string

SharedDir returns the absolute path of the directory on the host that is shared with all services in docker.

func (*Scenario) Start

func (s *Scenario) Start(services ...Service) error

func (*Scenario) StartAndWaitReady

func (s *Scenario) StartAndWaitReady(services ...Service) error

func (*Scenario) Stop

func (s *Scenario) Stop(services ...Service) error

func (*Scenario) WaitReady

func (s *Scenario) WaitReady(services ...Service) error

type Service

type Service interface {
	Name() string
	Start(networkName, dir string) error
	WaitReady() error

	// It should be ok to Stop and Kill more than once, with next invokes being noop.
	Kill() error
	Stop() error
}

type TCPReadinessProbe added in v1.0.0

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

TCPReadinessProbe checks readiness by ensure a TCP connection can be established.

func NewTCPReadinessProbe added in v1.0.0

func NewTCPReadinessProbe(port int) *TCPReadinessProbe

func (*TCPReadinessProbe) Ready added in v1.0.0

func (p *TCPReadinessProbe) Ready(service *ConcreteService) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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