Skip to content
bossfight
.dev
roadmap
problems
rounds
bosses
guides
patterns
quiz
mock
progress
sign in
Search
Ctrl K
~/rounds
Metrics pipeline
medium
60 min
Python
Stripe Bug Squash-style
Google code comprehension-style
1
The same minute, three rows
2
Build a feature
3
Make it fast
repo
metrics/
__init__.py
aggregate.py
buckets.py
cli.py
endpoints.py
export.py
parse.py
pipeline.py
tests/
visible/
test_pipeline.py
logs.py
README.md
README.md
read-only
# metrics Turns our API servers' access logs into per-minute metrics for the dashboard. A log line looks like this: 2026-09-14T21:59:58.120+02:00 web-3 GET /api/orders/88?full=1 200 123ms timestamp (ISO 8601 with its UTC offset; no offset means UTC), host, method, path, HTTP status, latency. Servers log in their own local time: the Frankfurt hosts use `+02:00`, the Virginia ones `-04:00`, some use `Z`. The log collector merges every host into one file **in time order**. metrics/parse.py parse_line(): one line -> Event, or None for junk metrics/endpoints.py endpoint_for(): /api/orders/88?full=1 -> /api/orders/:id metrics/buckets.py minute_of(): which UTC minute an event belongs to metrics/aggregate.py Stats per (minute, endpoint) metrics/export.py the CSV the dashboard loads metrics/pipeline.py run(lines, out): parse, aggregate, write CSV metrics/cli.py python -m metrics.cli access.log > metrics.csv The CSV has one row per UTC minute and endpoint, sorted by minute, then endpoint: minute,endpoint,count,errors,avg_ms,max_ms 2026-09-14T19:59Z,/api/orders/:id,412,3,87.4,1630 `errors` counts 5xx responses. Lines that don't parse are skipped and counted. Run the tests with `python -m pytest` (or press Run in the browser).
esc