Skip to content

Commit

Permalink
Merge pull request #76 from AJun01/AJun01/fix-issue-71
Browse files Browse the repository at this point in the history
Anonymization in/out
  • Loading branch information
mariosk authored Aug 20, 2024
2 parents 306a494 + 7c854da commit cb3a427
Show file tree
Hide file tree
Showing 12 changed files with 4,453 additions and 5,892 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,27 @@ If you want to uninstall just unlink it like this:
npm unlink flexbench
```

# How to turn on Anonymization Feature

After you cloned your exmaple, set the anonymize mode into true to turn on anonymization for the HTTPS response:

```
trafficSimulator.setAnonymization(true);
```

If you want to use existing example file to copy and paste over, please go to example folder and find simple-request-anonymized.js

You can always test the anonymization feature by running simple-request-anonymized.js:

```
node simple-request-anonymized.js
```

Features
========
* Throttling
* Clustering
* Anonymizing
* Set delay between requests
* Random or consecutive generation of requests
* Statistics aggregation
Expand Down
12 changes: 0 additions & 12 deletions compose-dev.yaml

This file was deleted.

79 changes: 79 additions & 0 deletions example/simple-request-anonymized.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Scenario:
* Generate requests towards specific domain
**/
var trafficSimulator = require('flexbench');


function runTest() {
trafficSimulator.debugMode(true);
trafficSimulator.testDuration(5);//-1 for infinite run
trafficSimulator.workers(1);
trafficSimulator.clients(2)
trafficSimulator.throttleRequests_bps(50000);//-1 for no throttling
trafficSimulator.randomDelayBetweenRequests('0.5-1.1');

//Anonymized
trafficSimulator.setAnonymization(true);

trafficSimulator.setFunc('request', requestFunc);

trafficSimulator.start();

trafficSimulator.events.on('end', function (stats) {
//This function will run on exit/stop, when worker has received a message to offload his stats to his master
//Get from stats object all exposed metrics
console.log('Traffic Simulator Results');
console.log('-------------------------');

var cArr = Object.keys(stats.counters);

for (var i = 0; i < cArr.length; i++) {
var key = cArr[i];
console.log('counter %s: %s ', key, stats.counters[key]);
}
console.log("Exiting..");
process.exit();
})



//stop test after specific period or condition\
setTimeout(function () {
trafficSimulator.stop();
}, 20 * 1000);

}

/**
* Create your generate request function here
* */
var requestFunc = function () {
//GENERATE REQUEST FUNCTION
var headers = {
"my-dummy-header": '1'
};
var options = {};
options['host'] = 'www.example.com';
options['port'] = '80';
options['path'] = '/';
options['method'] = 'GET';
if (headers) {
options['headers'] = headers;
}
//you can use the provided request function from HTS, in order 'catch'/count all response codes in a stats object
var req = trafficSimulator.request(options, function (response) {
console.log("Response: %s", response.statusCode);
response.setEncoding('utf8');
response.on('data', function (chunk) {
console.log(chunk.length)
console.log('hi: ', chunk.toString());
});
});

req.on('error', function (err) {
console.log('error:' + err.message);
});
}

runTest();
Loading

0 comments on commit cb3a427

Please sign in to comment.