diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f233ca2..fdfda86c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,7 @@ orbs: aws-cli: circleci/aws-cli@0.1.9 aws_assume_role: lbh-hackit/aws_assume_role@0.1.0 sonarcloud: sonarsource/sonarcloud@1.1.1 + grafana: grafana/k6@1.1.0 executors: docker-python: @@ -234,6 +235,10 @@ jobs: workflows: check-and-deploy-development: jobs: + - grafana/k6: + context: api-load-testing + arguments: --env TOKEN=$API_DEVELOPMENT_TOKEN --env API_URL=$TENURE_API_URL + script: scripts/performance-testing-script.js - check-code-formatting: context: api-nuget-token-context - build-and-test: diff --git a/scripts/performance-testing-script.js b/scripts/performance-testing-script.js new file mode 100644 index 00000000..837bd5ee --- /dev/null +++ b/scripts/performance-testing-script.js @@ -0,0 +1,39 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; +import { Rate } from "k6/metrics"; + + +var failureRate = new Rate("check_failure_rate"); + +export const options = { + vus: 5, //default value, can be overwritten by passing the --vus CLI option + duration: '10s', //default value, can be overwritten by passing the --duration CLI option + thresholds: { + // We want the 95th percentile of all HTTP request durations to be less than 500ms + "http_req_duration": ["p(95)<1000"], + // Thresholds based on the custom metric we defined and use to track application failures + "check_failure_rate": [ + // Global failure rate should be less than 1% + "rate<0.01", + // Abort the test early if it climbs over 5% + { threshold: "rate<=0.05", abortOnFail: true }, + ], + } +}; +export const params = { + headers: { 'Authorization': `${__ENV.TOKEN}`}, +}; +export default function () { + var apiUrl = `${__ENV.API_URL}` + if (!apiUrl.includes('https://')) + { + apiUrl = "https://" + apiUrl; + } + const res = http.get(apiUrl, params); + + let checkRes = check(res, { 'status was 200': (r) => r.status == 200 }); + + failureRate.add(!checkRes); + + sleep(1); +} \ No newline at end of file