Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added web browser traffic in loadgenerator #1266

Merged
merged 9 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ services:
deploy:
resources:
limits:
memory: 120M
memory: 1G
restart: unless-stopped
ports:
- "${LOCUST_WEB_PORT}"
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion kubernetes/opentelemetry-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/loadgenerator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
jordibisbal8 marked this conversation as resolved.
Show resolved Hide resolved

FROM base as builder
RUN apt-get -qq update \
Expand All @@ -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
32 changes: 32 additions & 0 deletions src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
jordibisbal8 marked this conversation as resolved.
Show resolved Hide resolved
async with page.expect_navigation(wait_until="domcontentloaded"):
await page.click('button:has-text("Go Shopping")')
except:
pass
jordibisbal8 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/loadgenerator/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading