Skip to content

Commit

Permalink
Merge branch 'master' into release-v0.51.0
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Apr 29, 2024
2 parents e057ede + ace4bb4 commit a1c53b5
Show file tree
Hide file tree
Showing 617 changed files with 21,545 additions and 71,701 deletions.
3 changes: 1 addition & 2 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
check-latest: true
- name: Get golangci-lint version and download rules
shell: bash
Expand All @@ -28,5 +28,4 @@ runs:
uses: golangci/golangci-lint-action@349d20632dbaed38f0a492cc991152e3d351e854 # latest commit at the time that uses node20
with:
version: ${{ steps.getenv.outputs.GolangCIVersion }}
only-new-issues: true
args: "--config=${{ github.action_path }}/.golangci.yml"
21 changes: 1 addition & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:
APP_NAME: "k6"
DOCKER_IMAGE_ID: "grafana/k6"
GHCR_IMAGE_ID: ${{ github.repository }}
DEFAULT_GO_VERSION: "1.21.x"
DEFAULT_GO_VERSION: "1.22.x"

jobs:
configure:
Expand Down Expand Up @@ -287,25 +287,6 @@ jobs:
packaging/k6-*.msi
retention-days: 7

# Disabled until #1997 and #1998 are addressed.
# publish-macos:
# runs-on: macos-latest
# needs: [configure, build]
# if: ${{ startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }}
# env:
# VERSION: ${{ needs.configure.outputs.k6_version }}
# HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
# steps:
# - name: Download source code archive
# run: curl -fsSL "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/archive/${VERSION}.tar.gz" -o "${VERSION}.tar.gz"
# - name: Set up Homebrew
# uses: Homebrew/actions/setup-homebrew@2eb78889a50ba021d744837934f1af2d8c4458ec
# - name: Create version bump PR
# run: |
# brew bump-formula-pr k6 \
# --url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/archive/${VERSION}.tar.gz" \
# --sha256="$(shasum -a 256 ${VERSION}.tar.gz | cut -d' ' -f1)"

publish-github:
runs-on: ubuntu-latest
needs: [configure, build, package-windows]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
check-latest: true
- name: Check dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tc39.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
check-latest: true
- name: Run tests
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.20.x]
platform: [ubuntu-latest, windows-2019, macos-latest]
go-version: [1.21.x]
platform: [ubuntu-latest, windows-2019]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-2019, macos-latest]
platform: [ubuntu-latest, windows-2019]
runs-on: ${{ matrix.platform }}
continue-on-error: true
steps:
Expand Down Expand Up @@ -86,8 +86,8 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.21.x]
platform: [ubuntu-latest, windows-2019, macos-latest]
go-version: [1.22.x]
platform: [ubuntu-latest, windows-2019]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/wpt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Web Platform Tests
on:
workflow_dispatch:
pull_request:

defaults:
run:
shell: bash

jobs:
streams:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
check-latest: true
- name: Run tests
run: |
set -x
cd js/modules/k6/experimental/streams/tests
sh checkout.sh
go test ../... -tags=wpt
2 changes: 1 addition & 1 deletion .github/workflows/xk6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
check-latest: true
- name: Install Go tip
if: matrix.go == 'tip'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/dist
/pkg-build
/js/tc39/TestTC39
/js/modules/k6/experimental/streams/tests/wpt

.vscode
*.sublime-workspace
Expand Down
16 changes: 7 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# v1.55.2
# v1.57.2
# Please don't remove the first line. It uses in CI to determine the golangci version
run:
deadline: 5m
timeout: 5m

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
Expand All @@ -24,6 +24,11 @@ issues:
- gocognit
- funlen
- lll
- forcetypeassert
- path: js\/modules\/k6\/html\/.*\.go
text: "exported: exported "
linters:
- revive
- path: js\/modules\/k6\/http\/.*_test\.go
linters:
# k6/http module's tests are quite complex because they often have several nested levels.
Expand All @@ -38,17 +43,10 @@ issues:
text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden'

