Skip to content

Commit

Permalink
Update to artillery-load-test.yml and tests/artillery
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Nov 8, 2024
1 parent eceda54 commit 7a8ee66
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 62 deletions.
68 changes: 34 additions & 34 deletions frontend/artillery-load-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
config:
target: "http://127.0.0.1:3000"
tls:
rejectUnauthorized: false
http:
Expand All @@ -20,8 +21,17 @@ config:
local:
target: http://localhost:3000
phases:
- arrivalCount: 10
duration: 30
- duration: 2
arrivalRate: 5
name: Warm up phase
- duration: 1
arrivalRate: 1
maxVusers: 1
name: Ramp up load
- duration: 1
arrivalRate: 1
maxVusers: 1
name: Spike phase
prod:
target: https://simpler.grants.gov
staging:
Expand All @@ -34,38 +44,28 @@ config:
ensure: {}
apdex: {}
metrics-by-endpoint: {}
apdex:
threshold: 100
payload:
- path: "tests/artillery/{{ $environment}}-opportunities.csv"
fields:
- opp_id
skipHeader: true
name: opps
- path: "tests/artillery/{{ $environment}}-search.csv"
fields:
- query
- page
- status
- agency
skipHeader: true
name: opps
processor: "./tests/artillery/processor.ts"

before:
flow:
- function: loadData

scenarios:
- name: opportunities
- name: Opportunity Pages
beforeScenario: getOppId
flow:
- loop:
- get:
url: "/opportunity/{{ opp_id }}"
- think: 1
count: 10
over: opps
log: "/opportunity/{{ opp_id }}"
- name: search
- get:
url: "/opportunity/{{ id }}"
- log: "GET /opportunity/{{ id }}"
- name: 404 Pages
beforeScenario: get404
flow:
- loop:
- get:
url: "/search?query={{ query }}&page={{ page }}&status={{ status }}"
- think: 1
count: 10
over: opps
log: "/opportunity/{{ opp_id }}"
- get:
url: "/{{ route }}"
- log: "GET /{{ route }}"
- name: Searches
beforeScenario: getSearchQuery
flow:
- get:
url: "/search?{{ query }}"
- log: "GET /search?{{ query }}"
19 changes: 0 additions & 19 deletions frontend/tests/artillery/local-artillery-pages.yml

This file was deleted.

163 changes: 163 additions & 0 deletions frontend/tests/artillery/local-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"ids": [
311899, 311889, 311891, 45602, 45603, 45604, 45605, 45662, 311492, 311512,
311498
],
"queries": [
"test",
"grants",
"education",
"transportation",
"trauma",
"veterans"
],
"status": ["posted", "forecasted", "closed", "archived", "none"],
"agencies": [
"ARPAH",
"USAID",
"USAID-AFG",
"USAID",
"USAID-ARM",
"USAID-AZE",
"USAID-BAN",
"USAID-BEN",
"AC",
"DC",
"USDA",
"USDA-AMS",
"USDA-FNS1",
"DOC",
"DOC-DOCNOAAERA",
"DOC-EDA",
"DOC-NIST",
"DOD",
"DOD-AMC-ACCAPGN",
"DOD-AMC-ACCAPGD",
"DOD-AFRL-AFRLDET8",
"DOD-AFRL",
"DOD-USAFA",
"DOD-AFOSR",
"DOD-DARPA-BTO",
"ED",
"DOE",
"DOE-ARPAE",
"DOE-GFO",
"DOE-01",
"PAMS",
"PAMS-SC",
"HHS",
"HHS-ACF-FYSB",
"HHS-ACF",
"HHS-ACF-CB",
"DHS",
"DHS-DHS",
"DHS-OPO",
"DHS-USCG",
"HUD",
"USDOJ",
"USDOJ-OJP-BJA",
"USDOJ-OJP-COPS",
"DOL",
"DOL-ETA-ILAB",
"DOL-ETA-CEO",
"DOS",
"DOS-NEA-AC",
"DOS-DRL",
"DOS-ECA",
"DOI",
"DOI-BIA",
"DOI-BLM",
"DOI-BOR",
"USDOT",
"USDOT-ORP",
"USDOT-DO-SIPPRA",
"USDOT-GCR",
"DOT",
"DOT-DOT X-50",
"DOT-RITA",
"DOT-FAA-FAA ARG",
"DOT-FRA",
"DOT-FHWA",
"DOT-FTA",
"DOT-FAA-FAA COE-AJFE",
"DOT-FAA-FAA COE-FAA JAMS",
"DOT-FAA-FAA COE-TTHP",
"DOT-MA",
"DOT-NHTSA",
"VA",
"VA-CSHF",
"VA-HPGPDP",
"VA-LSV",
"VA-NVSP",
"VA-NCAC",
"VA-OMHSP",
"VA-SSVF",
"VA-NCA",
"VA-VLGP",
"EPA",
"IMLS",
"MCC",
"NASA",
"NASA-HQ",
"NASA-JSC",
"NASA-SFC",
"NASA",
"NARA",
"NEA",
"NEH",
"NSF",
"SSA"
],
"eligibility": [
"state_governments",
"county_governments",
"city_or_township_governments",
"special_district_governments",
"independent_school_districts",
"public_and_state_institutions_of_higher_education",
"private_institutions_of_higher_education",
"federally_recognized_native_american_tribal_governments",
"other_native_american_tribal_organizations",
"public_and_indian_housing_authorities",
"nonprofits_non_higher_education_with_501c3",
"nonprofits_non_higher_education_without_501c3",
"for_profit_organizations_other_than_small_businesses",
"small_businesses",
"other",
"unrestricted"
],
"funding": [
"cooperative_agreement",
"grant",
"procurement_contract",
"other"
],
"category": [
"recovery_act",
"agriculture",
"arts",
"business_and_commerce",
"community_development",
"consumer_protection",
"disaster_prevention_and_relief",
"education",
"employment_labor_and_training",
"energy",
"environment",
"food_and_nutrition",
"health",
"housing",
"humanities",
"information_and_statistics",
"infrastructure_investment_and_jobs_act",
"income_security_and_social_services",
"law_justice_and_legal_services",
"natural_resources",
"opportunity_zone_benefits",
"regional_development",
"science_technology_and_other_research_and_development",
"transportation",
"affordable_care_act",
"other"
]
}
4 changes: 0 additions & 4 deletions frontend/tests/artillery/local-opportunities.csv

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/tests/artillery/local-search.csv

