Add x-forwarded-for header in load-gen instead
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import os
|
||||
import random
|
||||
|
||||
from locust import HttpUser, task, between
|
||||
from random import choice
|
||||
from random import randint
|
||||
@@ -6,24 +8,39 @@ from random import randint
|
||||
class UserBehavior(HttpUser):
|
||||
wait_time = between(2, 10)
|
||||
|
||||
fake_ip_addresses = [
|
||||
# white house
|
||||
"156.33.241.5",
|
||||
# Hollywood
|
||||
"34.196.93.245",
|
||||
# Chicago
|
||||
"98.142.103.241",
|
||||
# Los Angeles
|
||||
"192.241.230.151"
|
||||
]
|
||||
|
||||
def on_start(self):
|
||||
""" on_start is called when a Locust start before any task is scheduled """
|
||||
print('Starting')
|
||||
|
||||
@task
|
||||
def login(self):
|
||||
fake_ip = random.choice(self.fake_ip_addresses)
|
||||
|
||||
credentials = {
|
||||
'name': 'user',
|
||||
'password': 'password'
|
||||
}
|
||||
res = self.client.post('/api/user/login', json=credentials)
|
||||
res = self.client.post('/api/user/login', json=credentials, headers={'x-forwarded-for': fake_ip})
|
||||
print('login {}'.format(res.status_code))
|
||||
|
||||
|
||||
@task
|
||||
def load(self):
|
||||
self.client.get('/')
|
||||
user = self.client.get('/api/user/uniqueid').json()
|
||||
fake_ip = random.choice(self.fake_ip_addresses)
|
||||
|
||||
self.client.get('/', headers={'x-forwarded-for': fake_ip})
|
||||
user = self.client.get('/api/user/uniqueid', headers={'x-forwarded-for': fake_ip}).json()
|
||||
uniqueid = user['uuid']
|
||||
print('User {}'.format(uniqueid))
|
||||
|
||||
@@ -39,28 +56,28 @@ class UserBehavior(HttpUser):
|
||||
|
||||
# vote for item
|
||||
if randint(1, 10) <= 3:
|
||||
self.client.put('/api/ratings/api/rate/{}/{}'.format(item['sku'], randint(1, 5)))
|
||||
self.client.put('/api/ratings/api/rate/{}/{}'.format(item['sku'], randint(1, 5)), headers={'x-forwarded-for': fake_ip})
|
||||
|
||||
self.client.get('/api/catalogue/product/{}'.format(item['sku']))
|
||||
self.client.get('/api/ratings/api/fetch/{}'.format(item['sku']))
|
||||
self.client.get('/api/cart/add/{}/{}/1'.format(uniqueid, item['sku']))
|
||||
self.client.get('/api/catalogue/product/{}'.format(item['sku']), headers={'x-forwarded-for': fake_ip})
|
||||
self.client.get('/api/ratings/api/fetch/{}'.format(item['sku']), headers={'x-forwarded-for': fake_ip})
|
||||
self.client.get('/api/cart/add/{}/{}/1'.format(uniqueid, item['sku']), headers={'x-forwarded-for': fake_ip})
|
||||
|
||||
cart = self.client.get('/api/cart/cart/{}'.format(uniqueid)).json()
|
||||
cart = self.client.get('/api/cart/cart/{}'.format(uniqueid), headers={'x-forwarded-for': fake_ip}).json()
|
||||
item = choice(cart['items'])
|
||||
self.client.get('/api/cart/update/{}/{}/2'.format(uniqueid, item['sku']))
|
||||
self.client.get('/api/cart/update/{}/{}/2'.format(uniqueid, item['sku']), headers={'x-forwarded-for': fake_ip})
|
||||
|
||||
# country codes
|
||||
code = choice(self.client.get('/api/shipping/codes').json())
|
||||
city = choice(self.client.get('/api/shipping/cities/{}'.format(code['code'])).json())
|
||||
code = choice(self.client.get('/api/shipping/codes', headers={'x-forwarded-for': fake_ip}).json())
|
||||
city = choice(self.client.get('/api/shipping/cities/{}'.format(code['code']), headers={'x-forwarded-for': fake_ip}).json())
|
||||
print('code {} city {}'.format(code, city))
|
||||
shipping = self.client.get('/api/shipping/calc/{}'.format(city['uuid'])).json()
|
||||
shipping = self.client.get('/api/shipping/calc/{}'.format(city['uuid']), headers={'x-forwarded-for': fake_ip}).json()
|
||||
shipping['location'] = '{} {}'.format(code['name'], city['name'])
|
||||
print('Shipping {}'.format(shipping))
|
||||
# POST
|
||||
cart = self.client.post('/api/shipping/confirm/{}'.format(uniqueid), json=shipping).json()
|
||||
cart = self.client.post('/api/shipping/confirm/{}'.format(uniqueid), json=shipping, headers={'x-forwarded-for': fake_ip}).json()
|
||||
print('Final cart {}'.format(cart))
|
||||
|
||||
order = self.client.post('/api/payment/pay/{}'.format(uniqueid), json=cart).json()
|
||||
order = self.client.post('/api/payment/pay/{}'.format(uniqueid), json=cart, headers={'x-forwarded-for': fake_ip}).json()
|
||||
print('Order {}'.format(order))
|
||||
|
||||
@task
|
||||
@@ -68,6 +85,6 @@ class UserBehavior(HttpUser):
|
||||
if os.environ.get('ERROR') == '1':
|
||||
print('Error request')
|
||||
cart = {'total': 0, 'tax': 0}
|
||||
self.client.post('/api/payment/pay/partner-57', json=cart)
|
||||
self.client.post('/api/payment/pay/partner-57', json=cart, headers={'x-forwarded-for': fake_ip})
|
||||
|
||||
|
||||
|
@@ -2,11 +2,6 @@ FROM nginx:1.19
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
RUN sed -i '1i load_module \"modules/ngx_http_js_module.so\";' /etc/nginx/nginx.conf && \
|
||||
sed -i '1i load_module \"modules/ngx_stream_js_module.so\";' /etc/nginx/nginx.conf
|
||||
|
||||
COPY instana_random_geo.js /opt/nginx_js/instana_random_geo.js
|
||||
|
||||
ENV CATALOGUE_HOST=catalogue \
|
||||
USER_HOST=user \
|
||||
CART_HOST=cart \
|
||||
|
@@ -54,32 +54,26 @@ server {
|
||||
#}
|
||||
|
||||
location /api/catalogue/ {
|
||||
proxy_set_header x-forwarded-for $fake_ip;
|
||||
proxy_pass http://${CATALOGUE_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/user/ {
|
||||
proxy_set_header x-forwarded-for $fake_ip;
|
||||
proxy_pass http://${USER_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/cart/ {
|
||||
proxy_set_header x-forwarded-for $fake_ip;
|
||||
proxy_pass http://${CART_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/shipping/ {
|
||||
proxy_set_header X-Forwarded-For $fake_ip;
|
||||
proxy_pass http://${SHIPPING_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/payment/ {
|
||||
proxy_set_header x-forwarded-for $fake_ip;
|
||||
proxy_pass http://${PAYMENT_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/ratings/ {
|
||||
proxy_set_header x-forwarded-for $fake_ip;
|
||||
proxy_pass http://${RATINGS_HOST}:80/;
|
||||
}
|
||||
|
||||
|
@@ -1,23 +0,0 @@
|
||||
var items = [
|
||||
// white house
|
||||
"156.33.241.5",
|
||||
// Hollywood
|
||||
"34.196.93.245",
|
||||
// Chicago
|
||||
"98.142.103.241",
|
||||
// Los Angeles
|
||||
"192.241.230.151",
|
||||
// Europe
|
||||
"34.105.212.119"
|
||||
];
|
||||
|
||||
// we get a random ip address to simulate specific locations of the requester
|
||||
function get(r) {
|
||||
if (process.env.NGINX_INJECT_FAKE_IP != '1') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return items[Math.floor(Math.random() * items.length)];
|
||||
}
|
||||
|
||||
export default get;
|
Reference in New Issue
Block a user