Skip to content

Commit

Permalink
Merge pull request #132 from pagopa/PAGOPA-1529-test-adeguamento-dei-…
Browse files Browse the repository at this point in the history
…perf-test-per-api-v-2

PAGOPA-1529 adding script for new api
  • Loading branch information
FedericoRuzzier authored Mar 26, 2024
2 parents 4400e17 + b88f4d3 commit 5d8ecc3
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .devops/performance-test-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ parameters:
values:
- calculator_getFees
- calculator_getFeesByPsp
- calculator_getFeesMulti
- calculator_getFeesByPspMulti

variables:
${{ if eq(parameters['ENVIRONMENT'], 'dev') }}:
Expand Down
6 changes: 3 additions & 3 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ microservice-chart:
resources:
requests:
memory: "512Mi"
cpu: "0.5"
cpu: "0.4"
limits:
memory: "768Mi"
cpu: "0.5"
memory: "1024Mi"
cpu: "1.0"
autoscaling:
enable: true
minReplica: 3
Expand Down
8 changes: 4 additions & 4 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ microservice-chart:
resources:
requests:
memory: "512Mi"
cpu: "0.75"
cpu: "0.5"
limits:
memory: "1024Mi"
cpu: "1.0"
Expand All @@ -68,12 +68,12 @@ microservice-chart:
metadata:
# Required
type: Utilization # Allowed types are 'Utilization' or 'AverageValue'
value: "70"
value: "80"
- type: memory
metadata:
# Required
type: Utilization # Allowed types are 'Utilization' or 'AverageValue'
value: "70"
value: "80"
fileConfig: {}
envConfig:
WEBSITE_SITE_NAME: 'pagopaafmcalculator' # required to show cloud role name in application insights
Expand All @@ -87,7 +87,7 @@ microservice-chart:
AMOUNT_THRESHOLD: '0'
ID_PSP_POSTE: 'BPPIITRRXXX'
AMEX_ABI: 'AMREX'
PSP_WHITELIST: 'PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019'
PSP_WHITELIST: 'PPAYITR1XXX,BPPIITRRXXX,CIPBITMM,UNCRITMM,BNLIITRR,BCITITMM,BIC36019,TMIL0101,POSOIT22XXX'
OTEL_SERVICE_NAME: "pagopa-afm-calculator"
OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=uat"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317"
Expand Down
2 changes: 1 addition & 1 deletion performance-test/src/calculator_getFees.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const paymenttypes = data["paymenttypes"];

// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const rootUrl = `${vars.host}`;
const rootUrl = `${vars.hostV1}`;
const cosmosDBURI = `${vars.cosmosDBURI}`;
const databaseID = `${vars.databaseID}`;
const validBundlesNum = `${vars.validBundlesNum}`;
Expand Down
2 changes: 1 addition & 1 deletion performance-test/src/calculator_getFeesByPsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const paymenttypes = data["paymenttypes"];

// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const rootUrl = `${vars.host}`;
const rootUrl = `${vars.hostV1}`;
const cosmosDBURI = `${vars.cosmosDBURI}`;
const databaseID = `${vars.databaseID}`;
const validBundlesNum = `${vars.validBundlesNum}`;
Expand Down
127 changes: 127 additions & 0 deletions performance-test/src/calculator_getFeesByPspMulti.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// 1. init code (once per VU)
// prepares the script: loading files, importing modules, and defining functions

import {check} from 'k6';
import {SharedArray} from 'k6/data';
import {addTouchpoints, deleteTouchpoints, getFeesByPspMulti, mapToValidBundles, getValidBundle} from './helpers/calculator_helper.js';
import { createDocument, deleteDocument } from "./helpers/cosmosdb_client.js";

export let options = JSON.parse(open(__ENV.TEST_TYPE));

// read configuration
// note: SharedArray can currently only be constructed inside init code
// according to https://k6.io/docs/javascript-api/k6-data/sharedarray
const varsArray = new SharedArray('vars', function () {
return JSON.parse(open(`${__ENV.VARS}`)).environment;
});

const data = JSON.parse(open('./helpers/data.json'));
const touchpoints = data["touchpoints"];
const paymenttypes = data["paymenttypes"];

// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const rootUrl = `${vars.hostV2}`;
const cartPathApi = `${vars.cartPathApi}`;
const cosmosDBURI = `${vars.cosmosDBURI}`;
const databaseID = `${vars.databaseID}`;
const validBundlesNum = `${vars.validBundlesNum}`;

const cosmosPrimaryKey = `${__ENV.COSMOS_SUBSCRIPTION_KEY}`;


