Skip to content

Commit

Permalink
[loadgenerator] - rewrite for new frontend and feature flags (open-te…
Browse files Browse the repository at this point in the history
…lemetry#290)

* loadgenerator rewrite

* remove set_currency from load generator

* add multi item checkout
  • Loading branch information
puckpuck authored Aug 16, 2022
1 parent 1de1a7d commit 2c417c5
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 52 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ significant modifications will be credited to OpenTelemetry Authors.
([#273](https://github.com/open-telemetry/opentelemetry-demo/pull/273))
* Reimplemented Frontend app using [Next.js](https://nextjs.org/) Browser client
([#236](https://github.com/open-telemetry/opentelemetry-demo/pull/236))
* Remove set_currency from load generator
([#290](https://github.com/open-telemetry/opentelemetry-demo/pull/290))
* Added Frontend [Cypress](https://www.cypress.io/) E2E tests
([#298](https://github.com/open-telemetry/opentelemetry-demo/pull/298))
263 changes: 211 additions & 52 deletions src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# limitations under the License.

import random
from locust import HttpUser, TaskSet, between
import uuid
from locust import HttpUser, task, between

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
Expand All @@ -33,64 +34,222 @@
URLLib3Instrumentor().instrument()

products = [
'0PUK6V6EV0',
'1YMWWN1N4O',
'2ZYFJ3GM2N',
'66VCHSJNUP',
'6E92ZMYYFZ',
'9SIQT8TOJO',
'L9ECAV7KIM',
'LS4PSXUNUM',
'OLJCESPC7Z']
"0PUK6V6EV0",
"1YMWWN1N4O",
"2ZYFJ3GM2N",
"66VCHSJNUP",
"6E92ZMYYFZ",
"9SIQT8TOJO",
"L9ECAV7KIM",
"LS4PSXUNUM",
"OLJCESPC7Z"
]

def index(l):
l.client.get("/")
people = [
{
"email": "larry_sergei@example.com",
"address": {
"streetAddress": "1600 Amphitheatre Parkway",
"zipCode": 94043,
"city": "Mountain View",
"state": "CA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4432-8015-6152-0454",
"creditCardExpirationMonth": 1,
"creditCardExpirationYear": 2039,
"creditCardCvv": 672
}
},
{
"email": "bill@example.com",
"address": {
"streetAddress": "One Microsoft Way",
"zipCode": 98052,
"city": "Redmond",
"state": "WA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4532-4211-7434-1278",
"creditCardExpirationMonth": 2,
"creditCardExpirationYear": 2039,
"creditCardCvv": 114
}
},
{
"email": "steve@example.com",
"address": {
"streetAddress": "One Apple Park Way",
"zipCode": 95014,
"city": "Cupertino",
"state": "CA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4532-6178-2799-1951",
"creditCardExpirationMonth": 3,
"creditCardExpirationYear": 2039,
"creditCardCvv": 239
}
},
{
"email": "mark@example.com",
"address": {
"streetAddress": "1 Hacker Way",
"zipCode": 94025,
"city": "Menlo Park",
"state": "CA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4539-1103-5661-7083",
"creditCardExpirationMonth": 4,
"creditCardExpirationYear": 2039,
"creditCardCvv": 784
}
},
{
"email": "jeff@example.com",
"address": {
"streetAddress": "410 Terry Ave N",
"zipCode": 98109,
"city": "Seattle",
"state": "WA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4916-0816-6217-7968",
"creditCardExpirationMonth": 5,
"creditCardExpirationYear": 2039,
"creditCardCvv": 397
}
},
{
"email": "reed@example.com",
"address": {
"streetAddress": "100 Winchester Circle",
"zipCode": 95032,
"city": "Los Gatos",
"state": "CA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4929-5431-0337-5647",
"creditCardExpirationMonth": 6,
"creditCardExpirationYear": 2039,
"creditCardCvv": 793
}
},
{
"email": "tobias@example.com",
"address": {
"streetAddress": "150 Elgin St",
"zipCode": 214,
"city": "Ottawa",
"state": "ON",
"country": "Canada"
},
"userCurrency": "CAD",
"creditCard": {
"creditCardNumber": "4763-1844-9699-8031",
"creditCardExpirationMonth": 7,
"creditCardExpirationYear": 2039,
"creditCardCvv": 488
}
},
{
"email": "jack@example.com",
"address": {
"streetAddress": "1355 Market St",
"zipCode": 94103,
"city": "San Francisco",
"state": "CA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4929-6495-8333-3657",
"creditCardExpirationMonth": 8,
"creditCardExpirationYear": 2039,
"creditCardCvv": 159
}
},
{
"email": "moore@example.com",
"address": {
"streetAddress": "2200 Mission College Blvd",
"zipCode": 95054,
"city": "Santa Clara",
"state": "CA",
"country": "United States"
},
"userCurrency": "USD",
"creditCard": {
"creditCardNumber": "4485-4803-8707-3547",
"creditCardExpirationMonth": 9,
"creditCardExpirationYear": 2039,
"creditCardCvv": 682
}
}
]

def setCurrency(l):
currencies = ['EUR', 'USD', 'JPY', 'CAD']
l.client.post("/setCurrency",
{'currency_code': random.choice(currencies)})

def browseProduct(l):
l.client.get("/product/" + random.choice(products))
class WebsiteUser(HttpUser):
wait_time = between(1, 10)

def viewCart(l):
l.client.get("/cart")
@task(1)
def index(self):
self.client.get("/")

def addToCart(l):
product = random.choice(products)
l.client.get("/product/" + product)
l.client.post("/cart", {
'product_id': product,
'quantity': random.choice([1,2,3,4,5,10])})
@task(10)
def browse_product(self):
self.client.get("/product/" + random.choice(products))

def checkout(l):
addToCart(l)
l.client.post("/cart/checkout", {
'email': 'someone@example.com',
'street_address': '1600 Amphitheatre Parkway',
'zip_code': '94043',
'city': 'Mountain View',
'state': 'CA',
'country': 'United States',
'credit_card_number': '4432-8015-6152-0454',
'credit_card_expiration_month': '1',
'credit_card_expiration_year': '2039',
'credit_card_cvv': '672',
})
@task(3)
def view_cart(self):
self.client.get("/cart")

class UserBehavior(TaskSet):
@task(2)
def add_to_cart(self, user=""):
if user == "":
user = str(uuid.uuid1())
product = random.choice(products)
self.client.get("/product/" + product)
cart_item = {
"item": {
"productId": product,
"quantity": random.choice([1, 2, 3, 4, 5, 10])
},
"userId": user
}
self.client.post("/api/cart", json=cart_item)

def on_start(self):
index(self)
@task(1)
def checkout(self):
# checkout call with an item added to cart
user = str(uuid.uuid1())
self.add_to_cart(user=user)
checkout_person = random.choice(people)
checkout_person["userId"] = user
self.client.post("/api/checkout", json=checkout_person)

tasks = {index: 1,
setCurrency: 2,
browseProduct: 10,
addToCart: 2,
viewCart: 3,
checkout: 1}
@task(1)
def checkout_multi(self):
# checkout call which adds 2-4 different items to cart before checkout
user = str(uuid.uuid1())
for i in range(random.choice([2, 3, 4])):
self.add_to_cart(user=user)
checkout_person = random.choice(people)
checkout_person["userId"] = user
self.client.post("/api/checkout", json=checkout_person)

class WebsiteUser(HttpUser):
tasks = [UserBehavior]
wait_time = between(1, 10)
def on_start(self):
self.index()

0 comments on commit 2c417c5

Please sign in to comment.