docs: README по требованиям к оформлению и демо-сервисы examples/ (#19)
CI / ruff · mypy · pytest (pull_request) Successful in 26m33s
CI / ruff · mypy · pytest (pull_request) Successful in 26m33s
- README: цели и задачи, что реализовано, развёртывание (локально за 5 минут и полный стек), переменные, команды и данные, используемые API, ограничения и лимиты, что не сделано, структура репозитория - examples/: hello (healthy + материал для grep/агента), crash (💥 и 🔁), cpu_hog (🔥), unhealthy (🩺), syntax_error/lint_fail для коммита, вопросы агенту и атаки; make demo-up / demo-down в том же Compose-проекте - make local-proxy: read-only Docker API для `make run` - ARCHITECTURE: краш при restart-политике и гистерезис алертов Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Healthy demo service: HTTP on :8000 with /health, and a log that has something to grep.
|
||||
|
||||
Every request is logged; every ~20 s a warning, every ~60 s a simulated DB error — material for «🔎 Свой grep»
|
||||
and «🤖 Спросить агента» («когда были ошибки подключения?»).
|
||||
"""
|
||||
|
||||
import itertools
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
||||
log = logging.getLogger("hello")
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self) -> None:
|
||||
body = b"ok\n" if self.path == "/health" else b"hello from tgit demo\n"
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, format: str, *args: object) -> None:
|
||||
log.info("%s %s", self.address_string(), format % args)
|
||||
|
||||
|
||||
def chatter() -> None:
|
||||
for tick in itertools.count(1):
|
||||
time.sleep(20)
|
||||
log.warning("slow request: /report took %d ms", 1200 + tick % 7 * 100)
|
||||
if tick % 3 == 0:
|
||||
log.error("connection refused: db:5432 (retry %d)", tick // 3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
threading.Thread(target=chatter, daemon=True).start()
|
||||
log.info("listening on :8000")
|
||||
ThreadingHTTPServer(("0.0.0.0", 8000), Handler).serve_forever()
|
||||
Reference in New Issue
Block a user