Skip to content

Commit

Permalink
Update perf tests for constant benchmark load (#455)
Browse files Browse the repository at this point in the history
* Update perf tests for constant benchmark load

* Adds suite k6 script to run all scenarios, github action for adhoc runs

* Use workflow input for perf test action and fix typo

* Fix broken artifact path
  • Loading branch information
cshnimble authored Mar 6, 2024
1 parent beeb80f commit dade2e1
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 28 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/performance-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: k6 Performance benchmark tests

on:
workflow_dispatch:
inputs:
environment:
type: environment
description: "Choose an environment to run against"
required: true

jobs:
run-k6-tests:
runs-on: ubuntu-latest
if: github.event.inputs.environment == 'development' || github.event.inputs.environment == 'test'
defaults:
run:
working-directory: Dfe.Academies.Performance/scripts
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run k6 test
uses: grafana/k6-action@v0.3.1
with:
filename: suite.js
env:
BASE_URL: ${{ secrets.TRAMS_API_BASE_URL }}
API_KEY: ${{ secrets.TRAMS_API_KEY }}

- name: Upload report
if: ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: summary
path: summary.html
1 change: 1 addition & 0 deletions Dfe.Academies.Performance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
summary.html
107 changes: 107 additions & 0 deletions Dfe.Academies.Performance/scripts/suite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { htmlReport } from 'https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js'
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js'
import { default as keyStagePerformance } from './v1/keyStagePerformance.js'
import { default as baselineTracker } from './v2/baselineTracker.js'
import { default as fssProjects } from './v2/fssProjects.js'
import { default as trustsV3 } from './v3/trusts.js'
import { default as establishments } from './v4/establishments.js'
import { default as trustsV4 } from './v4/trusts.js'

export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
keyStagePerformance: {
exec: 'ksp',
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s'
},
baselineTracker: {
exec: 'bt',
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s',
startTime: '30s'
},
fssProjects: {
exec: 'fss',
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s',
startTime: '60s'
},
trustsV3: {
exec: 'v3t',
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s',
startTime: '90s'
},
establishments: {
exec: 'est',
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s',
startTime: '120s'
},
trustsV4: {
exec: 'v4t',
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s',
startTime: '150s'
},
}
}

export function ksp() {
keyStagePerformance()
}

export function bt() {
baselineTracker()
}

export function fss() {
fssProjects()
}

export function v3t() {
trustsV3()
}

export function v4t() {
trustsV4()
}

export function est() {
establishments()
}

export function handleSummary(data) {
return {
'summary.html': htmlReport(data),
stdout: textSummary(data, { indent: ' ', enableColors: true }),
}
}
18 changes: 15 additions & 3 deletions Dfe.Academies.Performance/scripts/v1/keyStagePerformance.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import http from 'k6/http'
import { check, sleep } from 'k6'
import { sleep } from 'k6'
import { isStatus200, getHeaders } from '../utils/utils.js'

export const options = {
vus: 20,
duration: '30s'
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
constant_load: {
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s'
}
}
}

const baseUrl = __ENV.BASE_URL
Expand Down
17 changes: 14 additions & 3 deletions Dfe.Academies.Performance/scripts/v2/baselineTracker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import http from 'k6/http'
import { check, sleep } from 'k6'
import { sleep } from 'k6'
import { isStatus200, getHeaders } from '../utils/utils.js'

export const options = {
vus: 20,
duration: '30s'
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
constant_load: {
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s'
}
}
}

const baseUrl = `${__ENV.BASE_URL}/v2`
Expand Down
19 changes: 15 additions & 4 deletions Dfe.Academies.Performance/scripts/v2/fssProjects.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import http from 'k6/http'
import { check, sleep } from 'k6'
import { sleep } from 'k6'
import { isStatus200, getHeaders } from '../utils/utils.js'

export const options = {
vus: 20,
duration: '30s'
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
constant_load: {
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s'
}
}
}

const baseUrl = `${__ENV.BASE_URL}/v2`

export default function () {

getFreeSchoolProjects()

sleep(1)
}

Expand Down
25 changes: 18 additions & 7 deletions Dfe.Academies.Performance/scripts/v3/trusts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import http from 'k6/http'
import { check, sleep } from 'k6'
import { sleep } from 'k6'
import { isStatus200, getHeaders } from '../utils/utils.js'

export const options = {
vus: 20,
duration: '30s'
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
constant_load: {
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s'
}
}
}

const baseUrl = `${__ENV.BASE_URL}/v3`
Expand All @@ -22,23 +33,23 @@ export default function () {

function getTrustByUkPrn(ukprn) {
const res = http.get(`${baseUrl}/trust/${ukprn}`, {
headers: getHeaders()
headers: getHeaders()
})

isStatus200(res)
}

function searchTrustByName(name) {
const res = http.get(`${baseUrl}/trusts?groupName=${name}&page=1&count=10`, {
headers: getHeaders()
headers: getHeaders()
})

isStatus200(res);
isStatus200(res)
}

function searchTrustByUkPrn(ukprn) {
const res = http.get(`${baseUrl}/trusts?ukPrn=${ukprn}&page=1&count=10`, {
headers: getHeaders()
headers: getHeaders()
})

isStatus200(res)
Expand Down
22 changes: 17 additions & 5 deletions Dfe.Academies.Performance/scripts/v4/establishments.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import http from 'k6/http'
import { check, sleep } from 'k6'
import { sleep } from 'k6'
import { isStatus200, getHeaders } from '../utils/utils.js'

export const options = {
vus: 20,
duration: '30s'
}
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
constant_load: {
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s'
}
}
}

const baseUrl = `${__ENV.BASE_URL}/v4`

export default function () {

getEstablishmentByUkPrn('10079319')

getEstablishmentByUrn('100000')
Expand Down
24 changes: 18 additions & 6 deletions Dfe.Academies.Performance/scripts/v4/trusts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import http from 'k6/http'
import { check, sleep } from 'k6'
import { sleep } from 'k6'
import { isStatus200, getHeaders } from '../utils/utils.js'

export const options = {
vus: 20,
duration: '30s'
}
thresholds: {
http_req_failed: ['rate<0.01'], // Failure rate less than 1%
http_req_duration: ['p(95)<1000'] // Requests take <1s at the 95th percentile
},
scenarios: {
constant_load: {
executor: 'constant-arrival-rate',
duration: '10s',
preAllocatedVUs: 100,
rate: 10,
timeUnit: '1s',
gracefulStop: '60s'
}
}
}

const baseUrl = `${__ENV.BASE_URL}/v4`

Expand All @@ -16,7 +28,7 @@ export default function () {
getTrustByCompaniesHouseNumber('11082297')

getTrustByReferenceNumber('TR03739')

searchTrustByUkPrn('10067112')

searchTrustByName('SOUTH YORK MULTI ACADEMY TRUST')
Expand Down Expand Up @@ -54,7 +66,7 @@ function searchTrustByName(name) {
headers: getHeaders()
})

isStatus200(res);
isStatus200(res)
}

function searchTrustByUkPrn(ukprn) {
Expand Down

0 comments on commit dade2e1

Please sign in to comment.