This file was deleted.

93 changes: 90 additions & 3 deletions frontend/tests/artillery/processor.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,103 @@
import { readFile } from "fs/promises";
import { random } from "lodash";

type dataType = {
ids: Array<number>;
queries: Array<string>;
status: Array<string>;
agencies: Array<string>;
eligibility: Array<string>;
category: Array<string>;
$environment?: string;
};

type queryType = {
query: string;
};

// eslint-disable-next-line @typescript-eslint/require-await
async function getOppId(context: { vars: { id: number; ids: Array<number> } }) {
context.vars.id = context.vars.ids[random(context.vars.ids.length - 1)];
}

// eslint-disable-next-line @typescript-eslint/require-await
async function loadOppIds(context: { vars: { ids: Array<number> } }) {
context.vars.ids = [1, 2, 3, 4, 5];
async function get404(context: { vars: { route: string } }) {
const num = random(100);
// ~50% of 404s are opp pages.
if (num % 2 !== 0) {
context.vars.route = `opportunity/${num}`;
} else {
context.vars.route = randomString(num);
}
}

// eslint-disable-next-line @typescript-eslint/require-await
async function getSearchQuery(context: { vars: queryType & dataType }) {
const { queries, status, agencies, eligibility, category } = context.vars;
const qu = `query=${queries[random(queries.length - 1)]}`;
const st = `status=${status[random(status.length - 1)]}`;
const ag = `agency=${agencies[random(agencies.length - 1)]}`;
const cat = `category=${category[random(category.length - 1)]}`;
const el = `eligibility=${eligibility[random(eligibility.length - 1)]}`;
const pager = `page=${random(5)}`;
// Most search params only include the queries, but smaller percent include
// filters. This allows configuring that percent for composing the query.
const weights = [
{
percent: 50,
params: [qu, st, pager],
},
{
percent: 20,
params: [qu, st, ag],
},
{
percent: 20,
params: [qu, st, ag, cat],
},
{
percent: 10,
params: [qu, st, ag, cat, el],
},
];
const hundred = random(100);
let total = 0;
const selected = weights.find((item) => {
total += item.percent;
if (hundred <= total) {
return true;
}
return false;
});
context.vars.query = selected?.params.join("&") as string;
}

async function loadData(context: { vars: dataType }) {
const env = context.vars.$environment;
const envs = new Set(["local", "dev", "stage", "prod"]);
if (!env || !envs.has(env)) {
throw new Error(`env ${env ?? ""} does not exist in env list`);
}
// TODO: add more env data files.
const path = "./tests/artillery/local-data.json";
const file = await readFile(path, "utf8");
context.vars = JSON.parse(file) as dataType;
}

function randomString(length: number) {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = " ";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(random(charactersLength)));
}
return result;
}

module.exports = {
loadData,
getOppId,
loadOppIds,
get404,
getSearchQuery,
};

0 comments on commit 7a8ee66

Please sign in to comment.