From 0dc0ba170418b404069df9e9f21e65c622b632d5 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 20 Jul 2023 10:00:51 +0300 Subject: [PATCH] [#25] xk6: Read objects from registry for S3 tests Signed-off-by: Dmitrii Stepanov --- scenarios/s3.js | 24 ++++++++++++++++++++++++ scenarios/s3_car.js | 24 ++++++++++++++++++++++++ scenarios/s3local.js | 24 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/scenarios/s3.js b/scenarios/s3.js index e741708..6e3a690 100644 --- a/scenarios/s3.js +++ b/scenarios/s3.js @@ -48,6 +48,18 @@ if (registry_enabled && delete_age) { ); } +let obj_to_read_selector = undefined; +if (registry_enabled) { + obj_to_read_selector = registry.getSelector( + __ENV.REGISTRY_FILE, + "obj_to_read", + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, + { + status: "created", + } + ) +} + const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE), __ENV.PAYLOAD_TYPE || ""); const scenarios = {}; @@ -144,6 +156,18 @@ export function obj_read() { sleep(__ENV.SLEEP_READ); } + if(obj_to_read_selector) { + const obj = obj_to_read_selector.nextObject(5); + if (!obj) { + return; + } + const resp = s3_client.get(obj.s3_bucket, obj.s3_key) + if (!resp.success) { + log.withFields({bucket: obj.s3_bucket, key: obj.s3_key}).error(resp.error); + } + return + } + const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = s3_client.get(obj.bucket, obj.object); diff --git a/scenarios/s3_car.js b/scenarios/s3_car.js index 95edfd5..3ec5fa6 100644 --- a/scenarios/s3_car.js +++ b/scenarios/s3_car.js @@ -48,6 +48,18 @@ if (registry_enabled && delete_age) { ); } +let obj_to_read_selector = undefined; +if (registry_enabled) { + obj_to_read_selector = registry.getSelector( + __ENV.REGISTRY_FILE, + "obj_to_read", + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, + { + status: "created", + } + ) +} + const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE)); const scenarios = {}; @@ -171,6 +183,18 @@ export function obj_read() { sleep(__ENV.SLEEP_READ); } + if(obj_to_read_selector) { + const obj = obj_to_read_selector.nextObject(5); + if (!obj) { + return; + } + const resp = s3_client.get(obj.s3_bucket, obj.s3_key) + if (!resp.success) { + log.withFields({bucket: obj.s3_bucket, key: obj.s3_key}).error(resp.error); + } + return + } + const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = s3_client.get(obj.bucket, obj.object); diff --git a/scenarios/s3local.js b/scenarios/s3local.js index 4038eed..6d40f11 100644 --- a/scenarios/s3local.js +++ b/scenarios/s3local.js @@ -44,6 +44,18 @@ const log = logging.new().withField("config", config_file); const registry_enabled = !!__ENV.REGISTRY_FILE; const obj_registry = registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined; +let obj_to_read_selector = undefined; +if (registry_enabled) { + obj_to_read_selector = registry.getSelector( + __ENV.REGISTRY_FILE, + "obj_to_read", + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, + { + status: "created", + } + ) +} + const duration = __ENV.DURATION; const generator = datagen.generator(1024 * parseInt(__ENV.WRITE_OBJ_SIZE)); @@ -118,6 +130,18 @@ export function obj_write() { } export function obj_read() { + if(obj_to_read_selector) { + const obj = obj_to_read_selector.nextObject(5); + if (!obj) { + return; + } + const resp = s3_client.get(obj.s3_bucket, obj.s3_key) + if (!resp.success) { + log.withFields({bucket: obj.s3_bucket, key: obj.s3_key}).error(resp.error); + } + return + } + const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = s3_client.get(obj.bucket, obj.object);