mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +00:00
Add echo server, make it randomly take 2 secs.
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 frontend.marker
|
||||
all: qotd.marker app.marker client.marker searchapp.marker shout.marker frontend.marker echo.marker
|
||||
|
||||
qotd/qotd: qotd/qotd.o
|
||||
gcc -o $@ $< $(CFLAGS)
|
||||
@@ -21,6 +21,7 @@ client.marker: client/*
|
||||
searchapp.marker: searchapp/* searchapp/searchapp
|
||||
shout.marker: shout/* shout/shout
|
||||
frontend.marker: frontend/*
|
||||
echo.marker: echo/*
|
||||
%.marker:
|
||||
docker build -t tomwilkie/$(<D) $(<D)/
|
||||
touch $@
|
||||
|
||||
@@ -37,6 +37,10 @@ def do_search():
|
||||
r = sessions.session.get(random.choice(searchapps))
|
||||
return r.text
|
||||
|
||||
def do_echo(text):
|
||||
r = requests.get("http://echo/", data=text)
|
||||
return r.text
|
||||
|
||||
def ignore_error(f):
|
||||
try:
|
||||
return str(f())
|
||||
@@ -47,7 +51,7 @@ def ignore_error(f):
|
||||
@app.route('/')
|
||||
def hello():
|
||||
qotd_msg = do_qotd()
|
||||
qotd_msg += do_qotd()
|
||||
qotd_msg = do_echo(qotd_msg)
|
||||
return qotd_msg
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
8
experimental/example/echo/Dockerfile
Normal file
8
experimental/example/echo/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM python:2.7
|
||||
MAINTAINER Weaveworks Inc <help@weave.works>
|
||||
WORKDIR /home/weave
|
||||
ADD requirements.txt /home/weave/
|
||||
RUN pip install -r /home/weave/requirements.txt
|
||||
ADD echo.py /home/weave/
|
||||
EXPOSE 5000
|
||||
ENTRYPOINT ["python", "/home/weave/echo.py"]
|
||||
27
experimental/example/echo/echo.py
Normal file
27
experimental/example/echo/echo.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import random
|
||||
import time
|
||||
import threading
|
||||
import logging
|
||||
|
||||
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from werkzeug.serving import WSGIRequestHandler
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
if random.random() > 0.6:
|
||||
time.sleep(2)
|
||||
else:
|
||||
time.sleep(0.5)
|
||||
return request.data
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO)
|
||||
WSGIRequestHandler.protocol_version = "HTTP/1.0"
|
||||
app.run(host="0.0.0.0", port=80, debug=True)
|
||||
2
experimental/example/echo/requirements.txt
Normal file
2
experimental/example/echo/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
flask
|
||||
|
||||
@@ -21,4 +21,4 @@ start_container() {
|
||||
|
||||
start_container 1 tomwilkie/qotd qotd
|
||||
start_container 1 tomwilkie/app app
|
||||
|
||||
start_container 1 tomwilkie/echo echo
|
||||
|
||||
Reference in New Issue
Block a user