cloud

package
v0.0.0-...-6202178 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package cloud implements an Output that flushes to the k6 Cloud platform using the version1 of the protocol flushing a json-based payload.

Index

Constants

View Source
const (
	DataTypeSingle             = "Point"
	DataTypeMap                = "Points"
	DataTypeAggregatedHTTPReqs = "AggregatedPoints"
)

DataType constants

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedMetric

type AggregatedMetric struct {

	// Updated by Calc() and used in the JSON output
	Min float64 `json:"min"`
	Max float64 `json:"max"`
	Avg float64 `json:"avg"`
	// contains filtered or unexported fields
}

AggregatedMetric is used to store aggregated information for a particular metric in an SampleDataAggregatedMap.

func (*AggregatedMetric) Add

func (am *AggregatedMetric) Add(t time.Duration)

Add the new duration to the internal sum and update Min and Max if necessary

func (*AggregatedMetric) Calc

func (am *AggregatedMetric) Calc(count float64)

Calc populates the float fields for min and max and calculates the average value

type AggregatedRate

type AggregatedRate struct {
	Count   float64 `json:"count"`
	NzCount float64 `json:"nz_count"`
}

AggregatedRate is an aggregation of a Rate metric

func (*AggregatedRate) Add

func (ar *AggregatedRate) Add(b bool)

Add a boolean to the aggregated rate

func (AggregatedRate) IsDefined

func (ar AggregatedRate) IsDefined() bool

IsDefined implements easyjson.Optional

type MetricsClient

type MetricsClient struct {
	*cloudapi.Client
	// contains filtered or unexported fields
}

MetricsClient is a wrapper around the cloudapi.Client that is also capable of pushing

func NewMetricsClient

func NewMetricsClient(client *cloudapi.Client, logger logrus.FieldLogger, host string, noCompress bool) *MetricsClient

NewMetricsClient creates and initializes a new MetricsClient.

func (*MetricsClient) PushMetric

func (mc *MetricsClient) PushMetric(referenceID string, s []*Sample) error

PushMetric pushes the provided metric samples for the given referenceID

type Output

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

Output sends result data to the k6 Cloud service.

func New

func New(logger logrus.FieldLogger, conf cloudapi.Config, testAPIClient *cloudapi.Client) (*Output, error)

New creates a new Cloud output version 1.

func (*Output) AddMetricSamples

func (out *Output) AddMetricSamples(sampleContainers []metrics.SampleContainer)

AddMetricSamples receives a set of metric samples. This method is never called concurrently, so it defers as much of the work as possible to the asynchronous goroutines initialized in Start().

func (*Output) SetTestRunID

func (out *Output) SetTestRunID(id string)

SetTestRunID sets the passed test run id.

func (*Output) SetTestRunStopCallback

func (out *Output) SetTestRunStopCallback(stopFunc func(error))

SetTestRunStopCallback receives the function that stops the engine on error

func (*Output) Start

func (out *Output) Start() error

Start starts the Output, it starts the background goroutines for aggregating and flushing the collected metrics samples.

func (*Output) StopWithTestError

func (out *Output) StopWithTestError(testErr error) error

StopWithTestError gracefully stops all metric emission from the output: when all metric samples are emitted, it makes a cloud API call to finish the test run. If testErr was specified, it extracts the RunStatus from it.

type Sample

type Sample struct {
	Type   string      `json:"type"`
	Metric string      `json:"metric"`
	Data   interface{} `json:"data"`
}

Sample is the generic struct that contains all types of data that we send to the cloud.

func NewSampleFromTrail

func NewSampleFromTrail(trail *httpext.Trail) *Sample

NewSampleFromTrail just creates a ready-to-send Sample instance directly from a httpext.Trail.

func (Sample) MarshalEasyJSON

func (v Sample) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*Sample) UnmarshalEasyJSON

func (v *Sample) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Sample) UnmarshalJSON

func (ct *Sample) UnmarshalJSON(p []byte) error

UnmarshalJSON decodes the Data into the corresponding struct

type SampleDataAggregatedHTTPReqs

type SampleDataAggregatedHTTPReqs struct {
	Time   int64           `json:"time,string"`
	Type   string          `json:"type"`
	Count  uint64          `json:"count"`
	Tags   json.RawMessage `json:"tags,omitempty"`
	Values struct {
		Duration       AggregatedMetric `json:"http_req_duration"`
		Blocked        AggregatedMetric `json:"http_req_blocked"`
		Connecting     AggregatedMetric `json:"http_req_connecting"`
		TLSHandshaking AggregatedMetric `json:"http_req_tls_handshaking"`
		Sending        AggregatedMetric `json:"http_req_sending"`
		Waiting        AggregatedMetric `json:"http_req_waiting"`
		Receiving      AggregatedMetric `json:"http_req_receiving"`
		Failed         AggregatedRate   `json:"http_req_failed,omitempty"`
	} `json:"values"`
}

SampleDataAggregatedHTTPReqs is used in aggregated samples for HTTP requests.

func (*SampleDataAggregatedHTTPReqs) Add

func (sdagg *SampleDataAggregatedHTTPReqs) Add(trail *httpext.Trail)

Add updates all agregated values with the supplied trail data

func (*SampleDataAggregatedHTTPReqs) CalcAverages

func (sdagg *SampleDataAggregatedHTTPReqs) CalcAverages()

CalcAverages calculates and sets all `Avg` properties in the `Values` struct

func (SampleDataAggregatedHTTPReqs) MarshalEasyJSON

func (v SampleDataAggregatedHTTPReqs) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*SampleDataAggregatedHTTPReqs) UnmarshalEasyJSON

func (v *SampleDataAggregatedHTTPReqs) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

type SampleDataMap

type SampleDataMap struct {
	Time   int64              `json:"time,string"`
	Type   metrics.MetricType `json:"type"`
	Tags   json.RawMessage    `json:"tags,omitempty"`
	Values map[string]float64 `json:"values,omitempty"`
}

SampleDataMap is used by samples that contain multiple values, currently that's only iteration metrics (`iter_li_all`) and unaggregated HTTP requests (`http_req_li_all`).

func (SampleDataMap) MarshalEasyJSON

func (v SampleDataMap) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*SampleDataMap) UnmarshalEasyJSON

func (v *SampleDataMap) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

type SampleDataSingle

type SampleDataSingle struct {
	Time  int64              `json:"time,string"`
	Type  metrics.MetricType `json:"type"`
	Tags  json.RawMessage    `json:"tags,omitempty"`
	Value float64            `json:"value"`
}

SampleDataSingle is used in all simple un-aggregated single-value samples.

func (SampleDataSingle) MarshalEasyJSON

func (v SampleDataSingle) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*SampleDataSingle) UnmarshalEasyJSON

func (v *SampleDataSingle) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

Jump to

Keyboard shortcuts

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