generated from pagopa/pagopa-quarkus-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from pagopa/PPANTT-73-performance-tests
[PPANTT-73] feat: Performance tests
- Loading branch information
Showing
17 changed files
with
442 additions
and
114 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
# azure-pipelines.yml | ||
trigger: none | ||
|
||
parameters: | ||
- name: "ENVIRONMENT" | ||
displayName: "Environment" | ||
type: string | ||
values: | ||
- "dev" | ||
- "uat" | ||
default: "uat" | ||
- name: "TEST_TYPE" | ||
displayName: "Test type" | ||
type: string | ||
values: | ||
- "load" | ||
- "spike" | ||
- "stress" | ||
- "constant" | ||
default: "constant" | ||
- name: "NOTICE_TYPE" | ||
displayName: "Notice type" | ||
type: string | ||
values: | ||
- "single_opt" | ||
- "single_and_many_opt" | ||
- "single_and_multy_opt" | ||
- "single_and_co_opt" | ||
- "all" | ||
default: "all" | ||
- name: "DB_NAME" | ||
displayName: "DB name" | ||
type: string | ||
values: | ||
- pagopa_payment_options_servicek6 | ||
variables: | ||
${{ if eq(parameters['ENVIRONMENT'], 'dev') }}: | ||
poolImage: 'pagopa-dev-loadtest-linux' | ||
API_SUBSCRIPTION_KEY: "$(DEV_API_SUBSCRIPTION_KEY)" | ||
${{ if eq(parameters['ENVIRONMENT'], 'uat') }}: | ||
poolImage: 'pagopa-uat-loadtest-linux' | ||
API_SUBSCRIPTION_KEY: "$(UAT_API_SUBSCRIPTION_KEY)" | ||
|
||
pool: | ||
name: $(poolImage) | ||
|
||
steps: | ||
- script: | | ||
cd ./performance-test/src | ||
docker pull grafana/k6 | ||
displayName: Pull k6 image | ||
- script: | | ||
cd ./performance-test | ||
sh ./run_performance_test.sh ${{ parameters.ENVIRONMENT }} ${{ parameters.TEST_TYPE }} payment_options_service_test ${{ parameters.DB_NAME}} $OCP_APIM_SUBSCRIPTION_KEY | ||
displayName: Run k6 payment_options_service_test with notice type ${{ parameters.NOTICE_TYPE}} on ${{ parameters.ENVIRONMENT }} | ||
env: | ||
OCP_APIM_SUBSCRIPTION_KEY: ${{ variables.API_SUBSCRIPTION_KEY }} | ||
NOTICE_TYPE: ${{ parameters.NOTICE_TYPE }} | ||
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
# K6 tests | ||
|
||
This is a set of [k6](https://k6.io) tests. | ||
|
||
To invoke k6 tests use `run_performance_test.sh` script. | ||
|
||
|
||
## How to run 🚀 | ||
|
||
Use this command to launch the tests: | ||
|
||
``` shell | ||
sh run_performance_test.sh <local|dev|uat> <load|stress|spike|...> <script-filename> <DB-name> <apim_subscription_key> | ||
``` |
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,27 @@ | ||
version: '3.3' | ||
services: | ||
k6: | ||
image: grafana/k6 | ||
container_name: k6 | ||
volumes: | ||
- '${PWD}/src:/scripts' | ||
environment: | ||
- OCP_APIM_SUBSCRIPTION_KEY=${ocp_apim_subscription_key} | ||
- VARS=${env}.environment.json | ||
- TEST_TYPE=/scripts/test-types/${type}.json | ||
- K6_OUT=influxdb=http://nginx:8086/${db_name} | ||
command: run /scripts/${script}.js | ||
depends_on: | ||
- nginx | ||
|
||
nginx: | ||
image: nginx | ||
container_name: nginx | ||
volumes: | ||
- '${PWD}/nginx/nginx.conf:/etc/nginx/nginx.conf' | ||
environment: | ||
- ENVIRONMENT=${env} | ||
ports: | ||
- "8086:8086" | ||
- "80:80" | ||
|
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,16 @@ | ||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 8086; | ||
location / { | ||
proxy_pass https://api.uat.platform.pagopa.it/shared/influxdb/v1/; | ||
proxy_http_version 1.1; | ||
proxy_set_header Host api.uat.platform.pagopa.it; | ||
proxy_pass_request_headers on; | ||
} | ||
} | ||
} | ||
|
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,35 @@ | ||
# sh run_performance_test.sh <local|dev|uat|prod> <load|stress|spike|soak|...> <script-name> <db-name> <apim_subscription_key> | ||
|
||
ENVIRONMENT=$1 | ||
TYPE=$2 | ||
SCRIPT=$3 | ||
DB_NAME=$4 | ||
OCP_APIM_SUBSCRIPTION_KEY=$5 | ||
|
||
if [ -z "$ENVIRONMENT" ] | ||
then | ||
echo "No env specified: sh run_performance_test.sh <local|dev|uat|prod> <load|stress|spike|soak|...> <script-name> <db-name> <apim_subscription_key>" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$TYPE" ] | ||
then | ||
echo "No test type specified: sh run_performance_test.sh <local|dev|uat|prod> <load|stress|spike|soak|...> <script-name> <db-name> <apim_subscription_key>" | ||
exit 1 | ||
fi | ||
if [ -z "$SCRIPT" ] | ||
then | ||
echo "No script name specified: sh run_performance_test.sh <local|dev|uat|prod> <load|stress|spike|soak|...> <script-name> <db-name> <apim_subscription_key>" | ||
exit 1 | ||
fi | ||
|
||
export env=${ENVIRONMENT} | ||
export type=${TYPE} | ||
export script=${SCRIPT} | ||
export db_name=${DB_NAME} | ||
export ocp_apim_subscription_key=${OCP_APIM_SUBSCRIPTION_KEY} | ||
|
||
stack_name=$(cd .. && basename "$PWD") | ||
docker compose -p "${stack_name}-k6" up -d --remove-orphans --force-recreate --build | ||
docker logs -f k6 | ||
docker stop nginx |
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,8 @@ | ||
{ | ||
"environment": [ | ||
{ | ||
"env": "dev", | ||
"paymentOptionsServiceURIBasePath": "https://api.dev.platform.pagopa.it/payment-options/service/v1" | ||
} | ||
] | ||
} |
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,8 @@ | ||
{ | ||
"environment": [ | ||
{ | ||
"env": "local", | ||
"paymentOptionsServiceURIBasePath": "http://localhost:8080" | ||
} | ||
] | ||
} |
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,19 @@ | ||
import http from 'k6/http'; | ||
const subKey = `${__ENV.OCP_APIM_SUBSCRIPTION_KEY}`; | ||
|
||
export function getToService(endpoint, params) { | ||
let url = endpoint; | ||
let headers = { | ||
'Ocp-Apim-Subscription-Key': subKey, | ||
"Content-Type": "application/json" | ||
}; | ||
|
||
const queryParams = params ? Object.entries(params) : []; | ||
if (queryParams && queryParams.length) { | ||
queryParams.forEach((el, index) => { | ||
url = url.concat(index === 0 ? "?" : "&", el[0], "=", el[1]); | ||
}); | ||
} | ||
|
||
return http.get(url, { headers, responseType: "text", params }); | ||
} |
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,8 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"axios": "^0.27.2" | ||
}, | ||
"scripts" : { | ||
} | ||
} |
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,57 @@ | ||
import { getToService } from "./modules/payment_options_client.js"; | ||
import { SharedArray } from 'k6/data'; | ||
import { check } from 'k6'; | ||
|
||
const varsArray = new SharedArray('vars', function () { | ||
return JSON.parse(open(`./${__ENV.VARS}`)).environment; | ||
}); | ||
export const ENV_VARS = varsArray[0]; | ||
|
||
const paymentOptionsServiceURIBasePath = `${ENV_VARS.paymentOptionsServiceURIBasePath}`; | ||
const noticeType = `${__ENV.NOTICE_TYPE}`; | ||
|
||
const ORGANIZATIONAL_FISCAL_CODE = "77777777777"; | ||
|
||
const SINGLE_OPT_NOTICE_NUMBER = "311111111111111111"; | ||
const SINGLE_AND_MANY_OPT_NOTICE_NUMBER = "311111111111111112"; | ||
const SINGLE_AND_MULTI_OPT_NOTICE_NUMBER = "311111111111111116"; | ||
const SINGLE_AND_CO_OPT_NOTICE_NUMBER = "311111111112222225"; | ||
|
||
const VALID_PSP = "99999000001"; | ||
|
||
const getSelectedNoticeNumbers = () => { | ||
const noticeTypeAll = noticeType === "undefined" || noticeType === "all"; | ||
|
||
const selectedNotices = []; | ||
if (noticeType === "single_opt" || noticeTypeAll) { | ||
selectedNotices.push(SINGLE_OPT_NOTICE_NUMBER); | ||
} | ||
if (noticeType === "single_and_many_opt" || noticeTypeAll) { | ||
selectedNotices.push(SINGLE_AND_MANY_OPT_NOTICE_NUMBER); | ||
} | ||
if (noticeType === "single_and_multy_opt" || noticeTypeAll) { | ||
selectedNotices.push(SINGLE_AND_MULTI_OPT_NOTICE_NUMBER); | ||
} | ||
if (noticeType === "single_and_co_opt" || noticeTypeAll) { | ||
selectedNotices.push(SINGLE_AND_CO_OPT_NOTICE_NUMBER); | ||
} | ||
console.log(`Selected the following notices: ${JSON.stringify(selectedNotices)}`); | ||
return selectedNotices; | ||
} | ||
|
||
export default function () { | ||
const selectedNotices = getSelectedNoticeNumbers(); | ||
for (let i = 0; i < selectedNotices.length; i++) { | ||
const el = selectedNotices[i]; | ||
let response = getToService(`${paymentOptionsServiceURIBasePath}/payment-options/organizations/${ORGANIZATIONAL_FISCAL_CODE}/notices/${el}`, { idPsp: VALID_PSP }); | ||
console.info(`Payment Options Service getPaymentOptions with notice number ${el} call, Status ${response.status}`); | ||
|
||
let responseBody = JSON.parse(response.body); | ||
|
||
check(response, { | ||
'Payment Options Service getPaymentOptions status is 200': () => response.status === 200, | ||
'Payment Options Service getPaymentOptions body has list of payment options': () => | ||
Boolean(responseBody && responseBody.paymentOptions && responseBody.paymentOptions.length) | ||
}); | ||
} | ||
} |
Oops, something went wrong.