From 90a6725d82ec75eafd6860f82fecdfb56e1a22c0 Mon Sep 17 00:00:00 2001 From: Silvio Moioli Date: Thu, 8 Jun 2023 12:06:01 +0200 Subject: [PATCH] edit script to continuously change configmaps Signed-off-by: Silvio Moioli --- bin/run_tests.mjs | 9 ++++++++ k6/change_config_maps.js | 44 ++++++++++++++++------------------------ k6/k8s.js | 18 ++++++++++++++++ 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/bin/run_tests.mjs b/bin/run_tests.mjs index 903a81d..e819d02 100755 --- a/bin/run_tests.mjs +++ b/bin/run_tests.mjs @@ -56,3 +56,12 @@ const testerSAN = tester["san"] const testerPublicPort = tester["public_http_port"] console.log(` Grafana UI: http://${testerSAN}:${testerPublicPort}/grafana/ (admin/${ADMIN_PASSWORD})`) console.log() + +// Change config maps +for (const [name, downstream] of downstreams) { + k6_run(tester, + { BASE_URL: `https://${downstream["private_name"]}:6443`, KUBECONFIG: downstream["kubeconfig"], CONTEXT: downstream["context"], CONFIG_MAP_COUNT: CONFIG_MAP_COUNT, VUS: 10, RATE: 200, DURATION: "1h"}, + {commit: commit, cluster: name, test: "change_config_maps.mjs"}, + "k6/change_config_maps.js", true + ) +} diff --git a/k6/change_config_maps.js b/k6/change_config_maps.js index aa96a9e..38a5536 100644 --- a/k6/change_config_maps.js +++ b/k6/change_config_maps.js @@ -1,18 +1,17 @@ import { sleep } from 'k6'; -import encoding from 'k6/encoding'; -import exec from 'k6/execution'; +import { Counter } from 'k6/metrics'; import * as k8s from './k8s.js' // Parameters -const namespace = "scalability-test-temp" -const data = encoding.b64encode("a".repeat(1)) -const vus = 5 -const duration = '2h' -const rate = 1 +const namespace = "scalability-test" // Option setting const kubeconfig = k8s.kubeconfig(__ENV.KUBECONFIG, __ENV.CONTEXT) const baseUrl = __ENV.BASE_URL +const configMapCount = Number(__ENV.CONFIG_MAP_COUNT) +const vus = Number(__ENV.VUS) +const rate = Number(__ENV.RATE) +const duration = __ENV.DURATION export const options = { insecureSkipTLSVerify: true, @@ -23,10 +22,10 @@ export const options = { }, ], - summaryTrendStats: ['avg', 'min', 'med', 'max', 'p(95)', 'p(99)', 'count'], + setupTimeout: '8h', scenarios: { - create: { + change: { executor: 'constant-vus', exec: 'change', vus: vus, @@ -38,32 +37,23 @@ export const options = { } }; +// Custom metrics +const resourceMetric = new Counter('changed_resources') + // Test functions, in order of execution -export function setup() { - // delete leftovers, if any - k8s.del(`${baseUrl}/api/v1/namespaces/${namespace}`) - - // create empty namespace - const body = { - "metadata": { - "name": namespace, - }, - } - k8s.create(`${baseUrl}/api/v1/namespaces`, body) -} - export function change() { - const name = `test-config-map-${exec.scenario.name}-${exec.scenario.iterationInTest}` + const name = `test-config-maps-${Math.floor(Math.random() * configMapCount)}` const body = { "metadata": { "name": name, "namespace": namespace }, - "data": {"data": data} + "data": {"data": (Math.random() + 1).toString(36).substring(2)} } - k8s.create(`${baseUrl}/api/v1/namespaces/${namespace}/configmaps`, body) - sleep(1.0/rate) - k8s.del(`${baseUrl}/api/v1/namespaces/${namespace}/configmaps/${name}`) + k8s.update(`${baseUrl}/api/v1/namespaces/${namespace}/configmaps/${name}`, body) + sleep(vus/rate) + + resourceMetric.add(1) } diff --git a/k6/k8s.js b/k6/k8s.js index 4be2cc2..7ab77e4 100644 --- a/k6/k8s.js +++ b/k6/k8s.js @@ -56,6 +56,24 @@ export function del(url){ return res } +// updates an existing k8s resource +export function update(url, body){ + const res = http.put(url, JSON.stringify(body)); + + check(res, { + 'PUT returns status 200 or 409': (r) => r.status === 200 || r.status === 409, + }) + + if (res.status === 409) { + // wait a bit and try again + sleep(Math.random()) + + return update(url, body) + } + + return res +} + const continueRegex = /"continue":"([A-Za-z0-9]+)"/; // lists k8s resources