export function setup() {
// 2. setup code (once)
// The setup code runs, setting up the test environment (optional) and generating data
// used to reuse code for the same VU

for (let i = 0; i < touchpoints.length; i++) {
let response = createDocument(cosmosDBURI, databaseID, "touchpoints", cosmosPrimaryKey, touchpoints[i], touchpoints[i]['name']);
check(response, { "status is 201": (res) => (res.status === 201) });
}

for (let i = 0; i < paymenttypes.length; i++) {
let response = createDocument(cosmosDBURI, databaseID, "paymenttypes", cosmosPrimaryKey, paymenttypes[i], paymenttypes[i]['name']);
check(response, { "status is 201": (res) => (res.status === 201) });
}

for (let i = 0; i < validBundlesNum; i++) {
let validBundle = getValidBundle("int-test-"+i);
let response = createDocument(cosmosDBURI, databaseID, "validbundles", cosmosPrimaryKey, validBundle, validBundle['idPsp']);
check(response, { "status is 201": (res) => (res.status === 201) });
}

// precondition is moved to default fn because in this stage
// __VU is always 0 and cannot be used to create env properly
}

export default function calculator() {

const params = {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': __ENV.API_SUBSCRIPTION_KEY
},
};

// to give randomness to request in order to avoid caching
const paymentAmount = Math.floor(Math.random() * (100 + __VU) % 100);
//const primaryCreditorInstitution1 = '7777777777' + Math.floor(Math.random() * 10);
//const primaryCreditorInstitution2 = '7777777777' + Math.floor(Math.random() * 10);
const primaryCreditorInstitution = 'fiscalCode-' + Math.floor(Math.random() * 2) + 1;

let payload = {
"bin": "1005066",
"paymentMethod": "CP",
"touchpoint": "CHECKOUT",
"paymentNotice": [
{
"primaryCreditorInstitution": primaryCreditorInstitution,
"paymentAmount": paymentAmount/2,
"transferList": [
{
"creditorInstitution": "fiscalCode-1",
"transferCategory": "TAX1"
}
]
},
{
"primaryCreditorInstitution": primaryCreditorInstitution,
"paymentAmount": paymentAmount/2,
"transferList": [
{
"creditorInstitution": "fiscalCode-1",
"transferCategory": "TAX1"
}
]
}
]
}
const idPsp = String(Math.floor(Math.random() * 10) + 1).padStart(11, '0');

let response = getFeesByPspMulti(rootUrl, cartPathApi, idPsp, payload, params);

check(response, {
'getFeesMulti': (r) => r.status === 200,
});

}

export function teardown() {
// After All
for (let i = 0; i < touchpoints.length; i++) {
let response = deleteDocument(cosmosDBURI, databaseID, "touchpoints", cosmosPrimaryKey, touchpoints[i]['id'], touchpoints[i]["name"]);
check(response, { "status is 204": (res) => (res.status === 204) });
}

for (let i = 0; i < paymenttypes.length; i++) {
let response = deleteDocument(cosmosDBURI, databaseID, "paymenttypes", cosmosPrimaryKey, paymenttypes[i]['id'], paymenttypes[i]["name"]);
check(response, { "status is 204": (res) => (res.status === 204) });
}

for (let i = 0; i < validBundlesNum; i++) {
let validBundle = getValidBundle("int-test-"+i);
let response = deleteDocument(cosmosDBURI, databaseID, "validbundles", cosmosPrimaryKey, validBundle['id'], validBundle['idPsp']);
check(response, { "status is 204": (res) => (res.status === 204) });
}
}
127 changes: 127 additions & 0 deletions performance-test/src/calculator_getFeesMulti.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// 1. init code (once per VU)
// prepares the script: loading files, importing modules, and defining functions

import {check} from 'k6';
import {SharedArray} from 'k6/data';
import {addTouchpoints, deleteTouchpoints, getFeesMulti, mapToValidBundles, getValidBundle} from './helpers/calculator_helper.js';
import { createDocument, deleteDocument } from "./helpers/cosmosdb_client.js";

export let options = JSON.parse(open(__ENV.TEST_TYPE));

// read configuration
// note: SharedArray can currently only be constructed inside init code
// according to https://k6.io/docs/javascript-api/k6-data/sharedarray
const varsArray = new SharedArray('vars', function () {
return JSON.parse(open(`${__ENV.VARS}`)).environment;
});

const data = JSON.parse(open('./helpers/data.json'));
const touchpoints = data["touchpoints"];
const paymenttypes = data["paymenttypes"];

// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const rootUrl = `${vars.hostV2}`;
const cartPathApi = `${vars.cartPathApi}`;
const cosmosDBURI = `${vars.cosmosDBURI}`;
const databaseID = `${vars.databaseID}`;
const validBundlesNum = `${vars.validBundlesNum}`;

const cosmosPrimaryKey = `${__ENV.COSMOS_SUBSCRIPTION_KEY}`;


export function setup() {
// 2. setup code (once)
// The setup code runs, setting up the test environment (optional) and generating data
// used to reuse code for the same VU

for (let i = 0; i < touchpoints.length; i++) {
let response = createDocument(cosmosDBURI, databaseID, "touchpoints", cosmosPrimaryKey, touchpoints[i], touchpoints[i]['name']);
check(response, { "status is 201": (res) => (res.status === 201) });
}

for (let i = 0; i < paymenttypes.length; i++) {
let response = createDocument(cosmosDBURI, databaseID, "paymenttypes", cosmosPrimaryKey, paymenttypes[i], paymenttypes[i]['name']);
check(response, { "status is 201": (res) => (res.status === 201) });
}

for (let i = 0; i < validBundlesNum; i++) {
let validBundle = getValidBundle("int-test-"+i);
let response = createDocument(cosmosDBURI, databaseID, "validbundles", cosmosPrimaryKey, validBundle, validBundle['idPsp']);
check(response, { "status is 201": (res) => (res.status === 201) });
}

// precondition is moved to default fn because in this stage
// __VU is always 0 and cannot be used to create env properly
}

