From 1c7a3b3b6cfca98b8fcf98e18c235d63d7015532 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 28 Oct 2024 12:26:33 +0300 Subject: [PATCH] [#173] s3: Support variable key length Signed-off-by: Dmitrii Stepanov --- scenarios/libs/keygen.js | 43 ++++++++++++++++++++++++++------------ scenarios/run_scenarios.md | 1 + 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/scenarios/libs/keygen.js b/scenarios/libs/keygen.js index f6a9aa5..2691337 100644 --- a/scenarios/libs/keygen.js +++ b/scenarios/libs/keygen.js @@ -1,17 +1,34 @@ -import {uuidv4} from './k6-utils-1.4.0.js'; +import { uuidv4 } from './k6-utils-1.4.0.js'; export function generateS3Key() { - let width = parseInt(__ENV.DIR_WIDTH || '0'); - let height = parseInt(__ENV.DIR_HEIGHT || '0'); - - let key = '' - if (width > 0 && height > 0) { - for (let index = 0; index < height; index++) { - const w = Math.floor(Math.random() * width) + 1; - key = key + 'dir' + w + '/'; - } + let width = parseInt(__ENV.DIR_WIDTH || '0'); + let height = parseInt(__ENV.DIR_HEIGHT || '0'); + + let key = '' + if (width > 0 && height > 0) { + for (let index = 0; index < height; index++) { + const w = Math.floor(Math.random() * width) + 1; + key = key + 'dir' + w + '/'; } - - key += (__ENV.OBJ_NAME || uuidv4()); - return key; + } + + key += objName(); + return key; +} + +const asciiLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + +function objName() { + if (__ENV.OBJ_NAME) { + return __ENV.OBJ_NAME; + } + const length = parseInt(__ENV.OBJ_NAME_LENGTH || '0'); + if (length > 0) { + let name = ""; + for (let i = 0; i < length; i++) { + name += asciiLetters.charAt(Math.floor(Math.random() * asciiLetters.length)); + } + return name; + } + return uuidv4(); } \ No newline at end of file diff --git a/scenarios/run_scenarios.md b/scenarios/run_scenarios.md index 468340a..d0e8330 100644 --- a/scenarios/run_scenarios.md +++ b/scenarios/run_scenarios.md @@ -138,6 +138,7 @@ Options (in addition to the common options): * `DELETE_AGE` - age of object in seconds before which it can not be deleted. This parameter can be used to control how many objects we have in the system under load. * `SLEEP_DELETE` - time interval (in seconds) between deleting VU iterations. * `OBJ_NAME` - if specified, this name will be used for all write operations instead of random generation. + * `OBJ_NAME_LENGTH` - if specified, then name of the object will be generated with the specified length of ASCII characters. * `DIR_HEIGHT`, `DIR_WIDTH` - if both specified, object name will consist of `DIR_HEIGHT` directories, each of which can have `DIR_WIDTH` subdirectories, for example for `DIR_HEIGHT = 3, DIR_WIDTH = 100`, object names will be `/dir{1...100}/dir{1...100}/dir{1...100}/{uuid || OBJ_NAME}` ## S3 Multipart