Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from grafana/paul/upgrade-k6
Browse files Browse the repository at this point in the history
Update project to latest k6 and CI
  • Loading branch information
javaducky authored Aug 3, 2023
2 parents 9d267e4 + 3bb3d0e commit 1011112
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 123 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,38 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18.x
- name: Get module name
run: |
echo "::set-output name=Module::$(go list -m)"
id: module-name
- name: Verify builds with xk6
go-version: 1.20.x
- name: Check build
run: |
go version
pwd && ls -l
go install go.k6.io/xk6/cmd/xk6@latest
xk6 build --with ${{ steps.module-name.outputs.Module }}=.
MODULE_NAME=$(go list -m)
xk6 build \
--output ./k6ext \
--with $MODULE_NAME="."
./k6ext version
run-unit-tests:
runs-on: ubuntu-latest
test-go-versions:
strategy:
fail-fast: false
matrix:
go-version: [1.19.x, 1.20.x]
platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
- name: Install Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: 1.18.x
- name: Run unit tests
run: go test -v -cover -race ./...
go-version: ${{ matrix.go-version }}
- name: Run tests
run: |
which go
go version
go test -race -timeout 60s ./...
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18.x
go-version: 1.20.x
- name: Check module dependencies
run: |
go version
test -z "$(go mod tidy && git status go.* --porcelain)"
go mod verify
run-golangci:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18.x
go-version: 1.20.x
- name: Retrieve golangci-lint version
run: |
echo "::set-output name=Version::$(head -n 1 "${GITHUB_WORKSPACE}/.golangci.yml" | tr -d '# ')"
Expand Down
140 changes: 92 additions & 48 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# v1.47.2
# Please don't remove the first line. It is used in CI to determine the golangci version
# v1.53.3
# Please don't remove the first line. It uses in CI to determine the golangci version
run:
deadline: 5m

Expand All @@ -21,64 +21,108 @@ issues:
linters:
- cyclop
- dupl
- funlen
- gocognit
- funlen
- lll
- linters:
- paralleltest # false positive: https://github.com/kunwardeep/paralleltest/issues/8.
text: "does not use range value in test Run"
- staticcheck # Tracked in https://github.com/grafana/xk6-grpc/issues/14
text: "The entire proto file grpc/reflection/v1alpha/reflection.proto is marked as deprecated."
- linters:
- forbidigo
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
exhaustive:
default-signifies-exhaustive: true
funlen:
lines: 80
statements: 60
goconst:
min-len: 10
min-occurrences: 4
govet:
check-shadowing: true
maligned:
suggest-new: true
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
funlen:
lines: 80
statements: 60
forbidigo:
forbid:
- '^(fmt\\.Print(|f|ln)|print|println)$'
# Forbid everything in os, except os.Signal and os.SyscalError
- '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?'
# Forbid everything in syscall except the uppercase constants
- '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?'
- '^logrus\.Logger$'

linters:
enable-all: true
disable:
- decorder
- execinquery
- exhaustivestruct
- exhaustruct
- gci
- gochecknoinits
- gocyclo # replaced by cyclop since it also calculates the package complexity
- godot
- godox
- goerr113 # most of the errors here are meant for humans
- goheader
- golint # this linter is deprecated
- gomnd
- gomodguard
- grouper
- interfacer # deprecated
- ireturn
- maintidx
- maligned # replaced by govet 'fieldalignment'
- nlreturn
- nonamedreturns
- nosnakecase
- scopelint # deprecated, replaced by exportloopref
- tagliatelle
- testpackage
- thelper
- varnamelen
- wrapcheck # a little bit too much for k6, maybe after https://github.com/tomarrell/wrapcheck/issues/2 is fixed
- wsl
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- cyclop
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- gocognit
- goconst
- gocritic
- gofmt
- gofumpt
- goimports
- gomoddirectives
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- promlinter
- revive
- reassign
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
fast: false
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,25 @@ default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1
```

Inspect examples folder for more details.

# Testing Locally

This repository includes a [docker-compose.yml](./docker-compose.yml) file that starts RabbitMQ with Management Plugin for testing the extension locally.

> :warning: This environment is intended for testing only and should not be used for production purposes.
1. Start the docker compose environment.
```bash
docker compose up -d
```
Output should appear similar to the following:
```shell
✔ Network xk6-amqp_default Created ... 0.0s
✔ Container xk6-amqp-rabbitmq-1 Started ... 0.2s
```
2. Use your [custom k6 binary](#build) to run a k6 test script connecting to your RabbitMQ server started in the previous step.
```bash
./k6 run examples/test.js
```
3. Use the RabbitMQ admin console by accessing [http://localhost:15672/](http://localhost:15672/), then login using `guest` for both the Username and Password.
This will allow you to monitor activity within your messaging server.
18 changes: 9 additions & 9 deletions amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.k6.io/k6/js/modules"
)

const version = "v0.3.0"
const version = "v0.4.0"

// AMQP type holds connection to a remote AMQP server.
type AMQP struct {
Expand All @@ -39,14 +39,14 @@ type PublishOptions struct {
Mandatory bool
Immediate bool
Persistent bool
CorrelationId string
CorrelationID string
ReplyTo string
Expiration string
MessageId string
MessageID string
Timestamp int64 // unix epoch timestamp in seconds
Type string
UserId string
AppId string
UserID string
AppID string
}

// ConsumeOptions defines options for use when consuming a message.
Expand Down Expand Up @@ -145,13 +145,13 @@ func (amqp *AMQP) Publish(options PublishOptions) error {
publishing.Timestamp = time.Unix(options.Timestamp, 0)
}

publishing.CorrelationId = options.CorrelationId
publishing.CorrelationId = options.CorrelationID
publishing.ReplyTo = options.ReplyTo
publishing.Expiration = options.Expiration
publishing.MessageId = options.MessageId
publishing.MessageId = options.MessageID
publishing.Type = options.Type
publishing.UserId = options.UserId
publishing.AppId = options.AppId
publishing.UserId = options.UserID
publishing.AppId = options.AppID

return ch.PublishWithContext(
context.Background(), // TODO: use vu context
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.8'

services:
rabbitmq:
image: rabbitmq:3-management
ports:
- "5672:5672"
- "15672:15672"
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
module github.com/grafana/xk6-amqp

go 1.17
go 1.19

require (
github.com/rabbitmq/amqp091-go v1.5.0
github.com/vmihailenco/msgpack/v5 v5.3.5
go.k6.io/k6 v0.42.0
go.k6.io/k6 v0.45.0
)

require (
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dop251/goja v0.0.0-20221106173738-3b8a68ca89b4 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/dlclark/regexp2 v1.9.0 // indirect
github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mstoykov/atlas v0.0.0-20220808085829-90340e9998bd // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.24.2 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/guregu/null.v3 v3.3.0 // indirect
)
Loading

0 comments on commit 1011112

Please sign in to comment.