Skip to content

Commit

Permalink
✅ K6 create schemas (#1001)
Browse files Browse the repository at this point in the history
* K6 create-schemas.js scenario

* Refactor HA config validation scripts

* Fix typo

* Rework error handling

* Override config

* Refactored collections

* Fix coverage
  • Loading branch information
wdbasson authored Sep 3, 2024
1 parent 9672c1b commit f5a75fd
Show file tree
Hide file tree
Showing 14 changed files with 476 additions and 237 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/continuous-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ jobs:
fi
exit $EXIT_CODE
fi
pwd
- name: Upload .coverage files as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-files-${{ matrix.module.id }}
path: coverage-files/.coverage.${{ matrix.module.id }}
include-hidden-files: true

status-check:
name: Status Check
Expand Down
1 change: 1 addition & 0 deletions scripts/k6/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export VUS=5
export ITERATIONS=2
export ISSUER_PREFIX=k6_issuer
export HOLDER_PREFIX=k6_holder
export SCHEMA_PREFIX=k6_schema
export SCHEMA_NAME="proof_of_person"
export SCHEMA_VERSION="0.1.0"
2 changes: 1 addition & 1 deletion scripts/k6/libs/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ export function publishRevocation(issuerAccessToken) {
};
try {
const requestBody = {
revocation_registry_credential_map: {}
revocation_registry_credential_map: {},
};
const response = http.post(url, JSON.stringify(requestBody), params);

Expand Down
105 changes: 105 additions & 0 deletions scripts/k6/scenarios/create-schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* global __ENV, __ITER, __VU */
/* eslint-disable no-undefined, no-console, camelcase */

import { check, sleep } from "k6";
import { SharedArray } from "k6/data";
import file from "k6/x/file";
import { getGovernanceBearerToken } from "../libs/auth.js";
import { createSchema, getSchema } from "../libs/functions.js";

const outputFilepath = "output/create-schemas.json";
const vus = Number.parseInt(__ENV.VUS, 10);
const iterations = Number.parseInt(__ENV.ITERATIONS, 10);
const schemaPrefix = __ENV.SCHEMA_PREFIX;

export const options = {
scenarios: {
default: {
executor: "per-vu-iterations",
vus,
iterations,
maxDuration: "24h",
},
},
setupTimeout: "180s", // Increase the setup timeout to 120 seconds
teardownTimeout: "180s", // Increase the teardown timeout to 120 seconds
maxRedirects: 4,
thresholds: {
// https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2
"http_req_duration{scenario:default}": ["max>=0"],
"http_reqs{scenario:default}": ["count >= 0"],
"iteration_duration{scenario:default}": ["max>=0"],
checks: ["rate==1"],
},
tags: {
test_run_id: "phased-issuance",
test_phase: "create-schemas",
},
};

// Seed data: Generating a list of options.iterations unique wallet names
const schemas = new SharedArray("schemas", () => {
const schemasArray = [];
for (let i = 0; i < options.scenarios.default.iterations * options.scenarios.default.vus; i++) {
schemasArray.push({
schemaName: `${schemaPrefix}_${i}`,
schemaVersion: `0.0.${i}`,
});
}
return schemasArray;
});

export function setup() {
file.writeString(outputFilepath, "");
const governanceBearerToken = getGovernanceBearerToken();
return { governanceBearerToken }; // eslint-disable-line no-eval
}

const iterationsPerVU = options.scenarios.default.iterations;
// Helper function to calculate the wallet index based on VU and iteration
function getWalletIndex(vu, iter) {
const walletIndex = (vu - 1) * iterationsPerVU + (iter - 1);
return walletIndex;
}

export default function (data) {
const governanceBearerToken = data.governanceBearerToken;
const walletIndex = getWalletIndex(__VU, __ITER + 1); // __ITER starts from 0, adding 1 to align with the logic
const schema = schemas[walletIndex];

const checkSchemaResponse = getSchema(governanceBearerToken, schema.schemaName, schema.schemaVersion);
check(checkSchemaResponse, {
"Schema doesn't exist yet": (r) => r.status === 200 && r.body === "[]",
});

const createSchemaResponse = createSchema(governanceBearerToken, schema.schemaName, schema.schemaVersion);
check(createSchemaResponse, {
"Schema created successfully": (r) => r.status === 200 && r.json("id") != null && r.json("id") !== "",
});

const getSchemaResponse = getSchema(governanceBearerToken, schema.schemaName, schema.schemaVersion);
check(getSchemaResponse, {
"getSchema check passes": (r) => {
if (r.status !== 200 || r.body === "[]") {
return false;
}

try {
const schemaData = JSON.parse(r.body);
return schemaData.length > 0 && schemaData[0].id != null;
} catch (e) {
console.error("Failed to parse schema data:", e);
return false;
}
},
});

const { id: schemaId } = JSON.parse(getSchemaResponse.body)[0];

const schemaData = JSON.stringify({
schema_name: schema.schemaName,
schema_version: schema.schemaVersion,
schema_id: schemaId,
});
file.appendString(outputFilepath, `${schemaData}\n`);
}
20 changes: 7 additions & 13 deletions scripts/k6/scenarios/revoke-credentials.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
/* global __ENV, __ITER, __VU */
/* eslint-disable no-undefined, no-console, camelcase */

import { check, sleep } from "k6";
import { SharedArray } from "k6/data";
import { Counter, Trend } from "k6/metrics";
import { check } from "k6";
import { Counter } from "k6/metrics";
import { getBearerToken } from "../libs/auth.js";
import {
checkRevoked,
createCredentialDefinition,
deleteTenant,
getCredentialDefinitionId,
getWalletIdByWalletName,
revokeCredentialAutoPublish,
} from "../libs/functions.js";
import { createIssuerIfNotExists } from "../libs/issuerUtils.js";
import { createSchemaIfNotExists } from "../libs/schemaUtils.js";

const inputFilepath = "../output/create-credentials.json";
const data = open(inputFilepath, "r");

const vus = Number.parseInt(__ENV.VUS, 10);
const iterations = Number.parseInt(__ENV.ITERATIONS, 10);
const issuerPrefix = __ENV.ISSUER_PREFIX;
const testFunctionReqs = new Counter("test_function_reqs");
const numIssuers = 1;

export const options = {
scenarios: {
Expand All @@ -45,13 +47,6 @@ export const options = {
},
};

const inputFilepath = "../output/create-credentials.json";
const data = open(inputFilepath, "r");

const testFunctionReqs = new Counter("test_function_reqs");

const numIssuers = 1;

export function setup() {
const issuers = [];
const ids = data.trim().split("\n").map(JSON.parse);
Expand Down Expand Up @@ -150,6 +145,5 @@ export default function (data) {
return true;
},
});
// sleep(0.2);
testFunctionReqs.add(1);
}
35 changes: 35 additions & 0 deletions scripts/k6/scripts/collection_creddef.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

config() {
export VUS=5 # setting any higher will exceed 30s lifecyce pre-stop on tenant-web
export ITERATIONS=8
export ISSUER_PREFIX="k6_issuer_creddef"
}

init() {
run_test ./scenarios/create-issuers.js
}

scenario() {
run_test ./scenarios/create-creddef.js
}

cleanup() {
echo "Cleaning up..."
export ITERATIONS=$((INITIAL_ITERATIONS * INTIAL_VUS))
export VUS=1
xk6 run ./scenarios/delete-issuers.js
}

run_collection() {
local deployments="$1"

config
init
run_ha_iterations "${deployments}" scenario
cleanup
}
35 changes: 35 additions & 0 deletions scripts/k6/scripts/collection_issuer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

config() {
export VUS=15
export ITERATIONS=10
export ISSUER_PREFIX="k6_issuer_issuer"
}

init() {
log "No init function specified"
}

scenario() {
run_test ./scenarios/create-issuers.js
}

cleanup() {
echo "Cleaning up..."
export ITERATIONS=$((INITIAL_ITERATIONS * INTIAL_VUS))
export VUS=1
xk6 run ./scenarios/delete-issuers.js
}

run_collection() {
local deployments="$1"

config
init
run_ha_iterations "${deployments}" scenario
cleanup
}
39 changes: 39 additions & 0 deletions scripts/k6/scripts/collection_proof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

config() {
export VUS=10
export ITERATIONS=10
export ISSUER_PREFIX="k6_issuer_proof"
export HOLDER_PREFIX="k6_holder_proof"
}

init() {
run_test ./scenarios/create-holders.js
run_test ./scenarios/create-invitation.js
run_test ./scenarios/create-credentials.js
}

scenario() {
run_test ./scenarios/create-proof.js
}

cleanup() {
echo "Cleaning up..."
local iterations=$((INITIAL_ITERATIONS * INTIAL_VUS))
local vus=1
xk6 run ./scenarios/delete-holders.js -e ITERATIONS=${iterations} -e VUS=${vus}
xk6 run ./scenarios/delete-issuers.js -e ITERATIONS=1 -e VUS=1
}

run_collection() {
local deployments="$1"

config
init
run_ha_iterations "${deployments}" scenario
cleanup
}
44 changes: 44 additions & 0 deletions scripts/k6/scripts/collection_revocation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

config() {
export VUS=10
export ITERATIONS=5
export ISSUER_PREFIX="k6_issuer_revocation"
export HOLDER_PREFIX="k6_holder_revocation"
}

init() {
run_test ./scenarios/create-holders.js
run_test ./scenarios/create-invitation.js
run_test ./scenarios/create-credentials.js
run_test ./scenarios/create-proof.js
}

scenario() {
local iterations=$((ITERATIONS * VUS)) # revoke sequentially
local vus=1
run_test ./scenarios/revoke-credentials.js -e INTERATIONS=${iterations} -e VUS=${vus}
export IS_REVOKED=true
run_test ./scenarios/create-proof.js
}

cleanup() {
echo "Cleaning up..."
local iterations=$((ITERATIONS * VUS))
local vus=1
run_test ./scenarios/delete-holders.js -e ITERATIONS=${iterations} -e VUS=${vus}
run_test ./scenarios/delete-issuers.js -e ITERATIONS=1 -e VUS=1
}

run_collection() {
local deployments="$1"

config
init
run_ha_iterations "${deployments}" scenario
cleanup
}
32 changes: 32 additions & 0 deletions scripts/k6/scripts/collection_schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

config() {
export VUS=20
export ITERATIONS=25
export SCHEMA_PREFIX="k6_schema"
}

init() {
echo "No init function specified"
}

scenario() {
run_test ./scenarios/create-schemas.js
}

cleanup() {
echo "No cleanup specified for schema collection"
}

run_collection() {
local deployments="$1"

config
init
run_ha_iterations "${deployments}" scenario
cleanup
}
Loading

0 comments on commit f5a75fd

Please sign in to comment.