Skip to content

Commit

Permalink
Merge pull request #12 from pagopa/PAGOPA-658-pipeline-perf-test
Browse files Browse the repository at this point in the history
Pagopa 658 pipeline perf test
  • Loading branch information
FedericoRuzzier authored May 3, 2023
2 parents a02b288 + 231d1de commit 983e6d2
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 153 deletions.
35 changes: 12 additions & 23 deletions .devops/performance-test-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,35 @@
trigger: none

pool:
name: performance-test-linux
name: 'pagopa-dev-loadtest-linux'

parameters:
- name: "API_SUBSCRIPTION_KEY"
displayName: "API_SUBSCRIPTION_KEY"
type: string
- name: "ENVIRONMENT"
displayName: "Environment"
type: string
values:
- "dev"
- "uat"
- "prod"
- name: "TEST_TYPE"
displayName: "Test type"
type: string
values:
- "load"
- "spike"
- "stress"
- "soak"
- # TODO: add your values
- "ramping"
- "constant"
- name: "SCRIPT"
displayName: "Script name"
type: string
values:
- yourscriptname # TODO: add your script
- full_load_test
- create_organization

variables:
API_SUBSCRIPTION_KEY: $(DEV_POC_ENROLLMENT_SUB_KEY)

steps:
- script: |
cd ./performance-tests/src
cd ./performance-test/src
docker pull grafana/k6
displayName: Pull k6 image
# TODO: add your env params
- script: |
docker run \
-v ${PWD}:/script \
-e API_SUBSCRIPTION_KEY=${{ parameters.API_SUBSCRIPTION_KEY }} \
-e VARS=${{ parameters.ENVIRONMENT }}.environment.json \
-e TEST_TYPE=./test-types/${{ parameters.TEST_TYPE }}.json \
grafana/k6 run /script/${{ parameters.SCRIPT }}.js \
displayName: Run k6 ${{ parameters.SCRIPT }} on ${{ parameters.ENVIRONMENT }}
cd ./performance-test
sh ./run_performance_test.sh dev ${{ parameters.TEST_TYPE }} ${{ parameters.SCRIPT }} pocquarkusk6 $(API_SUBSCRIPTION_KEY)
displayName: Run k6 ${{ parameters.SCRIPT }} on dev
8 changes: 4 additions & 4 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ microservice-chart:
allowPrivilegeEscalation: false
resources:
requests:
memory: "384Mi"
cpu: "0.20"
memory: "256Mi"
cpu: "0.25"
limits:
memory: "512Mi"
cpu: "0.30"
cpu: "0.25"
autoscaling:
enable: true
minReplica: 1
maxReplica: 2
maxReplica: 3
pollingInterval: 10 # seconds
cooldownPeriod: 50 # seconds
triggers:
Expand Down
11 changes: 9 additions & 2 deletions performance-test/run_performance_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
ENVIRONMENT=$1
TYPE=$2
SCRIPT=$3
API_SUBSCRIPTION_KEY=$4
DB_NAME=$4
API_SUBSCRIPTION_KEY=$5

if [ -z "$ENVIRONMENT" ]
then
Expand All @@ -20,16 +21,22 @@ then
echo "No script name specified: sh run_performance_test.sh <local|dev|uat|prod> <load|stress|spike|soak|...> <script-name> <subkey>"
exit 1
fi
if [ -z "$DB_NAME" ]
then
DB_NAME="poc-quarkus-k6"
echo "No DB name specified: 'poc-quarkus-k6' is used."
fi

export env=${ENVIRONMENT}
export type=${TYPE}
export script=${SCRIPT}
export db_name=${DB_NAME}
export sub_key=${API_SUBSCRIPTION_KEY}

docker rm nginx
docker rm k6

stack_name=$(cd .. && basename "$PWD")
docker compose -p "${stack_name}" up -d --remove-orphans --force-recreate --build
docker compose -p "${stack_name}-k6" up -d --remove-orphans --force-recreate --build
docker logs -f k6
docker stop nginx
81 changes: 24 additions & 57 deletions performance-test/src/create_organization.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,42 @@
import http from 'k6/http';
import { check } from 'k6';
import { SharedArray } from 'k6/data';
import { randomOrg } from './modules/helpers.js';