export default function calculator() {

const params = {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': __ENV.API_SUBSCRIPTION_KEY
},
};

// to give randomness to request in order to avoid caching
const paymentAmount = Math.floor(Math.random() * (100 + __VU) % 100);
//const primaryCreditorInstitution1 = '7777777777' + Math.floor(Math.random() * 10);
//const primaryCreditorInstitution2 = '7777777777' + Math.floor(Math.random() * 10);
const primaryCreditorInstitution = 'fiscalCode-' + Math.floor(Math.random() * 2) + 1;

let payload = {
"bin": "1005066",
"paymentMethod": "CP",
"touchpoint": "CHECKOUT",
"idPspList": [],
"paymentNotice": [
{
"primaryCreditorInstitution": primaryCreditorInstitution,
"paymentAmount": paymentAmount/2,
"transferList": [
{
"creditorInstitution": "fiscalCode-1",
"transferCategory": "TAX1"
}
]
},
{
"primaryCreditorInstitution": primaryCreditorInstitution,
"paymentAmount": paymentAmount/2,
"transferList": [
{
"creditorInstitution": "fiscalCode-1",
"transferCategory": "TAX1"
}
]
}
]
}

let response = getFeesMulti(rootUrl, cartPathApi, payload, params);

check(response, {
'getFeesMulti': (r) => r.status === 200,
});

}

export function teardown() {
// After All
for (let i = 0; i < touchpoints.length; i++) {
let response = deleteDocument(cosmosDBURI, databaseID, "touchpoints", cosmosPrimaryKey, touchpoints[i]['id'], touchpoints[i]["name"]);
check(response, { "status is 204": (res) => (res.status === 204) });
}

for (let i = 0; i < paymenttypes.length; i++) {
let response = deleteDocument(cosmosDBURI, databaseID, "paymenttypes", cosmosPrimaryKey, paymenttypes[i]['id'], paymenttypes[i]["name"]);
check(response, { "status is 204": (res) => (res.status === 204) });
}

for (let i = 0; i < validBundlesNum; i++) {
let validBundle = getValidBundle("int-test-"+i);
let response = deleteDocument(cosmosDBURI, databaseID, "validbundles", cosmosPrimaryKey, validBundle['id'], validBundle['idPsp']);
check(response, { "status is 204": (res) => (res.status === 204) });
}
}
4 changes: 3 additions & 1 deletion performance-test/src/dev.environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"environment": [
{
"env": "dev",
"host": "https://api.dev.platform.pagopa.it/afm/calculator-service/v1",
"hostV1": "https://api.dev.platform.pagopa.it/afm/calculator-service/v1",
"hostV2": "https://api.dev.platform.pagopa.it/afm/calculator-service/v2",
"cartPathApi": "",
"cosmosDBURI": "https://pagopa-d-weu-afm-marketplace-cosmos-account.documents.azure.com:443/",
"databaseID":"db",
"validBundlesNum":"100"
Expand Down
12 changes: 12 additions & 0 deletions performance-test/src/helpers/calculator_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export function getFees(rootUrl, payload, params) {
return http.post(url, JSON.stringify(payload), params);
}

export function getFeesByPspMulti(rootUrl, cartPathApi, idPsp, payload, params) {
const url = `${rootUrl}/psps/${idPsp}/fees`.concat(cartPathApi)

return http.post(url, JSON.stringify(payload), params);
}

export function getFeesMulti(rootUrl, cartPathApi, payload, params) {
const url = `${rootUrl}/fees`.concat(cartPathApi)

return http.post(url, JSON.stringify(payload), params);
}

export function addTouchpoints(rootUrl, payload, params) {
const url = `${rootUrl}/configuration/touchpoint/add`

Expand Down
15 changes: 15 additions & 0 deletions performance-test/src/helpers/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@
"maxPaymentAmount": 20
}
]
},
{
"id": "int-test-4",
"ciFiscalCode": "77777777778",
"idBundle": "int-test-4",
"attributes": [
{
"id": "int-test-4",
"maxPaymentAmount": 20
},
{
"id": "int-test-5",
"maxPaymentAmount": 40
}
]
}
],
"touchpoints": [
Expand Down
4 changes: 3 additions & 1 deletion performance-test/src/local.environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"environment": [
{
"env": "local",
"host": "http://localhost:8080",
"hostV1": "http://localhost:8080",
"hostV2": "http://localhost:8080",
"cartPathApi": "/multi",
"cosmosDBURI": "https://localhost:8081",
"databaseID":"db",
"validBundlesNum":"10"
Expand Down
Loading

0 comments on commit 5d8ecc3

Please sign in to comment.