Home > Back-end >  k6 parse user ids from S3 and execute 1 id per vu
k6 parse user ids from S3 and execute 1 id per vu

Time:10-12

I downloaded data from S3 via S3Client. Below is the data:

{“size”:188,“storageClass”:“STANDARD”,“data”:“fakeUserMF0000004\r\nfakeUserMF0000005\r\nfakeUserMF0000006\r\nfakeUserMF0000007\r\nfakeUserMF0000008\r\nfakeUserMF0000009\r\nfakeUserMF0000010\r\nfakeUserMF0000011\r\nfakeUserMF0000015\r\nfakeUserMF0000016”,“etag”:null,“key”:“3kMultiRep.csv”,“lastModified”:1665467135000}

Question: How do I parse those fakeUserMFxxxxxxx out of “data” key and then execute 1 per VU?

export function setup() {
// Download the S3 object containing the test data
const inputObject = s3.getObject(bucketName, testFileKey);
return JSON.stringify(iputObject.data);
}

export default function (data) {
console.log(data.split(/\r\n/));
}

Somehow, those fakeUserMFxxxxxx was not parsed out properly.. Any idea?

INFO[0001] ["\"fakeUserMF0000004\\r\\nfakeUserMF0000005\\r\\nfakeUserMF0000006\\r\\nfakeUserMF0000007\\r\\nfakeUserMF0000008\\r\\nfakeUserMF0000009\\r\\nfakeUserMF0000010\\r\\nfakeUserMF0000011\\r\\nfakeUserMF0000015\\r\\nfakeUserMF0000016\""]  source=console

CodePudding user response:

Why are you stringifying the string again? Just get rid of JSON.stringify. inputObject.data is already a string. Stringifying the string "abc\n" will give you "\"abc\\n\"" – you are double-encoding.

export function setup() {
  // Download the S3 object containing the test data
  const inputObject = s3.getObject(bucketName, testFileKey);
  return inputObject.data;
}
  • Related