-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: K6 Tests | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 */1 * * *' # every hour | ||
|
||
jobs: | ||
docker: | ||
timeout-minutes: 10 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
|
||
- name: Start containers | ||
run: docker compose -f docker-compose.yml -f docker-compose.k6.workflows.yml run k6-tracetest | ||
env: | ||
TRACETEST_API_TOKEN: ${{secrets.TRACETEST_TOKEN}} | ||
POKESHOP_DEMO_URL: ${{secrets.POKESHOP_DEMO_URL}} | ||
|
||
- name: Stop containers | ||
if: always() | ||
run: docker compose -f docker-compose.yml -f docker-compose.k6.workflows.yml down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3' | ||
|
||
services: | ||
k6-tracetest: | ||
build: | ||
context: . | ||
dockerfile: k6.Dockerfile | ||
environment: | ||
XK6_TRACETEST_API_TOKEN: ${TRACETEST_API_TOKEN} | ||
POKESHOP_DEMO_URL: ${POKESHOP_DEMO_URL} | ||
depends_on: | ||
- worker | ||
- api | ||
volumes: | ||
- ./test/k6/add-pokemon.js:/import-pokemon.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: '3' | ||
|
||
services: | ||
k6-tracetest: | ||
build: | ||
context: . | ||
dockerfile: k6.Dockerfile | ||
environment: | ||
XK6_TRACETEST_API_TOKEN: ${TRACETEST_API_TOKEN} | ||
POKESHOP_DEMO_URL: ${POKESHOP_DEMO_URL} | ||
depends_on: | ||
- api | ||
- tracetest-agent | ||
- worker | ||
volumes: | ||
- ./test/k6/import-pokemon.js:/import-pokemon.js | ||
tracetest-agent: | ||
image: kubeshop/tracetest-agent:latest | ||
environment: | ||
TRACETEST_DEV: ${TRACETEST_DEV} | ||
TRACETEST_API_KEY: ${TRACETEST_AGENT_API_KEY} | ||
TRACETEST_SERVER_URL: ${TRACETEST_SERVER_URL} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.21-alpine as builder | ||
|
||
WORKDIR /app | ||
|
||
ENV CGO_ENABLED 0 | ||
RUN go install go.k6.io/xk6/cmd/xk6@latest | ||
|
||
RUN xk6 build v0.50.0 --with github.com/kubeshop/xk6-tracetest | ||
|
||
FROM alpine | ||
|
||
COPY --from=builder /app/k6 /bin/ | ||
COPY ./test/k6/import-pokemon.js . | ||
ENV XK6_TRACETEST_API_TOKEN=your-api-token | ||
ENV POKESHOP_DEMO_URL=http://localhost:8081 | ||
|
||
ENTRYPOINT k6 run /import-pokemon.js -o xk6-tracetest -e POKESHOP_DEMO_URL=$POKESHOP_DEMO_URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Http, Tracetest } from 'k6/x/tracetest'; | ||
import { sleep } from 'k6'; | ||
|
||
export const options = { | ||
vus: 5, | ||
duration: '5s', | ||
}; | ||
|
||
const POKESHOP_DEMO_URL = __ENV.POKESHOP_DEMO_URL || 'http://localhost:8081'; | ||
|
||
const http = new Http(); | ||
const tracetest = Tracetest(); | ||
|
||
export default function () { | ||
const url = `${POKESHOP_DEMO_URL}/pokemon`; | ||
const payload = JSON.stringify({ | ||
name: 'charizard', | ||
type: 'flying', | ||
imageUrl: 'https://assets.pokemon.com/assets/cms2/img/pokedex/full/006.png', | ||
isFeatured: true, | ||
}); | ||
const params = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
|
||
const definition = `type: Test | ||
spec: | ||
id: k6-tracetest-pokeshop-add-pokemon | ||
name: "K6 - Add a Pokemon" | ||
trigger: | ||
type: k6 | ||
specs: | ||
- selector: span[tracetest.span.type="http" name="POST /pokemon" http.method="POST"] | ||
name: The POST /pokemon was called correctly | ||
assertions: | ||
- attr:http.status_code = 201 | ||
- selector: span[tracetest.span.type="general" name="validate request"] | ||
name: The request sent to API is valid | ||
assertions: | ||
- attr:validation.is_valid = "true" | ||
- selector: span[tracetest.span.type="database" name="create pokeshop.pokemon" db.system="postgres" db.name="pokeshop" db.user="ashketchum" db.operation="create" db.sql.table="pokemon"] | ||
name: A Pokemon was inserted on database | ||
assertions: | ||
- attr:db.result | json_path '$.imageUrl' = "https://assets.pokemon.com/assets/cms2/img/pokedex/full/052.png" | ||
`; | ||
|
||
const response = http.post(url, payload, params); | ||
|
||
tracetest.runTest( | ||
response.trace_id, | ||
{ | ||
definition, | ||
should_wait: true, | ||
}, | ||
{ | ||
url, | ||
method: 'GET', | ||
} | ||
); | ||
|
||
sleep(1); | ||
} | ||
|
||
export function handleSummary() { | ||
return { | ||
stdout: tracetest.summary(), | ||
}; | ||
} | ||
|
||
export function teardown() { | ||
tracetest.validateResult(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.