import { createOrganization, deleteOrganization } from "./modules/orgsEnrollment_client.js";

//k6 run -o influxdb=http://influxdb:8086/k6 -e BASE_URL=http://localhost:8085 performance-test/src/full_load_test.js
//k6 run performance-test/src/full_load_test.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 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 orgsEnrollmentHost = `${vars.orgsEnrollmentHost}`;
const numberOfEventsToPreload = `${vars.numberOfEventsToPreload}`;

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

export function setup() {
}

function precondition() {
// no pre conditions
}

function postcondition(organizationFiscalCode) {

// Delete the newly created organization.
let tag = {
gpdMethod: "DeleteOrganization",
};

const params = {
headers: {
'Content-Type': 'application/json'
},
};

const r = deleteOrganization(orgsEnrollmentHost, organizationFiscalCode, params);

console.log("Delete organization " + organizationFiscalCode + " " + r.status);

check(r, {
"DeleteOrganization status is 200": (_r) => r.status === 200,
}, tag);
}
const rootUrl = `${vars.host}`;

export default function(data) {
const params = {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': __ENV.API_SUBSCRIPTION_KEY
},
};

const frameworkType = `?frameworkType=quarkus`

// Create an organization
let tag = {
orgsEnrollmentMethod: "CreateOrganization",
};
export default function () {

const params = {
headers: {
'Content-Type': 'application/json'
},
};
const organization_fiscal_code = randomOrg(11, "0123456789");

let mockOrganizationFiscalCode = 'mockOrganizationFiscalCode';
console.log(orgsEnrollmentHost + 'organization/' + mockOrganizationFiscalCode);
// Create new debt position (no validity date).

const response = createOrganization(orgsEnrollmentHost, mockOrganizationFiscalCode, params);
var url = `${rootUrl}/organizations/${organization_fiscal_code}${frameworkType}`;

console.log(`CreateOrganization ... ${response.status}`);
var r = http.post(url, "", params);

check(response, {"CreateOrganization status is 201": (res) => (res.status === 201)}, tag);
console.log("CreateOrganization call - organization_fiscal_code = " + organization_fiscal_code + ", Status = " + r.status);

postcondition(mockOrganizationFiscalCode, params);
}
check(r, {
'CreateOrganization status is 201': (r) => r.status === 201,
});
}
5 changes: 2 additions & 3 deletions performance-test/src/full_load_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export default function () {

var url = `${rootUrl}/organizations/${organization_fiscal_code}${frameworkType}`;


var r = http.post(url, params);
var r = http.post(url, "", params);

console.log("CreateOrganization call - organization_fiscal_code = " + organization_fiscal_code + ", Status = " + r.status);

Expand Down Expand Up @@ -62,7 +61,7 @@ export default function () {

url = `${rootUrl}/organizations/${organization_fiscal_code}${frameworkType}`;

r = http.del(url, params);
r = http.del(url, "", params);

console.log("DeleteOrganization call - organization_fiscal_code = " + organization_fiscal_code + ", Status = " + r.status);

Expand Down
55 changes: 0 additions & 55 deletions performance-test/src/modules/orgsEnrollment_client.js

This file was deleted.

6 changes: 3 additions & 3 deletions performance-test/src/test-types/constant.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"contacts": {
"executor": "constant-arrival-rate",
"duration": "3m",
"rate": 300,
"rate": 200,
"timeUnit": "1s",
"preAllocatedVUs": 2,
"maxVUs": 100
"preAllocatedVUs": 150,
"maxVUs": 150
}
},
"thresholds": {
Expand Down
12 changes: 6 additions & 6 deletions performance-test/src/test-types/load.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
],
"stages": [
{
"duration": "0.5s",
"target": 1
"duration": "1m",
"target": 100
},
{
"duration": "0.5s",
"target": 1
"duration": "2m",
"target": 200
},
{
"duration": "0s",
"target": 0
"duration": "1m",
"target": 150
}
],
"thresholds": {
Expand Down

0 comments on commit 983e6d2

Please sign in to comment.