Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 0 additions & 1 deletion 1

This file was deleted.

35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.11.1-slim@sha256:1591aa8c01b5b37ab31dbe5662c5bdcf40c2f1bce4ef1c1fd24802dae3d01052 as base

FROM base as builder

COPY requirements.txt .

RUN pip install --prefix="/install" -r requirements.txt

FROM base

WORKDIR /loadgen

COPY --from=builder /install /usr/local

# Add application code.
COPY locustfile.py .

# enable gevent support in debugger
ENV GEVENT_SUPPORT=True

ENTRYPOINT locust --host="http://${FRONTEND_ADDR}" --headless -u "${USERS:-10}" 2>&1
25 changes: 25 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pipeline {
agent any

stages {
stage('Build & Tag Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker build -t abhishek0768/loadgenerator:latest ."
}
}
}
}

stage('Push Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker push abhishek0768/loadgenerator:latest"
}
}
}
}
}
}
81 changes: 81 additions & 0 deletions locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/python
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import random
from locust import HttpUser, TaskSet, between

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

def index(l):
l.client.get("/")

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")

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])})

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',
})

class UserBehavior(TaskSet):

def on_start(self):
index(self)

tasks = {index: 1,
setCurrency: 2,
browseProduct: 10,
addToCart: 2,
viewCart: 3,
checkout: 1}

class WebsiteUser(HttpUser):
tasks = [UserBehavior]
wait_time = between(1, 10)
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locust==2.15.1
78 changes: 78 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
#
blinker==1.6.2
# via flask
brotli==1.0.9
# via geventhttpclient
certifi==2022.12.7
# via
# geventhttpclient
# requests
charset-normalizer==3.1.0
# via requests
click==8.1.3
# via flask
configargparse==1.5.3
# via locust
flask==2.3.2
# via
# flask-basicauth
# flask-cors
# locust
flask-basicauth==0.2.0
# via locust
flask-cors==3.0.10
# via locust
gevent==22.10.2
# via
# geventhttpclient
# locust
geventhttpclient==2.0.9
# via locust
greenlet==2.0.2
# via gevent
idna==3.4
# via requests
itsdangerous==2.1.2
# via flask
jinja2==3.1.2
# via flask
locust==2.15.1
# via -r requirements.in
markupsafe==2.1.2
# via
# jinja2
# werkzeug
msgpack==1.0.5
# via locust
psutil==5.9.5
# via locust
pyzmq==25.0.2
# via locust
requests==2.30.0
# via locust
roundrobin==0.0.4
# via locust
six==1.16.0
# via
# flask-cors
# geventhttpclient
typing-extensions==4.5.0
# via locust
urllib3==1.26.15
# via requests
werkzeug==2.3.4
# via
# flask
# locust
zope-event==4.6
# via gevent
zope-interface==6.0
# via gevent

# The following packages are considered to be unsafe in a requirements file:
# setuptools