[#173] s3: Support variable key length
All checks were successful
DCO action / DCO (pull_request) Successful in 1m2s
Tests and linters / Tests (pull_request) Successful in 1m43s
Tests and linters / Lint (pull_request) Successful in 2m42s
Tests and linters / Tests with -race (pull_request) Successful in 2m43s

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 f4c65c6112
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
2 changed files with 27 additions and 13 deletions

View file

@ -1,17 +1,30 @@
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()); key += objName();
return key; return key;
}
const asciiLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890()"
function objName() {
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 (__ENV.OBJ_NAME || 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