From c06f68e21895a0f63a3f7b1d67dd2c006d751ba3 Mon Sep 17 00:00:00 2001 From: Silvio Moioli Date: Fri, 30 May 2025 19:26:00 +0200 Subject: [PATCH] k6: add benchmark for listing resources directly from Kubernetes (#65) * k6/k8s: make list limit configurable Signed-off-by: Silvio Moioli * k6: add Kubernetes api read benchmark Signed-off-by: Silvio Moioli --------- Signed-off-by: Silvio Moioli --- k6/k8s.js | 3 +-- k6/k8s_api_benchmark.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 k6/k8s_api_benchmark.js diff --git a/k6/k8s.js b/k6/k8s.js index c8143f1..de83dba 100644 --- a/k6/k8s.js +++ b/k6/k8s.js @@ -6,7 +6,6 @@ import * as YAML from './lib/js-yaml-4.1.0.mjs' import { URL } from './lib/url-1.0.0.js'; -const limit = 5000 const timeout = '3600s' // loads connection variables from kubeconfig's specified context @@ -59,7 +58,7 @@ export function del(url){ const continueRegex = /"continue":"([A-Za-z0-9]+)"/; // lists k8s resources -export function list(url) { +export function list(url, limit) { let _continue = 'first' let responses = [] diff --git a/k6/k8s_api_benchmark.js b/k6/k8s_api_benchmark.js new file mode 100644 index 0000000..d1581e7 --- /dev/null +++ b/k6/k8s_api_benchmark.js @@ -0,0 +1,41 @@ +import * as k8s from './k8s.js' + +// Parameters +const vus = __ENV.VUS || 1 +const perVuIterations = __ENV.PER_VU_ITERATIONS || 30 +const resource = __ENV.RESOURCE || "configmaps" +const limit = __ENV.LIMIT || 5000 +const namespace = __ENV.NAMESPACE || "scalability-test" +const kubeconfig = k8s.kubeconfig(__ENV.KUBECONFIG, __ENV.CONTEXT) +const baseUrl = __ENV.BASE_URL + +// Option setting +export const options = { + insecureSkipTLSVerify: true, + + tlsAuth: [ + { + cert: kubeconfig["cert"], + key: kubeconfig["key"], + }, + ], + + scenarios: { + list : { + executor: 'per-vu-iterations', + exec: 'list', + vus: vus, + iterations: perVuIterations, + maxDuration: '24h', + } + }, + thresholds: { + checks: ['rate>0.99'] + } +} + +// Test functions, in order of execution + +export function list() { + k8s.list(`${baseUrl}/api/v1/namespaces/${namespace}/${resource}`, limit) +}