Skip to content

Commit

Permalink
adding performance test pipe (#102)
Browse files Browse the repository at this point in the history
Co-authored-by: LuciaM1 <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Lucia Mazzocchi <[email protected]>
Co-authored-by: EmVal <[email protected]>
Co-authored-by: Escarsel <[email protected]>
Co-authored-by: USERSAD\evalenti <[email protected]>
Co-authored-by: Elis Kina <[email protected]>
Co-authored-by: GabrieleMaiocchiFilippo <[email protected]>
  • Loading branch information
9 people authored Dec 20, 2023
1 parent 5aa38fa commit aaf4ec1
Show file tree
Hide file tree
Showing 15 changed files with 15,312 additions and 14,975 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/performance-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Manual run performance test

on:
workflow_dispatch:

defaults:
run:
shell: bash

permissions: write-all

jobs:
manual-create-pre-release:
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/dev'
strategy:
matrix:
environment: [dev]

name: "manual-run-performance-test"
runs-on: ubuntu-latest
environment: ${{ matrix.environment }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run k6 local test
uses: grafana/[email protected]
env:
MODEL_APPLICATION_BASE_URL: ${{ vars.MODEL_APPLICATION_BASE_URL }}
MODEL_APPLICATION_BASE_PATH: ${{ vars.MODEL_APPLICATION_BASE_PATH }}
MODEL_APPLICATION_KEY: ${{ secrets.MODEL_APPLICATION_KEY }}
with:
filename: perfomance_test/run_performance_tests.js
2 changes: 1 addition & 1 deletion helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: v1.3.3
version: v1.4.0-dev.3
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
44 changes: 44 additions & 0 deletions performance_test/functions/Bpmn/BPMN_associate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import http from 'k6/http';
import { group, check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';
import { generateAssociationBody, generateUpgradedBpmnByDefKey } from '../../utils_functions.js';
import { deployBpmn } from './BPMN_deploy.js';
import { upgradeBpmn } from './BPMN_upgrade.js';

export function associateRouteBpmn(baseUrl, token, acquirerId, tagName, version) {
group(tagName, function () {

const deployedBpmn = JSON.parse(deployBpmn(baseUrl, token, 'BPMNdeploy', version));
upgradeBpmn(
deployedBpmn.bpmnId,
generateUpgradedBpmnByDefKey(deployedBpmn.definitionKey),
token,
baseUrl,
'BPMNupgrade'
);

const fd = new FormData();

const params = {
headers: {
'Content-Type': 'application/json; boundary=' + fd.boundary,
'x-api-key': token,
},
tags: { name: tagName }
};

const endPoint = '/bpmn/bank/' + acquirerId + '/associations/function/MENU';
const url = baseUrl + endPoint;

const response = http.put(url, generateAssociationBody(deployedBpmn.bpmnId), params);

// console.error();
// console.log('Response status ASSOCIATE:', response.request);
// console.log('Response status ASSOCIATE:', response.status);
// console.log('Response body ASSOCIATE:', response.body);

check(response, {
'response code was 200': (response) => response.status == 200,
});
})
}
28 changes: 28 additions & 0 deletions performance_test/functions/Bpmn/BPMN_create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import http from 'k6/http';
import { check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';

export function createBpmn(baseUrl, token, fileBpmn) {
const fd = new FormData();
fd.append('filename', 'performance_test');
fd.append('file', fileBpmn);
fd.append('functionType', 'MENU');

const headers = {
'Content-Type': 'multipart/form-data; boundary=' + fd.boundary,
'x-api-key': token,
};

const params = {
headers: headers,
tags: { name: 'BPMNcreate' }
};

const response = http.post(`${baseUrl}/bpmn`, fd.body(), params);

check(response, {
'response code was 200': (response) => response.status == 200
});

return typeof response !== 'undefined' ? response.body : {};
}
34 changes: 34 additions & 0 deletions performance_test/functions/Bpmn/BPMN_deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import http from 'k6/http';
import { check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';
import { createBpmnAndGetId } from '../../utils_functions.js';

export function deployBpmn(baseUrl, token, tagName, version) {

const newBpmnBody = createBpmnAndGetId(baseUrl, token);
const fd = new FormData();
const params = {
headers: {
'Content-Type': 'application/json; boundary=' + fd.boundary,
'x-api-key': token,
},
tags: { name: tagName }
};

const endPoint = '/bpmn/deploy/' + newBpmnBody.bpmnId + '/version/' + version;
const url = baseUrl + endPoint;

const response = http.post(url, fd.body(), params);

// console.error();
// console.log('Response status DEPLOY:', response.request);
// console.log('Response status DEPLOY:', response.status);
// console.log('Response body DEPLOY:', response.body);

check(response, {
'response code was 200': (response) => response.status == 200,
});

return typeof response !== 'undefined' ? response.body : {};

}
23 changes: 23 additions & 0 deletions performance_test/functions/Bpmn/BPMN_getAll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import http from 'k6/http';
import { group, check } from 'k6';


export function getAllBpmn(baseUrl, token) {
group('BPMNgetAll', function () {

const params = {
headers: {
'x-api-key': token,
},
tags: { name: 'BPMNgetAll' },
};

let res = http.get(`${baseUrl}/api/v1/model/bpmn`, params);

console.log(`Get All BPMN request duration: ${res.timings.duration} ms`);

check(res, {
'response code was 200': (res) => res.status == 200,
});
});
}
34 changes: 34 additions & 0 deletions performance_test/functions/Bpmn/BPMN_upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import http from 'k6/http';
import { check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';

export function upgradeBpmn(uuid, fileBpmn, token, baseUrl, tagName) {
const fd = new FormData();
fd.append('uuid', uuid);
fd.append('filename', 'performance_test');
fd.append('file', fileBpmn);
fd.append('functionType', 'MENU');

const headers = {
'Content-Type': 'multipart/form-data; boundary=' + fd.boundary,
'x-api-key': token,
};

const endPoint = '/bpmn/upgrade';
const url = baseUrl + endPoint;

const params = {
headers: headers,
tags: { name: tagName }
}

const response = http.post(url,fd.body(), params);

// console.log('Response status UPGRADE:', response.request);
// console.log('Response status UPGRADE:', response.status);
// console.log('Response body UPGRADE:', response.body);

check(response, {
'response code was 200': (response) => response.status == 200
});
}
32 changes: 32 additions & 0 deletions performance_test/functions/Resources/RESOUCRES_update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import http from 'k6/http';
import { check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';
import { generateRandomHTML, generatedHTMLResource } from '../../utils_functions.js';

export function updateHtmlResource(baseUrl, token) {
const fd = new FormData();
const resourceId = generatedHTMLResource(baseUrl, token).resourceId;

fd.append('file', generateRandomHTML());

const headers = {
'Content-Type': 'multipart/form-data; boundary=' + fd.boundary,
'x-api-key': token,
};

const params = {
headers: headers,
tags: { name: 'RESOURCEUpdate' }
};

const response = http.put(`${baseUrl}/resources/${resourceId}`, fd.body(), params);

// console.error();
// console.log('Response request Resource UPDATE:', response.request);
// console.log('Response status Resource UPDATE:', response.status);
// console.log('Response body Resource UPDATE:', response.body);

check(response, {
'response code was 200': (response) => response.status == 200
});
}
36 changes: 36 additions & 0 deletions performance_test/functions/Resources/RESOURCES_create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import http from 'k6/http';
import { check } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';

export function createHtmlResource(baseUrl, token, file) {
const fd = new FormData();
fd.append('filename', `performance_test_${new Date().getTime()}.html`);
fd.append('file', file);
fd.append('resourceType', 'HTML');
fd.append('path', 'performanceTest')

const headers = {
'Content-Type': 'multipart/form-data; boundary=' + fd.boundary,
'x-api-key': token,
};

const params = {
headers: headers,
tags: { name: 'RESOURCECreate' }
};

const response = http.post(`${baseUrl}/resources`, fd.body(), params);

// console.error();
// console.log('Response request Resource CREATE:', response.request);
// console.log('Response status Resource CREATE:', response.status);
// console.log('Response body Resource CREATE:', response.body);

check(response, {
'response code was 200': (response) => response.status == 200
});



return typeof response !== 'undefined' ? response.body : {};
}
61 changes: 61 additions & 0 deletions performance_test/options_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const thresholdsSettings = {
http_req_failed: [{ threshold: 'rate<0.01', abortOnFail: true }],
http_req_duration: ['p(99)<2000'],
};

export const nameThresholds={
'http_req_duration{name:BPMNcreate}': ['p(95)<500'],
'http_req_waiting{name:BPMNcreate}':['p(95)<200'],
'http_req_failed{name:BPMNcreate}':['rate<0.01'],
'http_reqs{name:BPMNcreate}':[],

'http_req_duration{name:BPMNgetAll}': ['p(95)<6000'],
'http_req_waiting{name:BPMNgetAll}':['p(95)<6000'],
'http_req_failed{name:BPMNgetAll}':['rate<0.01'],
'http_reqs{name:BPMNgetAll}':[],

'http_req_duration{name:BPMNdeploy}': ['p(95)<1500'],
'http_req_waiting{name:BPMNdeploy}':['p(95)<300'],
'http_req_failed{name:BPMNdeploy}':['rate<0.01'],
'http_reqs{name:BPMNdeploy}':[],

'http_req_duration{name:BPMNassociate}': ['p(95)<1500'],
'http_req_waiting{name:BPMNassociate}':['p(95)<00'],
'http_req_failed{name:BPMNassociate}':['rate<0.01'],
'http_reqs{name:BPMNassociate}':[],

'http_req_duration{name:BPMNupgrade}': ['p(95)<1500'],
'http_req_waiting{name:BPMNupgrade}':['p(95)<00'],
'http_req_failed{name:BPMNupgrade}':['rate<0.01'],
'http_reqs{name:BPMNupgrade}':[],

// RESOURCES

'http_req_duration{name:RESOURCECreate}': ['p(95)<1500'],
'http_req_waiting{name:RESOURCECreate}':['p(95)<00'],
'http_req_failed{name:RESOURCECreate}':['rate<0.01'],
'http_reqs{name:RESOURCECreate}':[],

'http_req_duration{name:RESOURCEUpdate}': ['p(95)<1500'],
'http_req_waiting{name:RESOURCEUpdate}':['p(95)<00'],
'http_req_failed{name:RESOURCEUpdate}':['rate<0.01'],
'http_reqs{name:RESOURCEUpdate}':[]
}


export const average_load = {
executor: 'ramping-vus',
stages: [
{ duration: '2s', target: 20 },
{ duration: '5s', target: 20 },
{ duration: '5s', target: 0 },
],
};

export const low_load = {
executor: 'ramping-vus',
stages: [
{ duration: '4s', target: 1 },
{ duration: '4s', target: 0 },
],
};
28 changes: 28 additions & 0 deletions performance_test/run_performance_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { nameThresholds, low_load } from "./options_settings.js";
import { getAllBpmn } from "./functions/Bpmn/BPMN_getAll.js";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
import { associateRouteBpmn } from "./functions/Bpmn/BPMN_associate.js";
import { updateHtmlResource } from "./functions/Resources/RESOUCRES_update.js";

var appBaseUrl = `${__ENV.MODEL_APPLICATION_BASE_URL}`;
var appBasePath = `${__ENV.MODEL_APPLICATION_BASE_PATH}`;
var token = `${__ENV.MODEL_APPLICATION_KEY}`;


export const options = {
thresholds: nameThresholds,
scenarios: { low_load },
}


export function handleSummary(data) {
return {
"performance_summary.html": htmlReport(data),
};
}

export default function () {
getAllBpmn(appBaseUrl, token);
associateRouteBpmn(appBaseUrl.concat(appBasePath),token,'performance_acquirer','BPMNassociate',1);
updateHtmlResource(appBaseUrl.concat(appBasePath), token);
}
Loading

0 comments on commit aaf4ec1

Please sign in to comment.