From a7336b9dbb142e87d5d8fda91542f532ec828e23 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Wed, 10 Aug 2022 23:00:41 -0400 Subject: [PATCH 1/3] loadgenerator rewrite --- src/loadgenerator/locustfile.py | 254 +++++++++++++++++++++++++------- 1 file changed, 201 insertions(+), 53 deletions(-) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 58fb2d3b76..73ca7d24db 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -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 @@ -33,64 +34,211 @@ 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)) - -def viewCart(l): - l.client.get("/cart") +class WebsiteUser(HttpUser): + wait_time = between(1, 10) -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(1) + def index(self): + self.client.get("/") -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(10) + def browse_product(self): + self.client.get("/product/" + random.choice(products)) -class UserBehavior(TaskSet): + @task(3) + def view_cart(self): + self.client.get("/cart") - def on_start(self): - index(self) + @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) - tasks = {index: 1, - setCurrency: 2, - browseProduct: 10, - addToCart: 2, - viewCart: 3, - checkout: 1} + @task(1) + def checkout(self): + 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) -class WebsiteUser(HttpUser): - tasks = [UserBehavior] - wait_time = between(1, 10) + def on_start(self): + self.index() From 4687788cc319643528af925dc27c345eed9f9368 Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Wed, 10 Aug 2022 23:09:56 -0400 Subject: [PATCH 2/3] remove set_currency from load generator --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b61048b47..dc211fccfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,3 +65,5 @@ 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)) From 1a2f6b22bcc7fa71637be55f9f047936da3bc66e Mon Sep 17 00:00:00 2001 From: Pierre Tessier Date: Wed, 10 Aug 2022 23:35:26 -0400 Subject: [PATCH 3/3] add multi item checkout --- src/loadgenerator/locustfile.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 73ca7d24db..688ffe90a9 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -234,11 +234,22 @@ def add_to_cart(self, user=""): @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) + @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) + def on_start(self): self.index()