diff --git a/test-app2/Dockerfile b/test-app2/Dockerfile new file mode 100644 index 0000000..32bc2d7 --- /dev/null +++ b/test-app2/Dockerfile @@ -0,0 +1,14 @@ +FROM python:alpine + +LABEL org.opencontainers.image.source=https://github.com/scaleway/scw-handson-k8s-optimize-1st-workload + +RUN pip install bottle paste requests + +COPY run.py /run.py + +ENV K8S_NS="docker" +ENV K8S_NODE="local" + +EXPOSE 80 9001 + +ENTRYPOINT ["/run.py"] diff --git a/test-app2/Makefile b/test-app2/Makefile new file mode 100644 index 0000000..0e729a0 --- /dev/null +++ b/test-app2/Makefile @@ -0,0 +1,2 @@ +build: + docker build . -t ghcr.io/scaleway/hands-on-metrics:latest diff --git a/test-app2/README.md b/test-app2/README.md new file mode 100644 index 0000000..be298a6 --- /dev/null +++ b/test-app2/README.md @@ -0,0 +1,6 @@ +test-app2 +========= + +Small app to generate load, display a configmap and secret content and expose a fake metric. + + diff --git a/test-app2/run.py b/test-app2/run.py new file mode 100755 index 0000000..b8d71ea --- /dev/null +++ b/test-app2/run.py @@ -0,0 +1,45 @@ +#!/usr/local/bin/python + +import bottle, socket, functools, os, random, math +from multiprocessing import Process + +print = functools.partial(print, flush=True) + +def base_app(): + base_app = bottle.Bottle() + + @base_app.route("/") + def root(): + base = f"""Hello! My name is {socket.gethostname()}

+Here is the value of ENV_CONFIG {os.getenv('ENV_CONFIG',default='undefined')}
+Here is the value of ENV_SECRET {os.getenv('ENV_SECRET',default='undefined')}""" + + # generate load, based on registry.k8s.io/hpa-example but in python instead of php + x = 0.0001 + for i in range(1000000): + x += math.sqrt(x) + + return base + + base_app.run(host="0.0.0.0", port=80, server="paste") + +def metrics_app(): + metrics_app = bottle.Bottle() + + @metrics_app.route("/") + def root(): + metrics = f"""# HELP myapp_test_metric Random number between 0 and 100 +# TYPE myapp_test_metric gauge +myapp_test_metric {random.randint(0, 100)}.0""" + return metrics + + metrics_app.run(host="0.0.0.0", port=9001, server="paste") + +if __name__ == "__main__": + ps = [] + for f in [base_app, metrics_app]: + ps.append(Process(target=f)) + for p in ps: + p.start() + for p in ps: + p.join()