Merge pull request #44 from instana/geo

Showcase geo tags for calls derived from x-forwarded-for header. LGTM.
This commit is contained in:
steveww
2020-10-21 14:52:12 +01:00
committed by GitHub
5 changed files with 47 additions and 5 deletions

View File

@@ -107,8 +107,9 @@ services:
- "8080:8080"
networks:
- robot-shop
# Uncomment to enable Instana EUM
# environment:
#environment:
# NGINX_INJECT_FAKE_IP: "1"
# Uncomment to enable Instana EUM
# INSTANA_EUM_KEY: <your eum key>
# INSTANA_EUM_REPORTING_URL: https://eum-us-west-2.instana.io
# INSTANA_EUM_REPORTING_URL: https://eum-eu-west-1.instana.io

View File

@@ -1,7 +1,12 @@
FROM nginx:1.16
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 \
@@ -9,9 +14,9 @@ ENV CATALOGUE_HOST=catalogue \
PAYMENT_HOST=payment \
RATINGS_HOST=ratings
COPY njs.conf /etc/nginx/conf.d/njs.conf
COPY entrypoint.sh /root/
ENTRYPOINT ["/root/entrypoint.sh"]
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
COPY static /usr/share/nginx/html

View File

@@ -54,26 +54,32 @@ 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/;
}
@@ -82,4 +88,3 @@ server {
access_log off;
}
}

23
web/instana_random_geo.js Normal file
View File

@@ -0,0 +1,23 @@
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;

8
web/njs.conf Normal file
View File

@@ -0,0 +1,8 @@
# geo tags for calls derived from x-forwarded-for header
js_path /opt/nginx_js;
js_import instana_random_geo.js;
js_set $fake_ip instana_random_geo;