Skip to content

Commit

Permalink
Added test-app2
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud ALCABAS committed Jun 15, 2023
1 parent 79853ed commit 559095e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test-app2/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 2 additions & 0 deletions test-app2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
docker build . -t ghcr.io/scaleway/hands-on-metrics:latest
6 changes: 6 additions & 0 deletions test-app2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test-app2
=========

Small app to generate load, display a configmap and secret content and expose a fake metric.


45 changes: 45 additions & 0 deletions test-app2/run.py
Original file line number Diff line number Diff line change
@@ -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 <b>{socket.gethostname()}</b><br/><br/>
Here is the value of ENV_CONFIG <b>{os.getenv('ENV_CONFIG',default='undefined')}</b><br/>
Here is the value of ENV_SECRET <b>{os.getenv('ENV_SECRET',default='undefined')}</b>"""

# 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()

0 comments on commit 559095e

Please sign in to comment.