From 3cb52e488e2b33a043df708103af53b925384e95 Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Ansaldo Date: Fri, 17 Nov 2023 11:07:11 +0100 Subject: [PATCH 1/7] Added playwright on load generator docker image --- src/loadgenerator/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/loadgenerator/Dockerfile b/src/loadgenerator/Dockerfile index bf9026d428..d0b2b75e95 100644 --- a/src/loadgenerator/Dockerfile +++ b/src/loadgenerator/Dockerfile @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -FROM python:3.11-slim-buster as base +FROM python:3.11-slim-bullseye as base FROM base as builder RUN apt-get -qq update \ @@ -17,4 +17,6 @@ WORKDIR /usr/src/app/ COPY --from=builder /reqs /usr/local COPY ./src/loadgenerator/locustfile.py . COPY ./src/loadgenerator/people.json . +ENV LOCUST_PLAYWRIGHT=1 +RUN playwright install --with-deps chromium ENTRYPOINT locust From 3b8f621536f67c2aadcd542bffd19741f5887e65 Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Ansaldo Date: Fri, 17 Nov 2023 11:07:36 +0100 Subject: [PATCH 2/7] Added locust plugins as a dependency --- src/loadgenerator/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/loadgenerator/requirements.txt b/src/loadgenerator/requirements.txt index 0b31606874..a5cac33199 100644 --- a/src/loadgenerator/requirements.txt +++ b/src/loadgenerator/requirements.txt @@ -16,6 +16,7 @@ idna==3.4 itsdangerous==2.1.2 jinja2==3.1.2 locust==2.18.1 +locust_plugins==3.4.0 markupsafe==2.1.3 msgpack==1.0.7 opentelemetry-api==1.20.0 From eaa699a43d4dd29c3e072a466cecdd57a04751aa Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Ansaldo Date: Fri, 17 Nov 2023 11:09:33 +0100 Subject: [PATCH 3/7] Increased memory constrains and introduced LOCUST_BROWSER_TRAFFIC_ENABLED environment variable --- .env | 1 + docker-compose.yml | 3 ++- kubernetes/opentelemetry-demo.yaml | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 74ae9122e9..7722d701b1 100644 --- a/.env +++ b/.env @@ -67,6 +67,7 @@ LOCUST_HOST=http://${FRONTEND_PROXY_ADDR} LOCUST_WEB_HOST=loadgenerator LOCUST_AUTOSTART=true LOCUST_HEADLESS=false +LOCUST_BROWSER_TRAFFIC_ENABLED=false # Payment Service PAYMENT_SERVICE_PORT=50051 diff --git a/docker-compose.yml b/docker-compose.yml index 084852716e..d224dad9a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -369,7 +369,7 @@ services: deploy: resources: limits: - memory: 120M + memory: 1G restart: unless-stopped ports: - "${LOCUST_WEB_PORT}" @@ -379,6 +379,7 @@ services: - LOCUST_HOST - LOCUST_HEADLESS - LOCUST_AUTOSTART + - LOCUST_BROWSER_TRAFFIC_ENABLED - OTEL_EXPORTER_OTLP_ENDPOINT - OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE - OTEL_RESOURCE_ATTRIBUTES diff --git a/kubernetes/opentelemetry-demo.yaml b/kubernetes/opentelemetry-demo.yaml index dcc93781c5..130594cf2c 100644 --- a/kubernetes/opentelemetry-demo.yaml +++ b/kubernetes/opentelemetry-demo.yaml @@ -9818,6 +9818,8 @@ spec: value: "false" - name: LOCUST_AUTOSTART value: "true" + - name: LOCUST_BROWSER_TRAFFIC_ENABLED + value: "false" - name: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION value: python - name: OTEL_EXPORTER_OTLP_ENDPOINT @@ -9826,7 +9828,7 @@ spec: value: service.name=$(OTEL_SERVICE_NAME),service.namespace=opentelemetry-demo resources: limits: - memory: 120Mi + memory: 1Gi --- # Source: opentelemetry-demo/templates/component.yaml apiVersion: apps/v1 From 7e78c5b98d488fe7ffbf04289937c40f64727474 Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Ansaldo Date: Fri, 17 Nov 2023 11:10:31 +0100 Subject: [PATCH 4/7] Added playwright user to generate browser traffic --- src/loadgenerator/locustfile.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index ea40f0614d..42f4c7312a 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -5,9 +5,11 @@ import json +import os import random import uuid from locust import HttpUser, task, between +from locust_plugins.users.playwright import PlaywrightUser, pw, PageWithRetry, event from opentelemetry import context, baggage, trace from opentelemetry.metrics import set_meter_provider @@ -129,3 +131,33 @@ def on_start(self): ctx = baggage.set_baggage("synthetic_request", "true") context.attach(ctx) self.index() + + +browser_traffic_enabled = os.environ.get('LOCUST_BROWSER_TRAFFIC_ENABLED', False) + +if browser_traffic_enabled: + class WebsiteBrowserUser(PlaywrightUser): + headless = True # to use a headless browser, without a GUI + multiplier = 1 # run concurrent playwright sessions/browsers for each Locust user + wait_time = between(1, 10) + + @task + @pw + async def open_cart_browser_page(self, page: PageWithRetry): + try: + async with event(self, "Load up Cart Page"): + await page.goto("/cart") + except: + pass + + @task + @pw + async def open_home_browser_page(self, page: PageWithRetry): + try: + async with event(self, "Load up Astronomy Shop home page"): + await page.goto("/") + async with event(self, "Click on a button"): + async with page.expect_navigation(wait_until="domcontentloaded"): + await page.click('button:has-text("Go Shopping")') + except: + pass \ No newline at end of file From 4e671a64de1992db34895a69cbcdbfd4627e3dc1 Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Ansaldo Date: Fri, 17 Nov 2023 11:11:07 +0100 Subject: [PATCH 5/7] Updated changelog message --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee4b2868e..d9c28ba6d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ release. ([#1239](https://github.com/open-telemetry/opentelemetry-demo/pull/1239)) * update PHP quoteservice to use 1.0.0 ([#1236](https://github.com/open-telemetry/opentelemetry-demo/pull/1236)) +* enable browser traffic in loadgenerator using playwright ([#1266](https://github.com/open-telemetry/opentelemetry-demo/pull/1266)) ## 1.6.0 From 45e0a4ef80d0ee9149d4812420e8a41837396097 Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Date: Fri, 17 Nov 2023 16:32:36 +0100 Subject: [PATCH 6/7] Added skipping line + renamed event --- src/loadgenerator/locustfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 42f4c7312a..c5aac08b2b 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -156,8 +156,9 @@ async def open_home_browser_page(self, page: PageWithRetry): try: async with event(self, "Load up Astronomy Shop home page"): await page.goto("/") - async with event(self, "Click on a button"): + async with event(self, "Click on Go Shopping button"): async with page.expect_navigation(wait_until="domcontentloaded"): await page.click('button:has-text("Go Shopping")') except: - pass \ No newline at end of file + pass + From 2988f77dc46d4f98f52c376681d2311669fe7190 Mon Sep 17 00:00:00 2001 From: Jordi Bisbal Date: Tue, 21 Nov 2023 11:27:39 +0100 Subject: [PATCH 7/7] Downgraded greenlet to 3.0.0 --- src/loadgenerator/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loadgenerator/requirements.txt b/src/loadgenerator/requirements.txt index a5cac33199..5597f3b13b 100644 --- a/src/loadgenerator/requirements.txt +++ b/src/loadgenerator/requirements.txt @@ -11,7 +11,7 @@ flask-cors==4.0.0 gevent==23.9.1 geventhttpclient==2.0.11 googleapis-common-protos==1.61.0 -greenlet==3.0.1 +greenlet==3.0.0 idna==3.4 itsdangerous==2.1.2 jinja2==3.1.2