From 811d282a072789c81c3116fea86c0fbad045453e Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:51:18 +0100 Subject: [PATCH 01/15] PAGOPA-1529 adding script for new api --- performance-test/src/calculator_getFees.js | 2 +- .../src/calculator_getFeesByPsp.js | 2 +- .../src/calculator_getFeesMulti.js | 115 ++++++++++++++++++ performance-test/src/dev.environment.json | 4 +- .../src/helpers/calculator_helper.js | 6 + performance-test/src/local.environment.json | 4 +- performance-test/src/uat.environment.json | 4 +- 7 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 performance-test/src/calculator_getFeesMulti.js diff --git a/performance-test/src/calculator_getFees.js b/performance-test/src/calculator_getFees.js index 60791a06..fe5b04f8 100644 --- a/performance-test/src/calculator_getFees.js +++ b/performance-test/src/calculator_getFees.js @@ -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}`; diff --git a/performance-test/src/calculator_getFeesByPsp.js b/performance-test/src/calculator_getFeesByPsp.js index 0dcfd2af..8c52c104 100644 --- a/performance-test/src/calculator_getFeesByPsp.js +++ b/performance-test/src/calculator_getFeesByPsp.js @@ -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}`; diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js new file mode 100644 index 00000000..25d7cf41 --- /dev/null +++ b/performance-test/src/calculator_getFeesMulti.js @@ -0,0 +1,115 @@ +// 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 primaryCreditorInstitution = 'fiscalCode-' + Math.floor(Math.random() * 2) + 1; + + let payload = { + "bin": "1005066", + "paymentMethod": "CP", + "touchpoint": "CHECKOUT", + "idPspList": [], + "paymentNotice": [ + { + "primaryCreditorInstitution": primaryCreditorInstitution, + "paymentAmount": paymentAmount, + "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) }); + } +} diff --git a/performance-test/src/dev.environment.json b/performance-test/src/dev.environment.json index 6dd04711..e32628f9 100644 --- a/performance-test/src/dev.environment.json +++ b/performance-test/src/dev.environment.json @@ -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" diff --git a/performance-test/src/helpers/calculator_helper.js b/performance-test/src/helpers/calculator_helper.js index 3b673a6b..8da4dabe 100644 --- a/performance-test/src/helpers/calculator_helper.js +++ b/performance-test/src/helpers/calculator_helper.js @@ -12,6 +12,12 @@ export function getFees(rootUrl, payload, params) { 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` diff --git a/performance-test/src/local.environment.json b/performance-test/src/local.environment.json index e98f2552..1ed6be4e 100644 --- a/performance-test/src/local.environment.json +++ b/performance-test/src/local.environment.json @@ -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" diff --git a/performance-test/src/uat.environment.json b/performance-test/src/uat.environment.json index d52510dc..d4d7b870 100644 --- a/performance-test/src/uat.environment.json +++ b/performance-test/src/uat.environment.json @@ -2,7 +2,9 @@ "environment": [ { "env": "uat", - "host": "https://api.uat.platform.pagopa.it/afm/calculator-service/v1", + "hostV1": "https://api.uat.platform.pagopa.it/afm/calculator-service/v1", + "hostV2": "https://api.uat.platform.pagopa.it/afm/calculator-service/v2", + "cartPathApi": "", "cosmosDBURI": "https://pagopa-u-weu-afm-marketplace-cosmos-account.documents.azure.com:443/", "databaseID":"db", "validBundlesNum":"10000" From ffc636058de718da357b3ba48079aeee27cd6476 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:00:01 +0100 Subject: [PATCH 02/15] PAGOPA-1529 adding scenario to pipeline --- .devops/performance-test-pipelines.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.devops/performance-test-pipelines.yaml b/.devops/performance-test-pipelines.yaml index 0c4f7c32..12168007 100644 --- a/.devops/performance-test-pipelines.yaml +++ b/.devops/performance-test-pipelines.yaml @@ -26,6 +26,7 @@ parameters: values: - calculator_getFees - calculator_getFeesByPsp + - calculator_getFeesMulti variables: ${{ if eq(parameters['ENVIRONMENT'], 'dev') }}: From 41f8e335cefc4b69f4353d9b6abb17788b79144b Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:07:50 +0100 Subject: [PATCH 03/15] PAGOPA-1494 first load old test --- performance-test/src/uat.environment.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance-test/src/uat.environment.json b/performance-test/src/uat.environment.json index d4d7b870..cbced2ec 100644 --- a/performance-test/src/uat.environment.json +++ b/performance-test/src/uat.environment.json @@ -7,7 +7,7 @@ "cartPathApi": "", "cosmosDBURI": "https://pagopa-u-weu-afm-marketplace-cosmos-account.documents.azure.com:443/", "databaseID":"db", - "validBundlesNum":"10000" + "validBundlesNum":"10" } ] } From f4efe133f83a97ac1d5712d73a30355d44fb630f Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:25:40 +0100 Subject: [PATCH 04/15] PAGOPA-1529 fixing cred inst creation --- performance-test/src/calculator_getFeesMulti.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index 25d7cf41..8e2c73d5 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,7 +66,7 @@ export default function calculator() { // to give randomness to request in order to avoid caching const paymentAmount = Math.floor(Math.random() * (100 + __VU) % 100); - const primaryCreditorInstitution = 'fiscalCode-' + Math.floor(Math.random() * 2) + 1; + const primaryCreditorInstitution = '7777777777' + (int)Math.floor(Math.random() * 10); let payload = { "bin": "1005066", From 013f04a53691d6bb6bc59c19eea252916a065ecb Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:36:18 +0100 Subject: [PATCH 05/15] PAGOPA-1529 minor fix to script --- performance-test/src/calculator_getFeesMulti.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index 8e2c73d5..a83beac7 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,7 +66,7 @@ export default function calculator() { // to give randomness to request in order to avoid caching const paymentAmount = Math.floor(Math.random() * (100 + __VU) % 100); - const primaryCreditorInstitution = '7777777777' + (int)Math.floor(Math.random() * 10); + const primaryCreditorInstitution = '7777777777' + Math.floor(Math.random() * 10); let payload = { "bin": "1005066", From a82efd65a1cefc7b186d8974b128791d26a26a32 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Wed, 20 Mar 2024 09:52:33 +0100 Subject: [PATCH 06/15] PAGOPA-1529 minor fix to scenario --- performance-test/src/calculator_getFeesMulti.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index a83beac7..398ece66 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,7 +66,8 @@ export default function calculator() { // to give randomness to request in order to avoid caching const paymentAmount = Math.floor(Math.random() * (100 + __VU) % 100); - const primaryCreditorInstitution = '7777777777' + Math.floor(Math.random() * 10); + //const primaryCreditorInstitution = '7777777777' + Math.floor(Math.random() * 10); + const primaryCreditorInstitution = 'fiscalCode-' + Math.floor(Math.random() * 2) + 1; let payload = { "bin": "1005066", From 1fbccde7e8f6c089086c090961d7208567f434ca Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Wed, 20 Mar 2024 09:55:48 +0100 Subject: [PATCH 07/15] PAGOPA-1529 incrementing bundles to 10k --- performance-test/src/uat.environment.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/performance-test/src/uat.environment.json b/performance-test/src/uat.environment.json index cbced2ec..d4d7b870 100644 --- a/performance-test/src/uat.environment.json +++ b/performance-test/src/uat.environment.json @@ -7,7 +7,7 @@ "cartPathApi": "", "cosmosDBURI": "https://pagopa-u-weu-afm-marketplace-cosmos-account.documents.azure.com:443/", "databaseID":"db", - "validBundlesNum":"10" + "validBundlesNum":"10000" } ] } From b4571e0045d7201402055401a5c83311c59be5ff Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Wed, 20 Mar 2024 10:48:43 +0100 Subject: [PATCH 08/15] PAGOPA-1529 adding data to test cart --- .../src/calculator_getFeesMulti.js | 19 +++++++++++++++---- performance-test/src/helpers/data.json | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index 398ece66..2a04206e 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,8 +66,9 @@ export default function calculator() { // to give randomness to request in order to avoid caching const paymentAmount = Math.floor(Math.random() * (100 + __VU) % 100); - //const primaryCreditorInstitution = '7777777777' + Math.floor(Math.random() * 10); - const primaryCreditorInstitution = 'fiscalCode-' + Math.floor(Math.random() * 2) + 1; + 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", @@ -76,8 +77,18 @@ export default function calculator() { "idPspList": [], "paymentNotice": [ { - "primaryCreditorInstitution": primaryCreditorInstitution, - "paymentAmount": paymentAmount, + "primaryCreditorInstitution": primaryCreditorInstitution1, + "paymentAmount": paymentAmount/2, + "transferList": [ + { + "creditorInstitution": "fiscalCode-1", + "transferCategory": "TAX1" + } + ] + }, + { + "primaryCreditorInstitution": primaryCreditorInstitution2, + "paymentAmount": paymentAmount/2, "transferList": [ { "creditorInstitution": "fiscalCode-1", diff --git a/performance-test/src/helpers/data.json b/performance-test/src/helpers/data.json index 6c5fddc3..d6fe4be4 100644 --- a/performance-test/src/helpers/data.json +++ b/performance-test/src/helpers/data.json @@ -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": [ From 91bc94cd2348878de7093386f73e7dc9bf4ff690 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:33:07 +0100 Subject: [PATCH 09/15] PAGOPA-1529 old test attempt --- performance-test/src/calculator_getFeesMulti.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index 2a04206e..2a74e283 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,9 +66,9 @@ export default function calculator() { // 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; + //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", @@ -77,7 +77,7 @@ export default function calculator() { "idPspList": [], "paymentNotice": [ { - "primaryCreditorInstitution": primaryCreditorInstitution1, + "primaryCreditorInstitution": primaryCreditorInstitution, "paymentAmount": paymentAmount/2, "transferList": [ { @@ -87,7 +87,7 @@ export default function calculator() { ] }, { - "primaryCreditorInstitution": primaryCreditorInstitution2, + "primaryCreditorInstitution": primaryCreditorInstitution, "paymentAmount": paymentAmount/2, "transferList": [ { From d54801ff5196cb502859697b6f68604e443f0f7d Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:26:55 +0100 Subject: [PATCH 10/15] PAGOPA-1529 changing load test type --- performance-test/src/test-types/load.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/performance-test/src/test-types/load.json b/performance-test/src/test-types/load.json index 3ac57a60..8ef8c61e 100644 --- a/performance-test/src/test-types/load.json +++ b/performance-test/src/test-types/load.json @@ -12,11 +12,11 @@ "stages": [ { "duration": "5m", - "target": 100 + "target": 200 }, { "duration": "10m", - "target": 100 + "target": 400 }, { "duration": "5m", From ee4a16741c04de15d4ca9bc63a6ca89411664b88 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:33:57 +0100 Subject: [PATCH 11/15] PAGOPA-1529 testing new scenario --- performance-test/src/calculator_getFeesMulti.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index 2a74e283..2a04206e 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,9 +66,9 @@ export default function calculator() { // 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; + 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", @@ -77,7 +77,7 @@ export default function calculator() { "idPspList": [], "paymentNotice": [ { - "primaryCreditorInstitution": primaryCreditorInstitution, + "primaryCreditorInstitution": primaryCreditorInstitution1, "paymentAmount": paymentAmount/2, "transferList": [ { @@ -87,7 +87,7 @@ export default function calculator() { ] }, { - "primaryCreditorInstitution": primaryCreditorInstitution, + "primaryCreditorInstitution": primaryCreditorInstitution2, "paymentAmount": paymentAmount/2, "transferList": [ { From da27486ab6ecd4722fc122edc4a2be1434af98ca Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:21:32 +0100 Subject: [PATCH 12/15] PAGOPA-1529 reverting scenario --- performance-test/src/calculator_getFeesMulti.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/performance-test/src/calculator_getFeesMulti.js b/performance-test/src/calculator_getFeesMulti.js index 2a04206e..2a74e283 100644 --- a/performance-test/src/calculator_getFeesMulti.js +++ b/performance-test/src/calculator_getFeesMulti.js @@ -66,9 +66,9 @@ export default function calculator() { // 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; + //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", @@ -77,7 +77,7 @@ export default function calculator() { "idPspList": [], "paymentNotice": [ { - "primaryCreditorInstitution": primaryCreditorInstitution1, + "primaryCreditorInstitution": primaryCreditorInstitution, "paymentAmount": paymentAmount/2, "transferList": [ { @@ -87,7 +87,7 @@ export default function calculator() { ] }, { - "primaryCreditorInstitution": primaryCreditorInstitution2, + "primaryCreditorInstitution": primaryCreditorInstitution, "paymentAmount": paymentAmount/2, "transferList": [ { From 67f8567ca08659c3aaeeac5fbfacd2cac83dc5ce Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:52:51 +0100 Subject: [PATCH 13/15] PAGOPA-1529 adding psp specific scenario --- .devops/performance-test-pipelines.yaml | 1 + .../src/calculator_getFeesByPspMulti.js | 127 ++++++++++++++++++ .../src/helpers/calculator_helper.js | 6 + 3 files changed, 134 insertions(+) create mode 100644 performance-test/src/calculator_getFeesByPspMulti.js diff --git a/.devops/performance-test-pipelines.yaml b/.devops/performance-test-pipelines.yaml index 12168007..971890f9 100644 --- a/.devops/performance-test-pipelines.yaml +++ b/.devops/performance-test-pipelines.yaml @@ -27,6 +27,7 @@ parameters: - calculator_getFees - calculator_getFeesByPsp - calculator_getFeesMulti + - calculator_getFeesByPspMulti variables: ${{ if eq(parameters['ENVIRONMENT'], 'dev') }}: diff --git a/performance-test/src/calculator_getFeesByPspMulti.js b/performance-test/src/calculator_getFeesByPspMulti.js new file mode 100644 index 00000000..f97fa231 --- /dev/null +++ b/performance-test/src/calculator_getFeesByPspMulti.js @@ -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) }); + } +} diff --git a/performance-test/src/helpers/calculator_helper.js b/performance-test/src/helpers/calculator_helper.js index 8da4dabe..3cf6ca1c 100644 --- a/performance-test/src/helpers/calculator_helper.js +++ b/performance-test/src/helpers/calculator_helper.js @@ -12,6 +12,12 @@ 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) From b88f4d308bb19c24f033b3b9635e0e078b28f5a7 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:50:11 +0100 Subject: [PATCH 14/15] PAGOPA-529 new helm values --- helm/values-prod.yaml | 6 +++--- helm/values-uat.yaml | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index b4aabf83..510f5d36 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -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 diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 620a1c53..3ff16600 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -53,7 +53,7 @@ microservice-chart: resources: requests: memory: "512Mi" - cpu: "0.75" + cpu: "0.5" limits: memory: "1024Mi" cpu: "1.0" @@ -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 @@ -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" From 8012e7faa54a79fb3403fd2740ae99f65d87f1d8 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Tue, 26 Mar 2024 11:03:51 +0000 Subject: [PATCH 15/15] Bump to version 2.10.14 [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi-node-v1.json | 2 +- openapi/openapi-node-v2.json | 2 +- openapi/openapi-v1.json | 2 +- openapi/openapi-v2.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 78f85868..035c0a34 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-afm-calculator description: Microservice that handles calculation for pagoPA Advanced Fees Management type: application -version: 2.25.0 -appVersion: 2.10.13 +version: 2.26.0 +appVersion: 2.10.14 dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index b5696a36..fa3131d4 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-calculator - tag: "2.10.13" + tag: "2.10.14" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 510f5d36..59e200ea 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-calculator - tag: "2.10.13" + tag: "2.10.14" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 3ff16600..54cfa1a0 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-afm-calculator - tag: "2.10.13" + tag: "2.10.14" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi-node-v1.json b/openapi/openapi-node-v1.json index 7dd5e6d7..b6a64110 100644 --- a/openapi/openapi-node-v1.json +++ b/openapi/openapi-node-v1.json @@ -4,7 +4,7 @@ "title": "PagoPA API Calculator Logic", "description": "Calculator Logic microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", - "version": "2.10.13" + "version": "2.10.14" }, "servers": [ { diff --git a/openapi/openapi-node-v2.json b/openapi/openapi-node-v2.json index 017ce64e..f72ca37b 100644 --- a/openapi/openapi-node-v2.json +++ b/openapi/openapi-node-v2.json @@ -4,7 +4,7 @@ "title": "PagoPA API Calculator Logic", "description": "Calculator Logic microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", - "version": "2.10.13" + "version": "2.10.14" }, "servers": [ { diff --git a/openapi/openapi-v1.json b/openapi/openapi-v1.json index c9554596..f6f07564 100644 --- a/openapi/openapi-v1.json +++ b/openapi/openapi-v1.json @@ -4,7 +4,7 @@ "title": "PagoPA API Calculator Logic", "description": "Calculator Logic microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", - "version": "2.10.13" + "version": "2.10.14" }, "servers": [ { diff --git a/openapi/openapi-v2.json b/openapi/openapi-v2.json index 017ce64e..f72ca37b 100644 --- a/openapi/openapi-v2.json +++ b/openapi/openapi-v2.json @@ -4,7 +4,7 @@ "title": "PagoPA API Calculator Logic", "description": "Calculator Logic microservice for pagoPA AFM", "termsOfService": "https://www.pagopa.gov.it/", - "version": "2.10.13" + "version": "2.10.14" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 60b80bfa..3757b517 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa calculator - 2.10.13 + 2.10.14 afm-calculator Calculator Logic microservice for pagoPA AFM