From e92ce668a86ac3c84cf7ffb97faf557c95ab0663 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 14 Jun 2024 11:26:01 +0300 Subject: [PATCH] [#145] scenarios: Format js files with clang Signed-off-by: Dmitrii Stepanov --- examples/native.js | 4 +- examples/native_onsite.js | 4 +- scenarios/grpc.js | 108 +++++++++++++++++++------------------- scenarios/grpc_car.js | 70 ++++++++++++------------ scenarios/verify.js | 52 +++++++++--------- 5 files changed, 119 insertions(+), 119 deletions(-) diff --git a/examples/native.js b/examples/native.js index ff3cb40..d971909 100644 --- a/examples/native.js +++ b/examples/native.js @@ -7,7 +7,7 @@ const frostfs_cli = native.connect("s01.frostfs.devenv:8080", "1dd37fba80fec4e6a export const options = { stages: [ - {duration: '30s', target: 10}, + { duration: '30s', target: 10 }, ], }; @@ -24,7 +24,7 @@ export function setup() { fail(res.error) } console.info("created container", res.container_id) - return {container_id: res.container_id} + return { container_id: res.container_id } } export default function (data) { diff --git a/examples/native_onsite.js b/examples/native_onsite.js index d987f34..ba71460 100644 --- a/examples/native_onsite.js +++ b/examples/native_onsite.js @@ -14,11 +14,11 @@ export const options = { export default function () { let headers = { - 'unique_header': uuidv4() + 'unique_header': uuidv4() } let resp = frostfs_obj.put(headers) if (resp.success) { - frostfs_cli.get(container, resp.object_id) + frostfs_cli.get(container, resp.object_id) } else { console.log(resp.error) } diff --git a/scenarios/grpc.js b/scenarios/grpc.js index d18b1a0..973cf25 100644 --- a/scenarios/grpc.js +++ b/scenarios/grpc.js @@ -1,25 +1,25 @@ -import {sleep} from 'k6'; -import {SharedArray} from 'k6/data'; +import { sleep } from 'k6'; +import { SharedArray } from 'k6/data'; import exec from 'k6/execution'; import logging from 'k6/x/frostfs/logging'; import native from 'k6/x/frostfs/native'; import registry from 'k6/x/frostfs/registry'; import stats from 'k6/x/frostfs/stats'; -import {newGenerator} from './libs/datagen.js'; -import {parseEnv} from './libs/env-parser.js'; -import {textSummary} from './libs/k6-summary-0.0.2.js'; -import {uuidv4} from './libs/k6-utils-1.4.0.js'; +import { newGenerator } from './libs/datagen.js'; +import { parseEnv } from './libs/env-parser.js'; +import { textSummary } from './libs/k6-summary-0.0.2.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); const obj_list = new SharedArray( - 'obj_list', - function() { return JSON.parse(open(__ENV.PREGEN_JSON)).objects; }); + 'obj_list', + function () { return JSON.parse(open(__ENV.PREGEN_JSON)).objects; }); const container_list = new SharedArray( - 'container_list', - function() { return JSON.parse(open(__ENV.PREGEN_JSON)).containers; }); + 'container_list', + function () { return JSON.parse(open(__ENV.PREGEN_JSON)).containers; }); const read_size = JSON.parse(open(__ENV.PREGEN_JSON)).obj_size; const summary_json = __ENV.SUMMARY_JSON || '/tmp/summary.json'; @@ -27,17 +27,17 @@ const summary_json = __ENV.SUMMARY_JSON || '/tmp/summary.json'; // Select random gRPC endpoint for current VU const grpc_endpoints = __ENV.GRPC_ENDPOINTS.split(','); const grpc_endpoint = - grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)]; + grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)]; const grpc_client = native.connect( - grpc_endpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 5, - __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 60, - __ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false, - 1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0')); + grpc_endpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 5, + __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 60, + __ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false, + 1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0')); const log = logging.new().withField('endpoint', grpc_endpoint); const registry_enabled = !!__ENV.REGISTRY_FILE; const obj_registry = - registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined; + registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined; const duration = __ENV.DURATION; @@ -49,11 +49,11 @@ const read_age = __ENV.READ_AGE ? parseInt(__ENV.READ_AGE) : 10; let obj_to_read_selector = undefined; if (registry_enabled) { obj_to_read_selector = registry.getLoopedSelector( - __ENV.REGISTRY_FILE, 'obj_to_read', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status : 'created', - age : read_age, - }) + __ENV.REGISTRY_FILE, 'obj_to_read', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status: 'created', + age: read_age, + }) } const scenarios = {}; @@ -63,11 +63,11 @@ const write_grpc_chunk_size = 1024 * parseInt(__ENV.GRPC_CHUNK_SIZE || '0') const generator = newGenerator(write_vu_count > 0); if (write_vu_count > 0) { scenarios.write = { - executor : 'constant-vus', - vus : write_vu_count, - duration : `${duration}s`, - exec : 'obj_write', - gracefulStop : '5s', + executor: 'constant-vus', + vus: write_vu_count, + duration: `${duration}s`, + exec: 'obj_write', + gracefulStop: '5s', }; } @@ -78,24 +78,24 @@ if (registry_enabled && delete_age) { obj_to_delete_exit_on_null = write_vu_count == 0; let constructor = obj_to_delete_exit_on_null ? registry.getOneshotSelector - : registry.getSelector; + : registry.getSelector; obj_to_delete_selector = - constructor(__ENV.REGISTRY_FILE, 'obj_to_delete', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status : 'created', - age : delete_age, - }); + constructor(__ENV.REGISTRY_FILE, 'obj_to_delete', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status: 'created', + age: delete_age, + }); } const read_vu_count = parseInt(__ENV.READERS || '0'); if (read_vu_count > 0) { scenarios.read = { - executor : 'constant-vus', - vus : read_vu_count, - duration : `${duration}s`, - exec : 'obj_read', - gracefulStop : '5s', + executor: 'constant-vus', + vus: read_vu_count, + duration: `${duration}s`, + exec: 'obj_read', + gracefulStop: '5s', }; } @@ -103,21 +103,21 @@ const delete_vu_count = parseInt(__ENV.DELETERS || '0'); if (delete_vu_count > 0) { if (!obj_to_delete_selector) { throw new Error( - 'Positive DELETE worker number without a proper object selector'); + 'Positive DELETE worker number without a proper object selector'); } scenarios.delete = { - executor : 'constant-vus', - vus : delete_vu_count, - duration : `${duration}s`, - exec : 'obj_delete', - gracefulStop : '5s', + executor: 'constant-vus', + vus: delete_vu_count, + duration: `${duration}s`, + exec: 'obj_delete', + gracefulStop: '5s', }; } export const options = { scenarios, - setupTimeout : '5s', + setupTimeout: '5s', }; export function setup() { @@ -133,7 +133,7 @@ export function setup() { const start_timestamp = Date.now() console.log( - `Load started at: ${Date(start_timestamp).toString()}`) + `Load started at: ${Date(start_timestamp).toString()}`) } export function teardown(data) { @@ -142,13 +142,13 @@ export function teardown(data) { } const end_timestamp = Date.now() console.log( - `Load finished at: ${Date(end_timestamp).toString()}`) + `Load finished at: ${Date(end_timestamp).toString()}`) } export function handleSummary(data) { return { - 'stdout' : textSummary(data, {indent : ' ', enableColors : false}), - [summary_json] : JSON.stringify(data), + 'stdout': textSummary(data, { indent: ' ', enableColors: false }), + [summary_json]: JSON.stringify(data), }; } @@ -157,13 +157,13 @@ export function obj_write() { sleep(__ENV.SLEEP_WRITE); } - const headers = {unique_header : uuidv4()}; + const headers = { unique_header: uuidv4() }; const container = - container_list[Math.floor(Math.random() * container_list.length)]; + container_list[Math.floor(Math.random() * container_list.length)]; const payload = generator.genPayload(); const resp = - grpc_client.put(container, headers, payload, write_grpc_chunk_size); + grpc_client.put(container, headers, payload, write_grpc_chunk_size); if (!resp.success) { log.withField('cid', container).error(resp.error); return; @@ -186,7 +186,7 @@ export function obj_read() { } const resp = grpc_client.get(obj.c_id, obj.o_id) if (!resp.success) { - log.withFields({cid : obj.c_id, oid : obj.o_id}).error(resp.error); + log.withFields({ cid: obj.c_id, oid: obj.o_id }).error(resp.error); } return } @@ -194,7 +194,7 @@ export function obj_read() { const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = grpc_client.get(obj.container, obj.object) if (!resp.success) { - log.withFields({cid : obj.container, oid : obj.object}).error(resp.error); + log.withFields({ cid: obj.container, oid: obj.object }).error(resp.error); } } @@ -214,7 +214,7 @@ export function obj_delete() { const resp = grpc_client.delete(obj.c_id, obj.o_id); if (!resp.success) { // Log errors except (2052 - object already deleted) - log.withFields({cid : obj.c_id, oid : obj.o_id}).error(resp.error); + log.withFields({ cid: obj.c_id, oid: obj.o_id }).error(resp.error); return; } diff --git a/scenarios/grpc_car.js b/scenarios/grpc_car.js index 296d654..d866610 100644 --- a/scenarios/grpc_car.js +++ b/scenarios/grpc_car.js @@ -1,22 +1,22 @@ -import {sleep} from 'k6'; -import {SharedArray} from 'k6/data'; +import { sleep } from 'k6'; +import { SharedArray } from 'k6/data'; import logging from 'k6/x/frostfs/logging'; import native from 'k6/x/frostfs/native'; import registry from 'k6/x/frostfs/registry'; import stats from 'k6/x/frostfs/stats'; -import {newGenerator} from './libs/datagen.js'; -import {parseEnv} from './libs/env-parser.js'; -import {textSummary} from './libs/k6-summary-0.0.2.js'; -import {uuidv4} from './libs/k6-utils-1.4.0.js'; +import { newGenerator } from './libs/datagen.js'; +import { parseEnv } from './libs/env-parser.js'; +import { textSummary } from './libs/k6-summary-0.0.2.js'; +import { uuidv4 } from './libs/k6-utils-1.4.0.js'; parseEnv(); -const obj_list = new SharedArray('obj_list', function() { +const obj_list = new SharedArray('obj_list', function () { return JSON.parse(open(__ENV.PREGEN_JSON)).objects; }); -const container_list = new SharedArray('container_list', function() { +const container_list = new SharedArray('container_list', function () { return JSON.parse(open(__ENV.PREGEN_JSON)).containers; }); @@ -26,17 +26,17 @@ const summary_json = __ENV.SUMMARY_JSON || '/tmp/summary.json'; // Select random gRPC endpoint for current VU const grpc_endpoints = __ENV.GRPC_ENDPOINTS.split(','); const grpc_endpoint = - grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)]; + grpc_endpoints[Math.floor(Math.random() * grpc_endpoints.length)]; const grpc_client = native.connect( - grpc_endpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 5, - __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 60, - __ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false, - 1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0')); + grpc_endpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 5, + __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 60, + __ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false, + 1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0')); const log = logging.new().withField('endpoint', grpc_endpoint); const registry_enabled = !!__ENV.REGISTRY_FILE; const obj_registry = - registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined; + registry_enabled ? registry.open(__ENV.REGISTRY_FILE) : undefined; const duration = __ENV.DURATION; @@ -48,22 +48,22 @@ const delete_age = __ENV.DELETE_AGE ? parseInt(__ENV.DELETE_AGE) : undefined; let obj_to_delete_selector = undefined; if (registry_enabled && delete_age) { obj_to_delete_selector = registry.getSelector( - __ENV.REGISTRY_FILE, 'obj_to_delete', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status: 'created', - age: delete_age, - }); + __ENV.REGISTRY_FILE, 'obj_to_delete', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status: 'created', + age: delete_age, + }); } const read_age = __ENV.READ_AGE ? parseInt(__ENV.READ_AGE) : 10; let obj_to_read_selector = undefined; if (registry_enabled) { obj_to_read_selector = registry.getLoopedSelector( - __ENV.REGISTRY_FILE, 'obj_to_read', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status: 'created', - age: read_age, - }) + __ENV.REGISTRY_FILE, 'obj_to_read', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status: 'created', + age: read_age, + }) } const scenarios = {}; @@ -109,7 +109,7 @@ const delete_rate = parseInt(__ENV.DELETE_RATE || '0'); if (delete_rate > 0) { if (!obj_to_delete_selector) { throw new Error( - 'Positive DELETE worker number without a proper object selector'); + 'Positive DELETE worker number without a proper object selector'); } scenarios.delete = { @@ -131,7 +131,7 @@ export const options = { export function setup() { const total_pre_allocated_vu_count = - pre_alloc_write_vus + pre_alloc_read_vus + pre_alloc_delete_vus; + pre_alloc_write_vus + pre_alloc_read_vus + pre_alloc_delete_vus; const total_max_vu_count = max_read_vus + max_write_vus + max_delete_vus console.log(`Pregenerated containers: ${container_list.length}`); @@ -152,7 +152,7 @@ export function setup() { const start_timestamp = Date.now() console.log( - `Load started at: ${Date(start_timestamp).toString()}`) + `Load started at: ${Date(start_timestamp).toString()}`) } export function teardown(data) { @@ -161,12 +161,12 @@ export function teardown(data) { } const end_timestamp = Date.now() console.log( - `Load finished at: ${Date(end_timestamp).toString()}`) + `Load finished at: ${Date(end_timestamp).toString()}`) } export function handleSummary(data) { return { - 'stdout': textSummary(data, {indent: ' ', enableColors: false}), + 'stdout': textSummary(data, { indent: ' ', enableColors: false }), [summary_json]: JSON.stringify(data), }; } @@ -176,13 +176,13 @@ export function obj_write() { sleep(__ENV.SLEEP_WRITE); } - const headers = {unique_header: uuidv4()}; + const headers = { unique_header: uuidv4() }; const container = - container_list[Math.floor(Math.random() * container_list.length)]; + container_list[Math.floor(Math.random() * container_list.length)]; const payload = generator.genPayload(); const resp = - grpc_client.put(container, headers, payload, write_grpc_chunk_size); + grpc_client.put(container, headers, payload, write_grpc_chunk_size); if (!resp.success) { log.withField('cid', container).error(resp.error); return; @@ -205,7 +205,7 @@ export function obj_read() { } const resp = grpc_client.get(obj.c_id, obj.o_id) if (!resp.success) { - log.withFields({cid: obj.c_id, oid: obj.o_id}).error(resp.error); + log.withFields({ cid: obj.c_id, oid: obj.o_id }).error(resp.error); } return } @@ -213,7 +213,7 @@ export function obj_read() { const obj = obj_list[Math.floor(Math.random() * obj_list.length)]; const resp = grpc_client.get(obj.container, obj.object) if (!resp.success) { - log.withFields({cid: obj.container, oid: obj.object}).error(resp.error); + log.withFields({ cid: obj.container, oid: obj.object }).error(resp.error); } } @@ -230,7 +230,7 @@ export function obj_delete() { const resp = grpc_client.delete(obj.c_id, obj.o_id); if (!resp.success) { // Log errors except (2052 - object already deleted) - log.withFields({cid: obj.c_id, oid: obj.o_id}).error(resp.error); + log.withFields({ cid: obj.c_id, oid: obj.o_id }).error(resp.error); return; } diff --git a/scenarios/verify.js b/scenarios/verify.js index 8cdd24f..15a0055 100644 --- a/scenarios/verify.js +++ b/scenarios/verify.js @@ -1,13 +1,13 @@ -import {sleep} from 'k6'; -import {Counter} from 'k6/metrics'; +import { sleep } from 'k6'; +import { Counter } from 'k6/metrics'; import logging from 'k6/x/frostfs/logging'; import native from 'k6/x/frostfs/native'; import registry from 'k6/x/frostfs/registry'; import s3 from 'k6/x/frostfs/s3'; import stats from 'k6/x/frostfs/stats'; -import {parseEnv} from './libs/env-parser.js'; -import {textSummary} from './libs/k6-summary-0.0.2.js'; +import { parseEnv } from './libs/env-parser.js'; +import { textSummary } from './libs/k6-summary-0.0.2.js'; parseEnv(); @@ -39,23 +39,23 @@ let grpc_client = undefined; if (__ENV.GRPC_ENDPOINTS) { const grpcEndpoints = __ENV.GRPC_ENDPOINTS.split(','); const grpcEndpoint = - grpcEndpoints[Math.floor(Math.random() * grpcEndpoints.length)]; + grpcEndpoints[Math.floor(Math.random() * grpcEndpoints.length)]; log = log.withField('endpoint', grpcEndpoint); grpc_client = native.connect( - grpcEndpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 0, - __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 0, - __ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false, - 1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0')); + grpcEndpoint, '', __ENV.DIAL_TIMEOUT ? parseInt(__ENV.DIAL_TIMEOUT) : 0, + __ENV.STREAM_TIMEOUT ? parseInt(__ENV.STREAM_TIMEOUT) : 0, + __ENV.PREPARE_LOCALLY ? __ENV.PREPARE_LOCALLY.toLowerCase() === 'true' : false, + 1024 * parseInt(__ENV.MAX_OBJECT_SIZE || '0')); } // Connect to random S3 endpoint let s3_client = undefined; if (__ENV.S3_ENDPOINTS) { const no_verify_ssl = __ENV.NO_VERIFY_SSL || 'true'; - const connection_args = {no_verify_ssl: no_verify_ssl}; + const connection_args = { no_verify_ssl: no_verify_ssl }; const s3_endpoints = __ENV.S3_ENDPOINTS.split(','); const s3_endpoint = - s3_endpoints[Math.floor(Math.random() * s3_endpoints.length)]; + s3_endpoints[Math.floor(Math.random() * s3_endpoints.length)]; log = log.withField('endpoint', s3_endpoint); s3_client = s3.connect(s3_endpoint, connection_args); } @@ -64,10 +64,10 @@ if (__ENV.S3_ENDPOINTS) { // execute as many iterations as there are objects. Each object will have 3 // retries to be verified const obj_to_verify_selector = registry.getSelector( - __ENV.REGISTRY_FILE, 'obj_to_verify', - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { - status: 'created', - }); + __ENV.REGISTRY_FILE, 'obj_to_verify', + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { + status: 'created', +}); const obj_to_verify_count = obj_to_verify_selector.count(); // Execute at least one iteration (executor shared-iterations can't run 0 // iterations) @@ -96,15 +96,15 @@ export function setup() { // Populate counters with initial values for (const [status, counter] of Object.entries(obj_counters)) { const obj_selector = registry.getSelector( - __ENV.REGISTRY_FILE, status, - __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, {status}); + __ENV.REGISTRY_FILE, status, + __ENV.SELECTION_SIZE ? parseInt(__ENV.SELECTION_SIZE) : 0, { status }); counter.add(obj_selector.count()); } } export function handleSummary(data) { return { - 'stdout': textSummary(data, {indent: ' ', enableColors: false}), + 'stdout': textSummary(data, { indent: ' ', enableColors: false }), [summary_json]: JSON.stringify(data), }; } @@ -137,19 +137,19 @@ function verify_object_with_retries(obj, attempts) { // ReferenceError: Cannot access a variable before initialization. let lg = log; if (obj.c_id && obj.o_id) { - lg = lg.withFields({cid: obj.c_id, oid: obj.o_id}); + lg = lg.withFields({ cid: obj.c_id, oid: obj.o_id }); result = grpc_client.verifyHash(obj.c_id, obj.o_id, obj.payload_hash); } else if (obj.s3_bucket && obj.s3_key) { - lg = lg.withFields({bucket: obj.s3_bucket, key: obj.s3_key}); + lg = lg.withFields({ bucket: obj.s3_bucket, key: obj.s3_key }); result = - s3_client.verifyHash(obj.s3_bucket, obj.s3_key, obj.payload_hash); + s3_client.verifyHash(obj.s3_bucket, obj.s3_key, obj.payload_hash); } else { lg.withFields({ - cid: obj.c_id, - oid: obj.o_id, - bucket: obj.s3_bucket, - key: obj.s3_key - }).warn(`Object cannot be verified with supported protocols`); + cid: obj.c_id, + oid: obj.o_id, + bucket: obj.s3_bucket, + key: obj.s3_key + }).warn(`Object cannot be verified with supported protocols`); return 'skipped'; }