linters-settings:
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
exhaustive:
default-signifies-exhaustive: true
govet:
check-shadowing: true
cyclop:
max-complexity: 25
maligned:
suggest-new: true
dupl:
threshold: 150
goconst:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For alternative ways of cloning the k6 repository, please refer to [GitHub's clo

#### Running the linter

We make use of the [golangci-lint](https://github.com/golangci/golangci-lint) tool to lint the code in CI. The actual version you can find in our [`.golangci.yml`](https://github.com/grafana/k6/blob/master/.golangci.yml#L1). To run it locally, first [install it](https://golangci-lint.run/usage/install/#local-installation), then run:
We make use of the [golangci-lint](https://github.com/golangci/golangci-lint) tool to lint the code in CI. The actual version you can find in our [`.golangci.yml`](https://github.com/grafana/k6/blob/master/.golangci.yml#L1). To run it locally, first [install it](https://golangci-lint.run/welcome/install/#local-installation), then run:

```bash
make lint
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.21-alpine3.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.22-alpine3.19 as builder
WORKDIR $GOPATH/src/go.k6.io/k6
COPY . .
ARG TARGETOS TARGETARCH
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check-linter-version:
## lint: Runs the linters.
lint: check-linter-version
echo "Running linters..."
golangci-lint run --out-format=tab --new-from-rev master ./...
golangci-lint run --out-format=tab ./...

## tests: Executes any unit tests.
tests:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Our team is dedicated to continuously improving and providing the best user expe

We hope it provides a clear overview of our plans for future development. We welcome feedback, corrections, and suggestions via GitHub to make it more comprehensive, accessible, and valuable for the community.

It's worth mentioning that we consider [upvotes (thumbs-up)](https://github.com/grafana/k6/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc) to be one of the essential metrics for determining community needs. If you want to show us the importance of a feature, please give it a thumbs-up.

## Contribute

If you want to contribute or help with the development of k6, start by reading [CONTRIBUTING.md](CONTRIBUTING.md). Before you start coding, it might be a good idea to first discuss your plans and implementation details with the k6 maintainers—especially when it comes to big changes and features. You can do this in the [GitHub issue](https://github.com/grafana/k6/issues) for the problem you're solving (create one if it doesn't exist).
Expand Down
4 changes: 2 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newHandler(cs *v1.ControlSurface, profilingEnabled bool) http.Handler {
func injectProfilerHandler(mux *http.ServeMux, profilingEnabled bool) {
var handler http.Handler

handler = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
handler = http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "text/plain; charset=utf-8")
_, _ = rw.Write([]byte("To enable profiling, please run k6 with the --profiling-enabled flag"))
})
Expand Down Expand Up @@ -91,7 +91,7 @@ func withLoggingHandler(l logrus.FieldLogger, next http.Handler) http.HandlerFun
}

func handlePing(logger logrus.FieldLogger) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
rw.Header().Add("Content-Type", "text/plain; charset=utf-8")
if _, err := fmt.Fprint(rw, "ok"); err != nil {
logger.WithError(err).Error("Error while printing ok")
Expand Down
6 changes: 3 additions & 3 deletions cloudapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCreateTestRun(t *testing.T) {

func TestFinished(t *testing.T) {
t.Parallel()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
fprint(t, w, "")
}))
defer server.Close()
Expand All @@ -70,7 +70,7 @@ func TestFinished(t *testing.T) {
func TestAuthorizedError(t *testing.T) {
t.Parallel()
called := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
called++
w.WriteHeader(http.StatusForbidden)
fprint(t, w, `{"error": {"code": 5, "message": "Not allowed"}}`)
Expand All @@ -89,7 +89,7 @@ func TestAuthorizedError(t *testing.T) {
func TestDetailsError(t *testing.T) {
t.Parallel()
called := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
called++
w.WriteHeader(http.StatusForbidden)
fprint(t, w, `{"error": {"code": 0, "message": "Validation failed", "details": { "name": ["Shorter than minimum length 2."]}}}`)
Expand Down
8 changes: 1 addition & 7 deletions cloudapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cloudapi

import (
"bytes"
"crypto/rand"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"math/rand"
"net/http"
"time"

Expand Down Expand Up @@ -230,15 +230,9 @@ func shouldAddIdempotencyKey(req *http.Request) bool {

// randomStrHex returns a hex string which can be used
// for session token id or idempotency key.
//
//nolint:gosec
func randomStrHex() string {
// 16 hex characters
b := make([]byte, 8)
_, _ = rand.Read(b)
return hex.EncodeToString(b)
}

func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
2 changes: 1 addition & 1 deletion cloudapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func NewConfig() Config {

// Apply saves config non-zero config values from the passed config in the receiver.
//
//nolint:funlen,gocognit,cyclop
//nolint:cyclop
func (c Config) Apply(cfg Config) Config {
if cfg.Token.Valid {
c.Token = cfg.Token
Expand Down
2 changes: 1 addition & 1 deletion cloudapi/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestConfigApply(t *testing.T) {
TracesEnabled: null.NewBool(true, true),
TracesHost: null.NewString("TracesHost", true),
TracesPushInterval: types.NewNullDuration(10*time.Second, true),
TracesPushConcurrency: null.NewInt(6, true),
TracesPushConcurrency: null.NewInt(6, true),
}

assert.Equal(t, full, full.Apply(empty))
Expand Down
2 changes: 1 addition & 1 deletion cloudapi/insights/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestClient_Dial_ReturnsNoErrorWithFailingDialer(t *testing.T) {
Block: true,
FailOnNonTempDialError: true,
Timeout: 1 * time.Second,
Dialer: func(ctx context.Context, s string) (net.Conn, error) {
Dialer: func(_ context.Context, _ string) (net.Conn, error) {
return nil, &fatalError{}
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func getNullString(flags *pflag.FlagSet, key string) null.String {
}

func exactArgsWithMsg(n int, msg string) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
return func(_ *cobra.Command, args []string) error {
if len(args) != n {
return fmt.Errorf("accepts %d arg(s), received %d: %s", n, len(args), msg)
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/config_consolidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
{opts{cli: []string{"--system-tags", `""`}}, exp{}, func(t *testing.T, c Config) {
assert.Equal(t, metrics.SystemTagSet(0), *c.Options.SystemTags)
}},
{opts{env: []string{`K6_SYSTEM_TAGS=""`}}, exp{}, func(t *testing.T, c Config) {
assert.Equal(t, metrics.SystemTagSet(0), *c.Options.SystemTags)
}},
{opts{env: []string{`K6_SYSTEM_TAGS=proto,method`}}, exp{}, func(t *testing.T, c Config) {
assert.Equal(t, metrics.SystemTagSet(metrics.TagProto|metrics.TagMethod), *c.Options.SystemTags)
}},
{
opts{
runner: &lib.Options{
Expand Down Expand Up @@ -479,6 +485,16 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
},
nil,
},
{
opts{
env: []string{"K6_PROFILING_ENABLED=true"},
cli: []string{"--profiling-enabled"},
},
exp{
consolidationError: false,
},
nil,
},
// TODO: test for differences between flagsets
// TODO: more tests in general, especially ones not related to execution parameters...
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getCmdLogin(gs *state.GlobalState) *cobra.Command {
Logging into a service changes the default when just "-o [type]" is passed with
no parameters, you can always override the stored credentials by passing some
on the commandline.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Usage()
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getCmdLoginCloud(gs *state.GlobalState) *cobra.Command {
This will set the default token used when just "k6 run -o cloud" is passed.`,
Example: exampleText,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
currentDiskConf, err := readDiskConfig(gs)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/login_influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func getCmdLoginInfluxDB(gs *state.GlobalState) *cobra.Command {
This will set the default server used when just "-o influxdb" is passed.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
config, err := readDiskConfig(gs)
if err != nil {
return err
Expand All @@ -40,7 +40,7 @@ This will set the default server used when just "-o influxdb" is passed.`,
conf = conf.Apply(jsonConfParsed)
}
if len(args) > 0 {
urlConf, err := influxdb.ParseURL(args[0]) //nolint:govet
urlConf, err := influxdb.ParseURL(args[0])
if err != nil {
return err
}
Expand Down

0 comments on commit a1c53b5

Please sign in to comment.