From 8a4a1cc0a4c1320baa39cd974d67db6f420f142a Mon Sep 17 00:00:00 2001 From: LBHMGeorgieva Date: Thu, 3 Nov 2022 15:26:57 +0000 Subject: [PATCH 1/5] test performance testing --- .circleci/config.yml | 20 ++++++++++++++ scripts/performance-testing-script.js | 39 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 scripts/performance-testing-script.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f233ca2..93e0e06f 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.3 executors: docker-python: @@ -132,6 +133,17 @@ commands: npm i serverless-associate-waf npm i @serverless/safeguards-plugin --save-dev sls deploy --stage <> --conceal + run-api-load-testing: + description: run k6 tests + parameters: + apiToken: + type: string + apiFullUrl: + type: string + steps: + - grafana/k6: + arguments: --env TOKEN=<> --env API_URL=<> + script: scripts/performance-testing-script.js jobs: check-code-formatting: executor: docker-dotnet @@ -230,10 +242,18 @@ jobs: steps: - deploy-lambda: stage: "production" + api-performance-testing-development: + executor: docker-python + steps: + - run-api-load-testing: + apiToken: $AUTH_TOKEN_DEVELOPMENT + apiFullUrl: $API_URL_LOAD_TESTING workflows: check-and-deploy-development: jobs: + - api-performance-testing-development: + context: mtfh-mfe-e2e-tests - 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 From 0e14164c6d78a5dabd4bf84ccb9d11696abe4733 Mon Sep 17 00:00:00 2001 From: LBHMGeorgieva Date: Thu, 3 Nov 2022 15:29:00 +0000 Subject: [PATCH 2/5] change orb reference --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 93e0e06f..fa09c6fb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +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.3 + k6: k6io/test@1.2.3 executors: docker-python: @@ -141,7 +141,7 @@ commands: apiFullUrl: type: string steps: - - grafana/k6: + - k6/test: arguments: --env TOKEN=<> --env API_URL=<> script: scripts/performance-testing-script.js jobs: From 6b001ed10fe362ea2bb7d7e219a51f163ccd7756 Mon Sep 17 00:00:00 2001 From: LBHMGeorgieva Date: Thu, 3 Nov 2022 15:36:14 +0000 Subject: [PATCH 3/5] change call to k6 orb --- .circleci/config.yml | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fa09c6fb..3b63b6f5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +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 - k6: k6io/test@1.2.3 + grafana: grafana/k6@1.1.3 executors: docker-python: @@ -133,17 +133,6 @@ commands: npm i serverless-associate-waf npm i @serverless/safeguards-plugin --save-dev sls deploy --stage <> --conceal - run-api-load-testing: - description: run k6 tests - parameters: - apiToken: - type: string - apiFullUrl: - type: string - steps: - - k6/test: - arguments: --env TOKEN=<> --env API_URL=<> - script: scripts/performance-testing-script.js jobs: check-code-formatting: executor: docker-dotnet @@ -245,9 +234,9 @@ jobs: api-performance-testing-development: executor: docker-python steps: - - run-api-load-testing: - apiToken: $AUTH_TOKEN_DEVELOPMENT - apiFullUrl: $API_URL_LOAD_TESTING + - grafana/k6: + arguments: --env TOKEN=$AUTH_TOKEN_DEVELOPMENT--env API_URL=$API_URL_LOAD_TESTING + script: scripts/performance-testing-script.js workflows: check-and-deploy-development: From dedf8e42c358b9a5d9f9cf7be525e99816a0c2e2 Mon Sep 17 00:00:00 2001 From: LBHMGeorgieva Date: Thu, 3 Nov 2022 15:41:43 +0000 Subject: [PATCH 4/5] try different orb version --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b63b6f5..9cecb95f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +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.3 + grafana: grafana/k6@1.1.0 executors: docker-python: From 6cdfbbeac0d92b5457faaed7e53792461f140107 Mon Sep 17 00:00:00 2001 From: LBHMGeorgieva Date: Thu, 3 Nov 2022 15:54:48 +0000 Subject: [PATCH 5/5] change k6 job invocation --- .circleci/config.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9cecb95f..fdfda86c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -231,18 +231,14 @@ jobs: steps: - deploy-lambda: stage: "production" - api-performance-testing-development: - executor: docker-python - steps: - - grafana/k6: - arguments: --env TOKEN=$AUTH_TOKEN_DEVELOPMENT--env API_URL=$API_URL_LOAD_TESTING - script: scripts/performance-testing-script.js workflows: check-and-deploy-development: jobs: - - api-performance-testing-development: - context: mtfh-mfe-e2e-tests + - 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: