Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upd perf test #50

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .devops/performance-test-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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: "SCRIPT"
displayName: "Script name"
type: string
values:
- "get_organization_receipts"
- "get_transaction_list"
- "get_transaction_details"
- "hide_transaction"
default: "get_organization_receipts"
- name: "DB_NAME"
displayName: "DB name"
type: string
values:
- pagopa_receipt_pdf_servicek6
variables:
${{ if eq(parameters['ENVIRONMENT'], 'dev') }}:
poolImage: 'pagopa-dev-loadtest-linux'
API_SUBSCRIPTION_KEY: "$(DEV_API_SUBSCRIPTION_KEY)"
cosmosConnectionString: "$(DEV_COSMOS_DB_CONNECTION_STRING)"
${{ if eq(parameters['ENVIRONMENT'], 'uat') }}:
poolImage: 'pagopa-uat-loadtest-linux'
API_SUBSCRIPTION_KEY: "$(UAT_API_SUBSCRIPTION_KEY)"
cosmosConnectionString: "$(UAT_COSMOS_DB_CONNECTION_STRING)"

pool:
name: $(poolImage)

steps:
- script: |
cd ./performance-test/src
docker pull grafana/k6
displayName: Pull k6 image
- script: |
cd ./performance-test/src
docker build -f ./DockerfilePre -t exec-node .
docker run --rm --name initToRunk6 \
-e COSMOS_RECEIPTS_CONN_STRING=${COSMOS_CONN_STRING} \
-e ENVIRONMENT_STRING="${ENVIRONMENT_STRING}" \
exec-node
displayName: Precondition run perf test
env:
COSMOS_CONN_STRING: ${{ variables.cosmosConnectionString }}
- script: |
cd ./performance-test
sh ./run_performance_test.sh ${{ parameters.ENVIRONMENT }} ${{ parameters.TEST_TYPE }} ${{ parameters.SCRIPT }} ${{ parameters.DB_NAME}} $OCP_APIM_SUBSCRIPTION_KEY
displayName: Run k6 ${{ parameters.SCRIPT }} on ${{ parameters.ENVIRONMENT }}
env:
API_SUBSCRIPTION_KEY: ${{ variables.API_SUBSCRIPTION_KEY }}
- script: |
cd ./performance-test/src
docker build -f ./DockerfilePost -t exec-node .
docker run --rm --name initToRunk6 \
-e COSMOS_CONN_STRING=${COSMOS_CONN_STRING} \
-e ENVIRONMENT_STRING="${ENVIRONMENT_STRING}" \
exec-node
displayName: Teardown run perf test
env:
COSMOS_CONN_STRING: ${{ variables.cosmosConnectionString }}
ENVIRONMENT_STRING: ${{ parameters.ENVIRONMENT }}

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ hs_err_pid*
yarn.lock

# Terraform
**/.terraform/
**/.terraform/
**/prf.sh
11 changes: 11 additions & 0 deletions performance-test/src/DockerfilePost
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# specify the node base image with your desired version node:<version>
FROM node:18

WORKDIR /src/node-app

COPY ./ ./

RUN yarn install

ENTRYPOINT ["yarn", "start-teardown"]

11 changes: 11 additions & 0 deletions performance-test/src/DockerfilePre
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# specify the node base image with your desired version node:<version>
FROM node:18

WORKDIR /src/node-app

COPY ./ ./

RUN yarn install

ENTRYPOINT ["yarn", "start-precondition"]

19 changes: 19 additions & 0 deletions performance-test/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ where
- _API_SUBSCRIPTION_KEY_ is your sub-key

`<script-name>.js` is the scenario to run with k6 (e.g. get_organization_receipts.js)

### PreCond
```sh
docker build -f DockerfilePre -t exec-node .

docker run --rm --name initToRunk6 \
-e COSMOS_CONN_STRING=${COSMOS_CONN_STRING} \
-e ENVIRONMENT_STRING="${ENVIRONMENT_STRING}" \
exec-node
```
### TearDown
```sh
docker build -f DockerfilePost -t exec-node .

docker run --rm --name initToRunk6 \
-e COSMOS_RECEIPTS_CONN_STRING=${COSMOS_CONN_STRING} \
-e ENVIRONMENT_STRING="${ENVIRONMENT_STRING}" \
exec-node
```
15 changes: 13 additions & 2 deletions performance-test/src/dev.environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
{
"env": "dev",
"bizEventServiceURI": "https://api.dev.platform.pagopa.it/bizevents/service/v1/",
"bizEventTrxURI": "https://api.dev.platform.pagopa.it/bizevents/tx-service/v1/",
"cosmosDBURI": "https://pagopa-d-weu-bizevents-ds-cosmos-account.documents.azure.com:443/",
"databaseID":"db",
"containerID":"biz-events",
"numberOfEventsToPreload":"1000"
"cartGeneralContainerId":"biz-event-view-general",
"cartItemContainerId": "biz-event-view-cart",
"cartUserContainerId": "biz-event-view-user",
"numberOfEventsToPreload":"1000",
"testData": [
{
"fiscalCode": "TSTPRF00A00A000A",
"base_id": "biz_event_transaction_perf_test",
"totalNotice": 2
}
]
}
]
}
}
46 changes: 46 additions & 0 deletions performance-test/src/get_transaction_details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import http from 'k6/http';
import { check } from 'k6';
import { SharedArray } from 'k6/data';

import { getTransactionDetails } from "./modules/bizeventservice_client.js";
import { makeidMix, getRandomItemFromArray, makeRandomFiscalCode, getTestData } from './modules/helpers.js';

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

const varsArray = new SharedArray('vars', function() {
return JSON.parse(open(`./${__ENV.VARS}`)).environment;
});
// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const cosmosDBURI = `${vars.cosmosDBURI}`;
const bizEventTrxURI = `${vars.bizEventTrxURI}`;

const testData = vars.testData;

const subKey = `${__ENV.API_SUBSCRIPTION_KEY}`;

export default function() {

// Get a transaction detail
let tag = {
bizEventMethod: "getTransactionDetails",
};

var itemToRecover = getRandomItemFromArray(testData);
var fiscalCode = itemToRecover.fiscalCode;

const params = {
headers: {
'Ocp-Apim-Subscription-Key': subKey,
'x-fiscal-code': fiscalCode,
'Content-Type': 'application/json'
},
};

const response = getTransactionDetails(
bizEventTrxURI, itemToRecover.baseId , params);
console.log(`getTransactionDetails ... ${response.status}`);

check(response, {"getTransactionDetails status is 200": (res) => (res.status === 200)}, tag);

}
45 changes: 45 additions & 0 deletions performance-test/src/get_transaction_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import http from 'k6/http';
import { check } from 'k6';
import { SharedArray } from 'k6/data';

import { getTransactionList } from "./modules/bizeventservice_client.js";
import { makeidMix, getRandomItemFromArray, makeRandomFiscalCode } from './modules/helpers.js';

const varsArray = new SharedArray('vars', function() {
return JSON.parse(open(`./${__ENV.VARS}`)).environment;
});
// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const cosmosDBURI = `${vars.cosmosDBURI}`;
const bizEventTrxURI = `${vars.bizEventTrxURI}`;

const testData = vars.testData;

const subKey = `${__ENV.API_SUBSCRIPTION_KEY}`;


export default function(data) {

// Get a transactionList
let tag = {
bizEventMethod: "GetTransactionList",
};

var itemToRecover = getRandomItemFromArray(testData);
var fiscalCode = itemToRecover.fiscalCode;

const params = {
headers: {
'Ocp-Apim-Subscription-Key': subKey,
'x-fiscal-code': fiscalCode,
'Content-Type': 'application/json'
},
};

const response = getTransactionList(bizEventTrxURI, params);

console.log(`GetTransactionList ... ${response.status}`);

check(response, {"GetTransactionList status is 200": (res) => (res.status === 200)}, tag);

}
46 changes: 46 additions & 0 deletions performance-test/src/hide_transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import http from 'k6/http';
import { check } from 'k6';
import { SharedArray } from 'k6/data';

import { getTransactionDetails } from "./modules/bizeventservice_client.js";
import { makeidMix, getRandomItemFromArray, makeRandomFiscalCode, getTestData } from './modules/helpers.js';

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

const varsArray = new SharedArray('vars', function() {
return JSON.parse(open(`./${__ENV.VARS}`)).environment;
});
// workaround to use shared array (only array should be used)
const vars = varsArray[0];
const cosmosDBURI = `${vars.cosmosDBURI}`;
const bizEventTrxURI = `${vars.bizEventTrxURI}`;

const testData = vars.testData;

const subKey = `${__ENV.API_SUBSCRIPTION_KEY}`;

export default function() {

// Disable a transaction
let tag = {
bizEventMethod: "disableTransaction",
};

var itemToRecover = getRandomItemFromArray(testData);
var fiscalCode = itemToRecover.fiscalCode;

const params = {
headers: {
'Ocp-Apim-Subscription-Key': subKey,
'x-fiscal-code': fiscalCode,
'Content-Type': 'application/json'
},
};

const response = disableTransaction(
bizEventTrxURI, itemToRecover.baseId , params);
console.log(`disableTransaction ... ${response.status}`);

check(response, {"disableTransaction status is 200": (res) => (res.status === 200)}, tag);

}
12 changes: 10 additions & 2 deletions performance-test/src/local.environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
"environment": [
{
"env": "local",
"bizEventServiceURI": "http://localhost:8080/",
"bizEventServiceURI": "http://biz-events-service:8080/",
"bizEventTrxURI": "http://biz-events-service:8080/",
"cosmosDBURI": "https://pagopa-d-weu-bizevents-ds-cosmos-account.documents.azure.com:443/",
"databaseID":"db",
"containerID":"biz-events",
"numberOfEventsToPreload":"1000"
"numberOfEventsToPreload":"1",
"testData": [
{
"fiscalCode": "TSTPRF00A00A000A",
"baseId": "biz_event_transaction_perf_test",
"totalNotice": 2
}
]
}
]
}
16 changes: 14 additions & 2 deletions performance-test/src/modules/bizeventservice_client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import http from 'k6/http';

export function getOrganizationReceipt(bizEventServiceURI, organizationfiscalcode, iur, iuv, params) {
return http.get(bizEventServiceURI+`organizations/${organizationfiscalcode}/receipts/${iur}/paymentoptions/${iuv}`, params)
export function getOrganizationReceipt(bizEventURI, organizationfiscalcode, iur, iuv, params) {
return http.get(bizEventURI+`organizations/${organizationfiscalcode}/receipts/${iur}/paymentoptions/${iuv}`, params)
}

export function getTransactionList(bizEventURI, params) {
return http.get(bizEventURI+`transactions?size=5`, params)
}

export function getTransactionDetails(bizEventURI, id, params) {
return http.get(bizEventURI+`transactions/${id}`, id , params)
}

export function disableTransaction(bizEventURI, id, params) {
return http.post(bizEventURI+`transactions/${id}/disable`, id , {} , params)
}
Loading
Loading