Overview
The cloud output (internal/output/cloud/output.go:55) sends metrics, traces, and test metadata to Grafana Cloud k6, providing:
- Real-time test monitoring
- Performance trend analysis
- Collaborative result sharing
- Threshold evaluation tracking
- Test run comparison
- Distributed test execution
Authentication
Before using the cloud output, authenticate with your k6 Cloud token:Basic Usage
Run a test with cloud output:- Create a test run in k6 Cloud
- Stream metrics during execution
- Display a URL to view results in real-time
- Finalize the test run on completion
Configuration
Via Script Options
Configure cloud settings in your test script:Via Environment Variables
All cloud configuration options can be set via environment variables:Environment variables take precedence over script options, allowing you to override settings without modifying test code.
Configuration Options
The cloud configuration (cloudapi/config.go:20) supports extensive options:
Basic Settings
- name: Test run name (default: script filename)
- projectID: k6 Cloud project ID
- token: Authentication token
Advanced Settings
- host: Ingest endpoint URL (default:
https://ingest.k6.io) - webAppURL: Web application URL for viewing results
- timeout: API request timeout (default: 1 minute)
- noCompress: Disable metric compression
- stopOnError: Stop test on cloud API errors
Metrics Streaming
- metricPushInterval: How often to send metrics (default: 1 second)
- metricPushConcurrency: Concurrent push connections (default: 1)
- maxTimeSeriesInBatch: Max time series per batch (default: 1000)
- aggregationPeriod: Metric aggregation window (default: 3 seconds)
- aggregationWaitPeriod: Wait time before aggregation (default: 8 seconds)
Traces
- tracesEnabled: Enable trace collection (default: true)
- tracesHost: Traces backend endpoint
- tracesPushInterval: Trace push interval (default: 1 second)
- tracesPushConcurrency: Concurrent trace pushes (default: 1)
Test Run Lifecycle
Required System Tags
The cloud output requires these system tags to be enabled (internal/output/cloud/output.go:158):
name: Request/metric namemethod: HTTP methodstatus: HTTP status codeerror: Error informationcheck: Check namegroup: Group hierarchy
Test Run Status
The cloud output reports detailed test run status (cloudapi/run_status.go):
- Finished: Test completed normally
- Aborted by user: User interrupted (Ctrl+C)
- Aborted by threshold: Threshold failure triggered abort
- Aborted by script error: Script error caused early termination
- Aborted by timeout: Test exceeded time limit
- Aborted by system: Infrastructure or cloud service issue
Direct Metric Pushing
You can push metrics directly to an existing test run without creating a new one:- Resuming interrupted tests
- Multiple k6 instances pushing to the same test run
- Custom test orchestration
Archive Upload
By default, k6 uploads the test archive (script + dependencies) to the cloud. Disable this with:The archive is required for cloud execution but optional when only streaming results from local tests.
Cloud vs Local Testing
The same cloud output is used for:- Local tests with cloud results: Run locally, stream results to cloud
- Cloud execution: Run tests on k6 Cloud infrastructure
- Distributed load generation
- Geographic load zones
- Larger scale capabilities
- No local resource constraints
API Versioning
The cloud output supports API version 2 (default):Error Handling
The cloud output can stop the test if cloud API errors occur:Troubleshooting
Authentication Failures
If you see authentication errors:- Verify your token is valid:
k6 login cloud - Check token environment variable:
echo $K6_CLOUD_TOKEN - Ensure project ID is correct
Connectivity Issues
For connection problems:- Verify you can reach the ingest endpoint
- Check firewall/proxy settings
- Try increasing the timeout value
- Enable debug logging:
k6 run --verbose --out cloud script.js
Missing Metrics
If metrics aren’t appearing:- Confirm required system tags are enabled
- Check test run URL for errors
- Verify metric names are valid
- Review aggregation settings