Skip to content

Commit 883b9ab

Browse files
style: make the demo app pass ruff
Docstrings, return annotations, a named ERROR_RATE constant, targeted S311 suppressions (randomness is jitter, not crypto), and an __init__.py so the demo dir isn't an implicit namespace package.
1 parent 99420a5 commit 883b9ab

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

demo/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Demo telemetry source for the monitoring stack (see compose.demo.yml)."""

demo/app.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
# Minimal FastAPI service for the demo overlay. All telemetry (traces,
2-
# metrics, logs with trace context) comes from OTel auto-instrumentation —
3-
# see compose.demo.yml. No OTel code needed here.
1+
"""Minimal FastAPI service for the demo overlay.
2+
3+
All telemetry (traces, metrics, logs with trace context) comes from OTel
4+
auto-instrumentation — see compose.demo.yml. No OTel code needed here.
5+
"""
6+
47
import logging
58
import random
69
import time
710

811
from fastapi import FastAPI, HTTPException
912

13+
ERROR_RATE = 0.1 # fixed error rate, enough to light up RED panels
14+
1015
logging.basicConfig(level=logging.INFO) # root logger defaults to WARNING; we want the INFO lines too
1116
log = logging.getLogger("demo-api")
1217
app = FastAPI()
1318

1419

1520
@app.get("/")
16-
def root():
21+
def root() -> dict[str, bool]:
22+
"""Fast, always-successful endpoint."""
1723
return {"ok": True}
1824

1925

2026
@app.get("/work")
21-
def work():
22-
time.sleep(random.uniform(0.02, 0.3))
23-
if random.random() < 0.1: # NOTE: fixed 10% error rate, enough to light up RED panels
27+
def work() -> dict[str, bool]:
28+
"""Simulate variable-latency work that sometimes fails."""
29+
time.sleep(random.uniform(0.02, 0.3)) # noqa: S311 — not crypto, just jitter
30+
if random.random() < ERROR_RATE: # noqa: S311
2431
log.error("work failed: upstream flaked")
2532
raise HTTPException(status_code=500, detail="upstream flaked")
2633
log.info("work done")

0 commit comments

Comments
 (0)