Documentation
¶
Overview ¶
Package cloudapi contains several things related to the k6 cloud API v6- various data and config structures, a REST API client, error handling, etc. They are all used in cloud tests (i.e. `k6 cloud`), and in local tests emitting their results to the k6 cloud output (i.e. `k6 run --out cloud`).
Index ¶
Constants ¶
const ( // RetryInterval is the default cloud request retry interval RetryInterval = 500 * time.Millisecond // MaxRetries specifies max retry attempts MaxRetries = 3 )
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse checks the parsed response. It returns nil if the code is in the successful range, otherwise it tries to parse the body and return a parsed error.
func GetTemporaryCloudConfig ¶
func GetTemporaryCloudConfig(cloudConfig json.RawMessage) (map[string]any, error)
GetTemporaryCloudConfig returns a temporary cloud config. Original comment TODO: Fix this We reuse cloud.Config for parsing options.cloud, but this probably shouldn't be done, as the idea of options.ext is that they are extensible without touching k6. But in order for this to happen, we shouldn't actually marshal cloud.Config on top of it, because it will be missing some fields that aren't actually mentioned in the struct. So in order for use to copy the fields that we need for k6 cloud's api we unmarshal in map[string]any and copy what we need if it isn't set already
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles communication with the k6 Cloud API.
func NewClient ¶
func NewClient(logger logrus.FieldLogger, token, host, version string, timeout time.Duration) (*Client, error)
NewClient return a new client for the cloud API
func (*Client) SetStackID ¶
SetStackID sets the stack ID for the client.
func (*Client) ValidateToken ¶
func (c *Client) ValidateToken(stackURL string) (_ *k6cloud.AuthenticationResponse, err error)
ValidateToken calls the endpoint to validate the Client's token and returns the result.
type Config ¶
type Config struct {
// TODO: refactor common stuff between cloud execution and output
Token null.String `json:"token" envconfig:"K6_CLOUD_TOKEN"`
StackID null.Int `json:"stackID" envconfig:"K6_CLOUD_STACK_ID"`
ProjectID null.Int `json:"projectID" envconfig:"K6_CLOUD_PROJECT_ID"`
Name null.String `json:"name" envconfig:"K6_CLOUD_NAME"`
Host null.String `json:"host" envconfig:"K6_CLOUD_HOST"`
Timeout types.NullDuration `json:"timeout" envconfig:"K6_CLOUD_TIMEOUT"`
LogsTailURL null.String `json:"-" envconfig:"K6_CLOUD_LOGS_TAIL_URL"`
WebAppURL null.String `json:"webAppURL" envconfig:"K6_CLOUD_WEB_APP_URL"`
TestRunDetails null.String `json:"testRunDetails" envconfig:"K6_CLOUD_TEST_RUN_DETAILS"`
NoCompress null.Bool `json:"noCompress" envconfig:"K6_CLOUD_NO_COMPRESS"`
StopOnError null.Bool `json:"stopOnError" envconfig:"K6_CLOUD_STOP_ON_ERROR"`
APIVersion null.Int `json:"apiVersion" envconfig:"K6_CLOUD_API_VERSION"`
// PushRefID is the identifier used by k6 Cloud to correlate all the things that
// belong to the same test run/execution. Currently, it is equivalent to the test run id.
// But, in the future, or in future solutions (e.g. Synthetic Monitoring), there might be
// no test run id, and we may still need an identifier to correlate all the things.
PushRefID null.String `json:"pushRefID" envconfig:"K6_CLOUD_PUSH_REF_ID"`
// Defines the max allowed number of time series in a single batch.
MaxTimeSeriesInBatch null.Int `json:"maxTimeSeriesInBatch" envconfig:"K6_CLOUD_MAX_TIME_SERIES_IN_BATCH"`
// The time interval between periodic API calls for sending samples to the cloud ingest service.
MetricPushInterval types.NullDuration `json:"metricPushInterval" envconfig:"K6_CLOUD_METRIC_PUSH_INTERVAL"`
// This is how many concurrent pushes will be done at the same time to the cloud
MetricPushConcurrency null.Int `json:"metricPushConcurrency" envconfig:"K6_CLOUD_METRIC_PUSH_CONCURRENCY"`
// If specified and is greater than 0, sample aggregation with that period is enabled
AggregationPeriod types.NullDuration `json:"aggregationPeriod" envconfig:"K6_CLOUD_AGGREGATION_PERIOD"`
// If aggregation is enabled, this specifies how long we'll wait for period samples to accumulate before trying to aggregate them.
AggregationWaitPeriod types.NullDuration `json:"aggregationWaitPeriod" envconfig:"K6_CLOUD_AGGREGATION_WAIT_PERIOD"`
// Indicates whether to send traces to the k6 Insights backend service.
TracesEnabled null.Bool `json:"tracesEnabled" envconfig:"K6_CLOUD_TRACES_ENABLED"`
// The host of the k6 Insights backend service.
TracesHost null.String `json:"traceHost" envconfig:"K6_CLOUD_TRACES_HOST"`
// This is how many concurrent pushes will be done at the same time to the cloud
TracesPushConcurrency null.Int `json:"tracesPushConcurrency" envconfig:"K6_CLOUD_TRACES_PUSH_CONCURRENCY"`
// The time interval between periodic API calls for sending samples to the cloud ingest service.
TracesPushInterval types.NullDuration `json:"tracesPushInterval" envconfig:"K6_CLOUD_TRACES_PUSH_INTERVAL"`
}
Config holds all the necessary data and options for sending metrics to the k6 Cloud.
func GetConsolidatedConfig ¶
func GetConsolidatedConfig( jsonRawConf json.RawMessage, env map[string]string, configArg string, cloudConfig json.RawMessage, ) (Config, error)
GetConsolidatedConfig combines the default config values with the JSON config values and environment variables and returns the final result.
type ResponseError ¶
type ResponseError struct {
Response *http.Response `json:"-"`
APIError k6cloud.ErrorApiModel `json:"error"`
}
ResponseError represents an error cause by talking to the API
func (ResponseError) Error ¶
func (e ResponseError) Error() string