Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (188 loc) · 9.42 KB
/
Copy pathMakefile
File metadata and controls
238 lines (188 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
.PHONY: help install install-dev \
db-up db-down docker-up docker-down docker-demo docker-logs \
init migrate demo ingest explain clusters ask \
api web web-serve worker test test-unit test-int test-cov eval eval-data bench bench-gate bench-api bench-workers loghub lint format \
openapi jsonschema config-docs client-go client-python clean
PYTHON := python
PIP := pip
SAMPLE := sample_data/sample_incident
OPENAPI := clients/openapi.json
help:
@echo "raglogs — incident explanation tool"
@echo ""
@echo "Local dev (needs a running Postgres — use 'make db-up')"
@echo " make install Install production dependencies"
@echo " make install-dev Install all dependencies including dev"
@echo " make db-up Start only PostgreSQL via Docker Compose"
@echo " make db-down Stop PostgreSQL"
@echo " make init Run DB migrations"
@echo " make demo Full CLI demo: db-up + init + ingest + explain"
@echo " make ingest Ingest sample incident logs"
@echo " make explain Explain the last hour"
@echo " make clusters Show top clusters"
@echo " make api Start FastAPI server (reload)"
@echo " make web Seed a fresh sample incident (demo) + serve at http://localhost:8000/"
@echo " make web-serve db-up + migrate + serve — no reseed, for repeat runs"
@echo " make worker Start background worker"
@echo ""
@echo "Docker (full stack)"
@echo " make docker-up Build and start api + worker + postgres"
@echo " make docker-down Stop and remove containers"
@echo " make docker-logs Follow api and worker logs"
@echo " make docker-demo Run raglogs demo inside the api container"
@echo ""
@echo "Testing"
@echo " make test All tests"
@echo " make test-unit Unit tests only"
@echo " make test-int Integration tests (needs live DB)"
@echo " make test-cov Unit tests with coverage"
@echo " make lint Ruff lint"
@echo " make format Ruff format"
@echo " make openapi Export OpenAPI schema to clients/openapi.json"
@echo " make jsonschema Export /v1/query JSON Schemas to clients/jsonschema/"
@echo " make client-go Generate Go client (oapi-codegen; no-op if missing)"
@echo " make client-python Optional OpenAPI Python generator, or use src/clients/v1.py"
@echo " make clean Remove build artifacts"
# ── Setup ─────────────────────────────────────────────────────────────────────
install-dev:
$(PIP) install -e ".[dev]"
install:
$(PIP) install -e .
# ── Local dev ──────────────────────────────────────────────────────────────────
db-up:
docker compose up postgres -d
@echo "Waiting for PostgreSQL..."
@sleep 3
db-down:
docker compose down
init:
alembic upgrade head
migrate: init
demo: db-up
@sleep 2
alembic upgrade head
raglogs demo
raglogs timeline --since 2h
raglogs compare --since 30m --baseline 24h
ingest:
raglogs ingest $(SAMPLE)
explain:
raglogs explain --since 1h
clusters:
raglogs clusters --since 1h
ask:
raglogs ask "why did the webhook fail?" --since 1h
# ── Development servers ────────────────────────────────────────────────────────
# Bind host passed to uvicorn *and* read by the startup auth guard (API_BIND_HOST).
# 0.0.0.0 matches historical `make api` behaviour; with AUTH_ENABLED=false the
# process logs a warning. Loopback: `make api API_BIND_HOST=127.0.0.1`.
API_BIND_HOST ?= 0.0.0.0
api:
API_BIND_HOST=$(API_BIND_HOST) uvicorn src.api.app:app --host $(API_BIND_HOST) --port 8000 --reload
web: demo
@echo "Web UI: http://localhost:8000/ — open it in a browser"
API_BIND_HOST=$(API_BIND_HOST) uvicorn src.api.app:app --host $(API_BIND_HOST) --port 8000 --reload
web-serve: db-up
@sleep 2
alembic upgrade head
@echo "Web UI: http://localhost:8000/ — open it in a browser"
API_BIND_HOST=$(API_BIND_HOST) uvicorn src.api.app:app --host $(API_BIND_HOST) --port 8000 --reload
worker:
raglogs worker
# ── Docker full stack ──────────────────────────────────────────────────────────
docker-up:
docker compose up --build -d
@echo "API: http://localhost:8000"
@echo "Docs: http://localhost:8000/docs"
docker-down:
docker compose down -v
docker-logs:
docker compose logs -f api worker
docker-demo:
docker compose exec api raglogs demo
# ── Tests ──────────────────────────────────────────────────────────────────────
test:
pytest tests/ -v
test-unit:
pytest tests/unit/ -v
test-int:
INTEGRATION_TESTS=1 pytest tests/integration/ -v
test-cov:
pytest tests/unit/ --cov=src --cov-report=term-missing
# Ingest→explain performance benchmark (#85). Needs a live Postgres (DB_URL).
# Prints a cost-vs-N curve; commit the numbers, don't optimise blind.
bench: db-up
$(PYTHON) scripts/bench_pipeline.py --sizes $(or $(SIZES),10000,100000,500000,1000000)
# API concurrency / connection-pool load test (#85). Needs a live Postgres (DB_URL).
# Drives the real ASGI app at rising concurrency; reports throughput + latency percentiles.
bench-api: db-up
$(PYTHON) scripts/bench_api.py --lines $(or $(LINES),10000) \
--concurrency $(or $(CONCURRENCY),1,2,4,8,16,32,64) --requests $(or $(REQUESTS),120)
# Out-of-process multi-worker scaling (#85). Real `uvicorn --workers N` + real socket.
# Needs a live Postgres (DB_URL). Reports throughput per worker count.
bench-workers: db-up
$(PYTHON) scripts/bench_workers.py --lines $(or $(LINES),10000) \
--workers $(or $(WORKERS),1,2,4,8) --concurrency-per-worker 2 --requests $(or $(REQUESTS),300)
# ── Eval harness ──────────────────────────────────────────────────────────────
eval: db-up
@sleep 2
alembic upgrade head
raglogs eval
eval-data:
$(PYTHON) scripts/eval_data.py
# Loghub-2.0 normalization benchmark. Download the corpus first (see the script
# header) — it is research/academic-use only and never committed.
loghub:
$(PYTHON) scripts/loghub_bench.py
# CI performance gate (#85): a single-size ingest→explain run with a pass/fail target,
# mirroring .github/workflows/bench.yml (which invokes scripts/benchmark.py directly).
# The fuller cost-vs-N curve is `make bench` (scripts/bench_pipeline.py) above; this used
# to also be named `bench`, which silently shadowed it — hence the rename.
bench-gate: db-up
@sleep 2
alembic upgrade head
$(PYTHON) scripts/benchmark.py
# ── Quality ───────────────────────────────────────────────────────────────────
lint:
ruff check src/ tests/
format:
ruff format src/ tests/
# ── OpenAPI / clients ─────────────────────────────────────────────────────────
openapi:
PYTHONPATH=. $(PYTHON) scripts/export_openapi.py
jsonschema:
PYTHONPATH=. $(PYTHON) scripts/export_jsonschema.py
# Regenerate docs/configuration.md from the Settings model (never edit it by hand).
config-docs:
$(PYTHON) scripts/gen_config_docs.py
# Generates clients/go/client.go when oapi-codegen is installed.
# Missing binary: print install hint and exit 0 so CI without Go still passes.
client-go: openapi
@if command -v oapi-codegen >/dev/null 2>&1; then \
mkdir -p clients/go; \
oapi-codegen -generate client,types -package raglogs -o clients/go/client.go $(OPENAPI); \
echo "Wrote clients/go/client.go"; \
else \
echo "oapi-codegen not found. Install with:"; \
echo " go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest"; \
echo "Then re-run: make client-go"; \
fi
# Committed client is src/clients/v1.py. Optional generator dump is gitignored.
client-python: openapi
@echo "Committed typed client: src/clients/v1.py (targets /v1)."
@if command -v openapi-python-client >/dev/null 2>&1; then \
mkdir -p clients/python/generated; \
openapi-python-client generate --path $(OPENAPI) --output-path clients/python/generated --overwrite; \
echo "Wrote clients/python/generated/"; \
else \
echo "Optional generator openapi-python-client not installed."; \
echo " pip install openapi-python-client"; \
echo "Using the thin committed client instead (src/clients/v1.py)."; \
fi
# ── Cleanup ───────────────────────────────────────────────────────────────────
clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type d -name .pytest_cache -exec rm -rf {} + 2>/dev/null || true
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
find . -name "*.pyc" -delete 2>/dev/null || true
@echo "Cleaned."