Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
juanq4 committed Oct 8, 2024
1 parent f6ec734 commit 6cc58bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 46 deletions.
56 changes: 12 additions & 44 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const impl = {
* @returns {boolean} true if file exists, false otherwise
*/
fileExists: (filePath) => {
console.log("fileExists");
try {
return fs.lstatSync(filePath).isFile();
} catch (ex) {
Expand All @@ -70,7 +69,6 @@ const impl = {
* script.yml file if the prior two conditions do not hold.
*/
findScriptPath: (scriptPath) => {
console.log("findScriptPath");
if (scriptPath) {
if (impl.fileExists(scriptPath)) {
if (path.isAbsolute(scriptPath)) {
Expand Down Expand Up @@ -100,7 +98,6 @@ const impl = {
* @returns {Promise.<string>}
*/
getScriptText: (options) => {
console.log("getScriptText");
// Priority: `--si`, `--stdIn`, `-d`, `--data`, `-p`, `--path`, ./script.yml, $(npm root -g)/script.yml
if (options.si || options.stdIn) {
return stdin();
Expand All @@ -125,16 +122,12 @@ const impl = {
* @param input The input to attempt parsing
* @returns {*} The parsed artillery script
*/
parseScript: (input) => {
console.log("parseScript");
return yaml.safeLoad(input);
},
parseScript: (input) => yaml.safeLoad(input),

/**
* Replace the given input flag with the `-d` flag, providing the stringification of the given script as its value.
*/
replaceArgv: (script) => {
console.log("replaceArgv");
const flags = [
{ flag: "-si", bool: true },
{ flag: "--stdIn", bool: true },
Expand Down Expand Up @@ -165,7 +158,6 @@ const impl = {
* @returns {{allowance: number, required: number}}
*/
scriptConstraints: (script) => {
console.log("scriptConstraints");
const networkBuffer = 2; // seconds to allow for network transmission
const resultsBuffer = 3; // seconds to allow for processing overhead (validation, decision making, results calculation)
const settings = platformSettings.getSettings(script);
Expand Down Expand Up @@ -196,7 +188,6 @@ const impl = {
},

generateScriptDefaults: (options) => {
console.log("generateScriptDefaults");
const opts = options || {};
opts.endpoint = opts.endpoint || "http://aws.amazon.com";
opts.duration = opts.duration || 5;
Expand All @@ -213,7 +204,6 @@ const impl = {
* @return {string} The string containing a JSON object that comprises the default script.
*/
generateScript: (options) => {
console.log("generateScript");
// fallback to defaults
const opts = impl.generateScriptDefaults(options);
// extract and combine options into generated script
Expand Down Expand Up @@ -257,7 +247,6 @@ scenarios:
* @param service The service to validate for deployment preconditions
*/
validateServiceForDeployment: (service) => {
console.log("validateServiceForDeployment");
if (
service &&
service.functions &&
Expand Down Expand Up @@ -368,7 +357,6 @@ scenarios:
* @param cwd Function to get the current working directory path
*/
validateServiceForInvocation: (options, script, cwd = process.cwd) => {
console.log("validateServiceForInvocation");
let toss = false;
try {
const localService = require(path.join(cwd(), "package.json")); // eslint-disable-line global-require, import/no-dynamic-require
Expand Down Expand Up @@ -397,7 +385,6 @@ scenarios:
* Copy artillery lambda files to temp dir.
*/
populateArtilleryLambda: (tempPath) => {
console.log("populateArtilleryLambda");
console.log(tempPath);
const sourceArtilleryLambdaPath = path.join(__dirname, "lambda");
let anyFailedCopies = false;
Expand All @@ -424,15 +411,13 @@ scenarios:
* Install artillery lambda dependencies to temp dir.
*/
installArtilleryLambdaDependencies: (tempPath) => {
console.log("installArtilleryLambdaDependencies");
npm.install(tempPath);
},

/**
* Get the user's slsart info.
*/
readUserSAConfig: () => {
console.log("readUserSAConfig");
let infoJSON = null;

// Read user's existing SA config or provide the (empty) default
Expand All @@ -447,16 +432,13 @@ scenarios:
/**
* Save the user's slsart info.
*/
writeUserSAConfig: (config) => {
console.log("writeUserSAConfig");
return fs.writeFileSync(constants.UserConfigPath, JSON.stringify(config));
},
writeUserSAConfig: (config) =>
fs.writeFileSync(constants.UserConfigPath, JSON.stringify(config)),

/**
* Checks for each of the asset files in the target dir.
*/
allServerlessFilesExist: (targetPath) => {
console.log("allServerlessFilesExist");
let slsFilesMissing = false;

// Check for each of the necessary Artillery Lambda files.
Expand Down Expand Up @@ -489,7 +471,6 @@ scenarios:
* @return {boolean} True if the temp path exists and has valid Artillery Lambda.
*/
verifyTempArtilleryLambda: (tempPath) => {
console.log("verifyTempArtilleryLambda");
if (
tempPath && // The temp path is not null,
fs.existsSync(tempPath) && // it exists,
Expand All @@ -513,7 +494,6 @@ scenarios:
* @returns {Promise.string} - path to temp Artillery Lambda assets
*/
tempArtilleryLambda: () => {
console.log("tempArtilleryLambda");
const userConfig = impl.readUserSAConfig();

// Check for existing temp directory with Artillery Lambda already available.
Expand Down Expand Up @@ -560,7 +540,6 @@ scenarios:
* @returns {string} - path to service config
*/
findServicePath: () => {
console.log("findServicePath");
const cwd = process.cwd();
const localServerlessPath = path.join(cwd, "serverless.yml");

Expand All @@ -577,7 +556,6 @@ scenarios:
* contain CLI parameters to pass to SLS.
*/
serverlessRunner: (options) => {
console.log("serverlessRunner");
// pretend that SLS was called.
process.argv[1] = Serverless.dirname;
// proceed with using SLS
Expand Down Expand Up @@ -667,7 +645,6 @@ scenarios:
* use when you need the names of resources in the cloud
*/
serverlessLoader: () => {
console.log("serverlessRunner");
const serverless = new Serverless({
interactive: false,
servicePath: impl.findServicePath(),
Expand All @@ -694,28 +671,25 @@ module.exports = {
* @return {Promise} A promise that completes after the deployment of the function and reporting of that
* deployment.
*/
deploy: (options) => {
console.log("deploy");
return impl.serverlessLoader().then((serverless) => {
deploy: (options) =>
impl.serverlessLoader().then((serverless) => {
impl.validateServiceForDeployment(serverless.service);

console.log(`${os.EOL}\tDeploying function...${os.EOL}`);

return impl.serverlessRunner(options).then(() => {
console.log(`${os.EOL}\tDeploy complete.${os.EOL}`);
});
});
},
}),
/**
* Send a script to the remote function. Prefer a script identified by the `-s` or `--script` option over a
* `script.yml` file in the current working directory over the global `script.yml`.
* @param options The options given by the user. See the ~/bin/serverless-artillery implementation for details.
* @return {Promise} A promise that completes after the invocation of the function with the script given
* by the user (or a fallback option).
*/
invoke: (options) => {
console.log("invoke");
return impl
invoke: (options) =>
impl
.getScriptText(options)
.then(impl.parseScript)
.then((input) => {
Expand Down Expand Up @@ -769,14 +743,12 @@ module.exports = {

return result;
});
});
},
}),

/**
* Kill an invoked lambda that is actively executing.
*/
kill: (options) => {
console.log("kill");
let funcName;
const lambdaOptions = {};

Expand Down Expand Up @@ -864,7 +836,6 @@ module.exports = {
* completion.
*/
remove: (options) => {
console.log("remove");
console.log(`${os.EOL}\tRemoving function...${os.EOL}`);

return impl.serverlessRunner(options).then(() => {
Expand All @@ -878,7 +849,6 @@ module.exports = {
* @param options The user's supplied options.
*/
script: (options) => {
console.log("script");
const destPath = options.out || "script.yml";
if (impl.fileExists(destPath)) {
return BbPromise.reject(
Expand Down Expand Up @@ -916,9 +886,8 @@ module.exports = {
* create and deploy a custom function definition.
* @returns {Promise} A promise that completes after the generation of function assets for subequent deployment.
*/
configure: (options) => {
console.log("options");
return new BbPromise((resolve, reject) => {
configure: (options) =>
new BbPromise((resolve, reject) => {
const conflicts = [];
const cwd = process.cwd();
// identify conflicts
Expand Down Expand Up @@ -991,8 +960,7 @@ module.exports = {
}
console.log(completeMessage.join(""));
}
});
},
}),
};

// TODO remove before publishing?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ config:
scenarios:
- name: "Perform Q4 IDP Login http journey to console"
flow:
- log: "Area: Traffic hittin login page"
- log: "Area: JWKS Endpoint"
- get:
url: "oauth/jwks"
2 changes: 1 addition & 1 deletion load-test/test-traffic-hitting-login-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ config:
max: 10000 # fail if max response time exceeds 5000ms
maxErrorRate: 8 # fail if error rate exceeds 0%
phases:
- duration: 100 # 5 min
- duration: 300 # 5 min
arrivalRate: 4 # 4 users per second ~ 200 per minutecala: 4, 8, 12, 20
rampTo: 6 #range of users per second
name: "Q4 IDP Login Load Test 300-166->333-228179506-all"
Expand Down

0 comments on commit 6cc58bf

Please sign in to comment.