forked from TrueCloudLab/xk6-frostfs
[#63] scenarios: Unify logs in verify script
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
4c2678077b
commit
52ed0d6d88
1 changed files with 18 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import native from 'k6/x/frostfs/native';
|
||||
import registry from 'k6/x/frostfs/registry';
|
||||
import s3 from 'k6/x/frostfs/s3';
|
||||
import logging from 'k6/x/frostfs/logging';
|
||||
import { sleep } from 'k6';
|
||||
import { Counter } from 'k6/metrics';
|
||||
import { textSummary } from './libs/k6-summary-0.0.2.js';
|
||||
|
@ -25,11 +26,14 @@ const obj_counters = {
|
|||
invalid: new Counter('invalid_obj'),
|
||||
};
|
||||
|
||||
let log = logging.new();
|
||||
|
||||
// Connect to random gRPC endpoint
|
||||
let grpc_client = undefined;
|
||||
if (__ENV.GRPC_ENDPOINTS) {
|
||||
const grpcEndpoints = __ENV.GRPC_ENDPOINTS.split(',');
|
||||
const grpcEndpoint = 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);
|
||||
}
|
||||
|
||||
|
@ -38,6 +42,7 @@ let s3_client = undefined;
|
|||
if (__ENV.S3_ENDPOINTS) {
|
||||
const s3_endpoints = __ENV.S3_ENDPOINTS.split(',');
|
||||
const s3_endpoint = s3_endpoints[Math.floor(Math.random() * s3_endpoints.length)];
|
||||
log = log.withField("endpoint", s3_endpoint);
|
||||
s3_client = s3.connect(`http://${s3_endpoint}`);
|
||||
}
|
||||
|
||||
|
@ -99,7 +104,7 @@ export function obj_verify() {
|
|||
|
||||
const obj = obj_to_verify_selector.nextObject();
|
||||
if (!obj) {
|
||||
console.log("All objects have been verified");
|
||||
log.info("All objects have been verified");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -111,12 +116,22 @@ export function obj_verify() {
|
|||
function verify_object_with_retries(obj, attempts) {
|
||||
for (let i = 0; i < attempts; i++) {
|
||||
let result;
|
||||
// Different name is required.
|
||||
// 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});
|
||||
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});
|
||||
result = s3_client.verifyHash(obj.s3_bucket, obj.s3_key, obj.payload_hash);
|
||||
} else {
|
||||
console.log(`Object id=${obj.id} cannot be verified with supported protocols`);
|
||||
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`);
|
||||
return "skipped";
|
||||
}
|
||||
|
||||
|
@ -127,7 +142,7 @@ function verify_object_with_retries(obj, attempts) {
|
|||
}
|
||||
|
||||
// Unless we explicitly saw that there was a hash mismatch, then we will retry after a delay
|
||||
console.log(`Verify error on ${obj.id}: ${result.error}. Object will be re-tried`);
|
||||
lg.error(`Verify error: ${result.error}. Object will be re-tried`);
|
||||
sleep(__ENV.SLEEP);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue