-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arnaud ALCABAS
committed
Jun 15, 2023
1 parent
79853ed
commit 559095e
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |