[#173] s3: Support variable key length

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-10-28 12:26:33 +03:00
parent e0cbc3b763
commit 1c7a3b3b6c
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
2 changed files with 31 additions and 13 deletions

View file

@ -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() { export function generateS3Key() {
let width = parseInt(__ENV.DIR_WIDTH || '0'); let width = parseInt(__ENV.DIR_WIDTH || '0');
let height = parseInt(__ENV.DIR_HEIGHT || '0'); let height = parseInt(__ENV.DIR_HEIGHT || '0');
let key = '' let key = ''
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
for (let index = 0; index < height; index++) { for (let index = 0; index < height; index++) {
const w = Math.floor(Math.random() * width) + 1; const w = Math.floor(Math.random() * width) + 1;
key = key + 'dir' + w + '/'; 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();
} }

View file

@ -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. * `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. * `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` - 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}` * `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 ## S3 Multipart