Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run k6 after staging deployments #4991

Merged
merged 9 commits into from
Oct 21, 2024
23 changes: 21 additions & 2 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ jobs:
- name: Run k6 frontend all against local Nuxt
run: |
just k6 frontend all \
-e FRONTEND_URL=http://127.0.0.1:8443/ \
-e service_url=http://127.0.0.1:8443/ \
-e text_summary=/tmp/k6-summary.txt

- name: Upload artifacts
Expand Down Expand Up @@ -739,7 +739,7 @@ jobs:
## Latest k6 run output[^update]

```
${summary}
{summary}
```

[^update]: This comment will automatically update with new output each time k6 runs for this PR
Expand Down Expand Up @@ -1312,6 +1312,25 @@ jobs:
wait_time: 60 # check every minute
max_time: 1800 # allow up to 30 minutes for a deployment

- name: Trigger staging k6 load test
uses: convictional/[email protected]
with:
owner: WordPress
repo: openverse
token: ${{ secrets.ACCESS_TOKEN }}
workflow_file_name: k6.yml
wait_interval: 60
obulat marked this conversation as resolved.
Show resolved Hide resolved
# TODO: Set to true once we see that this test is stable, and we can fail the deployment if it fails.
# @see https://github.com/WordPress/openverse/pull/4991
propagate_failure: false
client_payload: |
{
"namespace": "frontend",
"scenario": "all",
"service_url": "https://staging.openverse.org/",
"report": true
}

deploy-api:
name: Deploy staging API
runs-on: ubuntu-latest
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/k6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Run k6 scenario

on:
workflow_dispatch:
inputs:
namespace:
description: '"namespace" of the k6 test scenario to run.'
required: true
type: choice
# frontend is the only one so far, but we will add API back to the k6 tests at some point
options:
- frontend
scenario:
description: "The k6 scenario to run; availability differs per namespace. Run `ov j packages/js/k6/ls` for a list of all k6 scenarios for each namespace."
required: true
type: string
service_url:
description: "The service against which to run the k6 scenario."
required: true
type: string
report:
description: "Whether to report the run results to Grafana Cloud k6"
required: false
type: boolean
default: false

run-name: k6 run ${{ inputs.namespace }} ${{ inputs.scenario }} ${{ inputs.service_url }} report=${{ inputs.report }}

# Disallow running multiple load tests at once against the same service
concurrency: ${{ github.workflow }}-${{ inputs.service_url }}

jobs:
run-k6:
name: "Run k6 ${{ inputs.namespace }} ${{ inputs.scenario }} ${{ inputs.service_url }} report=${{ inputs.report }}"
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup CI env
uses: ./.github/actions/setup-env
with:
setup_python: false
install_recipe: node-install

- name: Setup k6
uses: grafana/setup-k6-action@v1

- name: k6 run ${{ inputs.namespace }} ${{ inputs.scenario }} ${{ inputs.service_url }}
env:
K6_CLOUD_TOKEN: ${{ secrets.GC_K6_TOKEN }}
K6_SIGNING_SECRET: ${{ secrets.K6_SIGNING_SECRET }}
run: |
just k6 ${{ inputs.namespace }} ${{ inputs.scenario }} \
${{ inputs.report && '-o cloud' || ''}} \
-e signing_secret="$K6_SIGNING_SECRET" \
-e service_url=${{ inputs.service_url }} \
-e text_summary=/tmp/k6-summary.txt

- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: k6-output
path: /tmp/k6-summary.txt
2 changes: 2 additions & 0 deletions docker/dev_env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ENV PATH="${PNPM_BIN}:${N_PREFIX}/bin:${PDM_PYTHONS}:${HOME}/.local/bin:${PATH}"
# - just: command runner
# - jq: JSON processor
# - which: locate a program file in `PATH`
# - tree: list files in a tree
# - python*: required by some Python libraries for compilation during installation
# - libffi*: required for the Python package cffi
# - pipx: Python CLI app installer
Expand Down Expand Up @@ -58,6 +59,7 @@ RUN mkdir /pipx \
just \
jq \
which \
tree \
xdg-utils \
nodejs npm \
python3.12 python3.12-devel pipx \
Expand Down
5 changes: 5 additions & 0 deletions packages/js/k6/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ run namespace scenario *extra_args:
#! /usr/bin/env bash
pnpm run build --input src/{{ namespace }}/{{ scenario }}.test.ts
k6 run "${@:3}" ./dist/{{ namespace }}/{{ scenario }}.test.js

# List namespaces and scenarios
@ls:
echo "Openverse k6 namespaces and scenarios"
tree src -P '*.test.ts' --noreport | cut -c 5- | sed 's/\.test\.ts//'
2 changes: 1 addition & 1 deletion packages/js/k6/src/frontend/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const PROJECT_ID = 3713375
// Default to location of `ov j p frontend prod`
export const FRONTEND_URL = __ENV.FRONTEND_URL || "http://127.0.0.1:8443/"
export const FRONTEND_URL = __ENV.service_url || "http://127.0.0.1:8443/"