mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Update example app to include a loadbalancer.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
CC=gcc
|
||||
CFLAGS=-g -lpthread
|
||||
|
||||
all: qotd.marker app.marker client.marker searchapp.marker shout.marker
|
||||
all: qotd.marker app.marker client.marker searchapp.marker shout.marker frontend.marker
|
||||
|
||||
qotd/qotd: qotd/qotd.o
|
||||
gcc -o $@ $< $(CFLAGS)
|
||||
@@ -20,6 +20,7 @@ app.marker: app/*
|
||||
client.marker: client/*
|
||||
searchapp.marker: searchapp/* searchapp/searchapp
|
||||
shout.marker: shout/* shout/shout
|
||||
frontend.marker: frontend/*
|
||||
%.marker:
|
||||
docker build -t tomwilkie/$(<D) $(<D)/
|
||||
touch $@
|
||||
|
||||
@@ -10,9 +10,9 @@ make all
|
||||
# "architecture"
|
||||
|
||||
```
|
||||
curl -> app --> searchapp -> elasticsearch
|
||||
|
|
||||
--> qotd -> internet
|
||||
|
|
||||
--> redis
|
||||
curl -> frontend --> app --> searchapp -> elasticsearch
|
||||
(nginx) |
|
||||
--> qotd -> internet
|
||||
|
|
||||
--> redis
|
||||
```
|
||||
|
||||
@@ -57,4 +57,4 @@ def hello():
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO)
|
||||
WSGIRequestHandler.protocol_version = "HTTP/1.1"
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
app.run(host="0.0.0.0", port=80, debug=True)
|
||||
|
||||
@@ -3,21 +3,28 @@ import random
|
||||
import threading
|
||||
import time
|
||||
import logging
|
||||
import socket
|
||||
import sys
|
||||
|
||||
app = 'http://app:5000/'
|
||||
frontend = 'frontend'
|
||||
concurrency = 2
|
||||
|
||||
def do_request(s):
|
||||
addrs = socket.getaddrinfo(frontend, 80)
|
||||
if len(addrs) <= 0:
|
||||
return
|
||||
addr = random.choice(addrs)
|
||||
s.get("http://%s:%d" % addr[4], timeout=1.0)
|
||||
|
||||
def do_requests():
|
||||
s = requests.Session()
|
||||
while True:
|
||||
try:
|
||||
s.get(app, timeout=1.0)
|
||||
logging.info("Did request")
|
||||
time.sleep(1)
|
||||
do_request(s)
|
||||
except:
|
||||
logging.error("Error doing request", exc_info=sys.exc_info())
|
||||
time.sleep(1)
|
||||
|
||||
time.sleep(1)
|
||||
logging.info("Did request")
|
||||
|
||||
def main():
|
||||
|
||||
11
experimental/example/frontend/Dockerfile
Normal file
11
experimental/example/frontend/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM ubuntu
|
||||
MAINTAINER Weaveworks Inc <help@weave.works>
|
||||
RUN apt-get update && \
|
||||
apt-get install -y nginx && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
RUN rm /etc/nginx/sites-available/default && \
|
||||
ln -sf /dev/stdout /var/log/nginx/access.log && \
|
||||
ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
COPY default.conf /etc/nginx/conf.d/
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
8
experimental/example/frontend/default.conf
Normal file
8
experimental/example/frontend/default.conf
Normal file
@@ -0,0 +1,8 @@
|
||||
server {
|
||||
listen 80;
|
||||
resolver dns.weave.local:53;
|
||||
|
||||
location / {
|
||||
proxy_pass http://app.weave.local$request_uri;
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,27 @@
|
||||
|
||||
set -eux
|
||||
|
||||
REPLICAS=${REPLICAS:-1}
|
||||
eval $(weave env)
|
||||
|
||||
start_container() {
|
||||
IMAGE=$1
|
||||
BASENAME=${2:-$1}
|
||||
IMAGE=$2
|
||||
BASENAME=$3
|
||||
REPLICAS=$1
|
||||
shift 3
|
||||
HOSTNAME=$BASENAME.weave.local
|
||||
|
||||
for i in $(seq $REPLICAS); do
|
||||
if docker inspect $BASENAME$i >/dev/null 2>&1; then
|
||||
docker rm -f $BASENAME$i
|
||||
fi
|
||||
weave run --with-dns --name=$BASENAME$i --hostname=$HOSTNAME $IMAGE
|
||||
docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE
|
||||
done
|
||||
}
|
||||
|
||||
start_container elasticsearch
|
||||
start_container tomwilkie/searchapp searchapp
|
||||
start_container redis
|
||||
start_container tomwilkie/qotd qotd
|
||||
start_container tomwilkie/app app
|
||||
start_container tomwilkie/client client
|
||||
start_container 1 elasticsearch elasticsearch
|
||||
start_container 2 tomwilkie/searchapp searchapp
|
||||
start_container 1 redis redis
|
||||
start_container 1 tomwilkie/qotd qotd
|
||||
start_container 2 tomwilkie/app app
|
||||
start_container 2 tomwilkie/frontend frontend --add-host=dns.weave.local:$(weave docker-bridge-ip)
|
||||
start_container 1 tomwilkie/client client
|
||||
|
||||
Reference in New Issue
Block a user