Spaces:
Running
Running
Melika Kheirieh
commited on
Commit
Β·
418f5a0
1
Parent(s):
7034c31
style(makefile): tidy and reorder sections for clarity
Browse files
Makefile
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# ---------- Config ----------
|
| 2 |
VENV_DIR ?= .venv
|
| 3 |
PY ?= $(if $(wildcard $(VENV_DIR)/bin/python),$(VENV_DIR)/bin/python,python3)
|
|
@@ -12,13 +16,17 @@ PORT ?= 8000
|
|
| 12 |
|
| 13 |
.DEFAULT_GOAL := help
|
| 14 |
|
| 15 |
-
#
|
|
|
|
|
|
|
| 16 |
.PHONY: help
|
| 17 |
help: ## Show this help
|
| 18 |
@printf "\n\033[1mAvailable targets:\033[0m\n"
|
| 19 |
@awk 'BEGIN {FS = ":.*##"} /^[[:alnum:]_.-]+:.*##/ {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
| 20 |
|
| 21 |
-
#
|
|
|
|
|
|
|
| 22 |
.PHONY: venv
|
| 23 |
venv: ## Create virtual environment in .venv/
|
| 24 |
python3 -m venv $(VENV_DIR)
|
|
@@ -36,7 +44,9 @@ dev-install: ## Install dev tools (ruff, mypy, pytest, coverage, uvicorn, etc.)
|
|
| 36 |
.PHONY: bootstrap
|
| 37 |
bootstrap: venv dev-install ## Create venv and install dev tools
|
| 38 |
|
| 39 |
-
#
|
|
|
|
|
|
|
| 40 |
.PHONY: fmt-check
|
| 41 |
fmt-check: ## Verify formatting without modifying files
|
| 42 |
$(RUFF) format . --check
|
|
@@ -49,13 +59,17 @@ lint: ## Run linting
|
|
| 49 |
typecheck: ## Run type checking only
|
| 50 |
$(MYPY) . --ignore-missing-imports --explicit-package-bases
|
| 51 |
|
| 52 |
-
#
|
|
|
|
|
|
|
| 53 |
.PHONY: format
|
| 54 |
format: ## Auto-format & fix with ruff
|
| 55 |
$(RUFF) format .
|
| 56 |
$(RUFF) check . --fix
|
| 57 |
|
| 58 |
-
#
|
|
|
|
|
|
|
| 59 |
.PHONY: test
|
| 60 |
test: ## Run fast test suite (exclude slow)
|
| 61 |
PYTHONPATH=$$PWD $(PYTEST) -q -m "not slow"
|
|
@@ -68,30 +82,40 @@ test-all: ## Run full test suite including slow tests
|
|
| 68 |
cov: ## Run tests with coverage
|
| 69 |
PYTHONPATH=$$PWD $(PYTEST) --cov=nl2sql --cov-report=term-missing
|
| 70 |
|
| 71 |
-
#
|
|
|
|
|
|
|
| 72 |
.PHONY: check
|
| 73 |
check: ## Run format check, lint, typecheck, and fast tests
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
#
|
|
|
|
|
|
|
| 80 |
.PHONY: precommit
|
| 81 |
precommit: ## Run all pre-commit hooks on all files
|
| 82 |
pre-commit run --all-files
|
| 83 |
|
| 84 |
-
#
|
|
|
|
|
|
|
| 85 |
.PHONY: run
|
| 86 |
run: ## Run FastAPI app (reload mode)
|
| 87 |
$(UVICORN) app.main:app --reload --host 0.0.0.0 --port $(PORT)
|
| 88 |
|
| 89 |
-
#
|
|
|
|
|
|
|
| 90 |
.PHONY: bench
|
| 91 |
bench: ## Run benchmark suite (DummyLLM fallback)
|
| 92 |
$(PY) -m benchmarks.run
|
| 93 |
|
| 94 |
-
#
|
|
|
|
|
|
|
| 95 |
.PHONY: docker-build
|
| 96 |
docker-build: ## Build Docker image
|
| 97 |
docker build -t $(DOCKER_IMG) .
|
|
@@ -100,7 +124,9 @@ docker-build: ## Build Docker image
|
|
| 100 |
docker-run: ## Run Docker container on port $(PORT)
|
| 101 |
docker run --rm -p $(PORT):8000 $(DOCKER_IMG)
|
| 102 |
|
| 103 |
-
#
|
|
|
|
|
|
|
| 104 |
.PHONY: clean
|
| 105 |
clean: ## Remove Python caches
|
| 106 |
rm -rf __pycache__ .pytest_cache .mypy_cache .ruff_cache
|
|
@@ -109,15 +135,15 @@ clean: ## Remove Python caches
|
|
| 109 |
clean-all: clean ## Remove build artifacts and coverage
|
| 110 |
rm -rf dist build .coverage *.egg-info
|
| 111 |
|
| 112 |
-
#
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
-
prom-up:
|
| 117 |
docker compose -f docker-compose.prom.yml up -d
|
| 118 |
|
| 119 |
-
|
| 120 |
-
prom-check:
|
| 121 |
@if command -v promtool >/dev/null 2>&1; then \
|
| 122 |
echo "π Running promtool locally..."; \
|
| 123 |
promtool check rules prometheus/rules.yml && promtool check config prometheus/prometheus.yml; \
|
|
@@ -129,91 +155,44 @@ prom-check:
|
|
| 129 |
promtool check config /etc/prometheus/prometheus.yml; \
|
| 130 |
fi
|
| 131 |
|
| 132 |
-
|
| 133 |
-
smoke:
|
| 134 |
./scripts/smoke_metrics.sh
|
| 135 |
|
| 136 |
-
|
| 137 |
-
obs-up:
|
| 138 |
@set -e; \
|
| 139 |
-
\
|
| 140 |
-
# 1) Up the stack
|
| 141 |
$(MAKE) prom-up; \
|
| 142 |
-
\
|
| 143 |
-
# 2) Wait for Prometheus readiness
|
| 144 |
-
# - Tries the /-/ready endpoint (preferred). Falls back to port check.
|
| 145 |
-
# - Times out after ~90s.
|
| 146 |
-
echo "β³ Waiting for Prometheus (http://localhost:9090) ..."; \
|
| 147 |
for i in $$(seq 1 30); do \
|
| 148 |
-
|
| 149 |
-
if
|
| 150 |
-
|
| 151 |
-
break; \
|
| 152 |
-
fi; \
|
| 153 |
-
# Fallback: check TCP port if /-/ready is not enabled
|
| 154 |
-
if nc -z localhost 9090 >/dev/null 2>&1; then \
|
| 155 |
-
echo "β
Prometheus port is open (assuming ready)"; \
|
| 156 |
-
break; \
|
| 157 |
-
fi; \
|
| 158 |
-
sleep 3; \
|
| 159 |
-
if [ $$i -eq 30 ]; then \
|
| 160 |
-
echo "β Prometheus did not become ready in time"; \
|
| 161 |
-
exit 1; \
|
| 162 |
-
fi; \
|
| 163 |
done; \
|
| 164 |
-
\
|
| 165 |
-
# 3) Wait for Grafana login page
|
| 166 |
-
# - Checks that /login returns HTTP 200/302.
|
| 167 |
-
echo "β³ Waiting for Grafana (http://localhost:3000) ..."; \
|
| 168 |
for i in $$(seq 1 30); do \
|
| 169 |
code=$$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/login || true); \
|
| 170 |
-
if [ "$$code" = "200" ] || [ "$$code" = "302" ]; then \
|
| 171 |
-
|
| 172 |
-
break; \
|
| 173 |
-
fi; \
|
| 174 |
-
sleep 3; \
|
| 175 |
-
if [ $$i -eq 30 ]; then \
|
| 176 |
-
echo "β Grafana did not become ready in time"; \
|
| 177 |
-
exit 1; \
|
| 178 |
-
fi; \
|
| 179 |
done; \
|
| 180 |
-
\
|
| 181 |
-
# 4) Run smoke to populate metrics
|
| 182 |
-
echo "π Running smoke traffic ..."; \
|
| 183 |
$(MAKE) smoke; \
|
| 184 |
-
echo "π Observability stack is live
|
| 185 |
-
# 5) Auto-import Grafana dashboard
|
| 186 |
$(MAKE) grafana-import
|
| 187 |
|
| 188 |
-
|
| 189 |
-
obs-down:
|
| 190 |
docker compose -f docker-compose.prom.yml down
|
| 191 |
|
| 192 |
-
|
| 193 |
-
obs-logs:
|
| 194 |
docker compose -f docker-compose.prom.yml logs -f
|
| 195 |
|
| 196 |
-
|
| 197 |
-
.PHONY: grafana-import
|
| 198 |
-
|
| 199 |
-
# Import dashboard JSON into Grafana via HTTP API
|
| 200 |
-
grafana-import:
|
| 201 |
@set -e; \
|
| 202 |
echo "β³ Waiting for Grafana API to become ready..."; \
|
| 203 |
for i in $$(seq 1 30); do \
|
| 204 |
code=$$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/health || true); \
|
| 205 |
-
if [ "$$code" = "200" ]; then \
|
| 206 |
-
|
| 207 |
-
break; \
|
| 208 |
-
fi; \
|
| 209 |
-
sleep 3; \
|
| 210 |
-
if [ $$i -eq 30 ]; then \
|
| 211 |
-
echo "β Grafana API did not become ready in time"; \
|
| 212 |
-
exit 1; \
|
| 213 |
-
fi; \
|
| 214 |
done; \
|
| 215 |
-
\
|
| 216 |
-
echo "π¦ Importing dashboard ..."; \
|
| 217 |
curl -s -X POST http://admin:admin@localhost:3000/api/dashboards/db \
|
| 218 |
-H "Content-Type: application/json" \
|
| 219 |
-d "{\"dashboard\": $$(cat prometheus/grafana_dashboard.json), \"overwrite\": true, \"folderId\": 0}" \
|
|
|
|
| 1 |
+
# ==============================================================
|
| 2 |
+
# Makefile β NL2SQL Copilot
|
| 3 |
+
# ==============================================================
|
| 4 |
+
|
| 5 |
# ---------- Config ----------
|
| 6 |
VENV_DIR ?= .venv
|
| 7 |
PY ?= $(if $(wildcard $(VENV_DIR)/bin/python),$(VENV_DIR)/bin/python,python3)
|
|
|
|
| 16 |
|
| 17 |
.DEFAULT_GOAL := help
|
| 18 |
|
| 19 |
+
# ==============================================================
|
| 20 |
+
# Meta
|
| 21 |
+
# ==============================================================
|
| 22 |
.PHONY: help
|
| 23 |
help: ## Show this help
|
| 24 |
@printf "\n\033[1mAvailable targets:\033[0m\n"
|
| 25 |
@awk 'BEGIN {FS = ":.*##"} /^[[:alnum:]_.-]+:.*##/ {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
| 26 |
|
| 27 |
+
# ==============================================================
|
| 28 |
+
# Setup
|
| 29 |
+
# ==============================================================
|
| 30 |
.PHONY: venv
|
| 31 |
venv: ## Create virtual environment in .venv/
|
| 32 |
python3 -m venv $(VENV_DIR)
|
|
|
|
| 44 |
.PHONY: bootstrap
|
| 45 |
bootstrap: venv dev-install ## Create venv and install dev tools
|
| 46 |
|
| 47 |
+
# ==============================================================
|
| 48 |
+
# Quality β Read-only (CI)
|
| 49 |
+
# ==============================================================
|
| 50 |
.PHONY: fmt-check
|
| 51 |
fmt-check: ## Verify formatting without modifying files
|
| 52 |
$(RUFF) format . --check
|
|
|
|
| 59 |
typecheck: ## Run type checking only
|
| 60 |
$(MYPY) . --ignore-missing-imports --explicit-package-bases
|
| 61 |
|
| 62 |
+
# ==============================================================
|
| 63 |
+
# Quality β Write mode (local dev)
|
| 64 |
+
# ==============================================================
|
| 65 |
.PHONY: format
|
| 66 |
format: ## Auto-format & fix with ruff
|
| 67 |
$(RUFF) format .
|
| 68 |
$(RUFF) check . --fix
|
| 69 |
|
| 70 |
+
# ==============================================================
|
| 71 |
+
# Tests
|
| 72 |
+
# ==============================================================
|
| 73 |
.PHONY: test
|
| 74 |
test: ## Run fast test suite (exclude slow)
|
| 75 |
PYTHONPATH=$$PWD $(PYTEST) -q -m "not slow"
|
|
|
|
| 82 |
cov: ## Run tests with coverage
|
| 83 |
PYTHONPATH=$$PWD $(PYTEST) --cov=nl2sql --cov-report=term-missing
|
| 84 |
|
| 85 |
+
# ==============================================================
|
| 86 |
+
# Unified gate for CI
|
| 87 |
+
# ==============================================================
|
| 88 |
.PHONY: check
|
| 89 |
check: ## Run format check, lint, typecheck, and fast tests
|
| 90 |
+
$(MAKE) fmt-check
|
| 91 |
+
$(MAKE) lint
|
| 92 |
+
$(MAKE) typecheck
|
| 93 |
+
$(MAKE) test
|
| 94 |
+
|
| 95 |
+
# ==============================================================
|
| 96 |
+
# Pre-commit
|
| 97 |
+
# ==============================================================
|
| 98 |
.PHONY: precommit
|
| 99 |
precommit: ## Run all pre-commit hooks on all files
|
| 100 |
pre-commit run --all-files
|
| 101 |
|
| 102 |
+
# ==============================================================
|
| 103 |
+
# Run app
|
| 104 |
+
# ==============================================================
|
| 105 |
.PHONY: run
|
| 106 |
run: ## Run FastAPI app (reload mode)
|
| 107 |
$(UVICORN) app.main:app --reload --host 0.0.0.0 --port $(PORT)
|
| 108 |
|
| 109 |
+
# ==============================================================
|
| 110 |
+
# Benchmarks
|
| 111 |
+
# ==============================================================
|
| 112 |
.PHONY: bench
|
| 113 |
bench: ## Run benchmark suite (DummyLLM fallback)
|
| 114 |
$(PY) -m benchmarks.run
|
| 115 |
|
| 116 |
+
# ==============================================================
|
| 117 |
+
# Docker
|
| 118 |
+
# ==============================================================
|
| 119 |
.PHONY: docker-build
|
| 120 |
docker-build: ## Build Docker image
|
| 121 |
docker build -t $(DOCKER_IMG) .
|
|
|
|
| 124 |
docker-run: ## Run Docker container on port $(PORT)
|
| 125 |
docker run --rm -p $(PORT):8000 $(DOCKER_IMG)
|
| 126 |
|
| 127 |
+
# ==============================================================
|
| 128 |
+
# Clean
|
| 129 |
+
# ==============================================================
|
| 130 |
.PHONY: clean
|
| 131 |
clean: ## Remove Python caches
|
| 132 |
rm -rf __pycache__ .pytest_cache .mypy_cache .ruff_cache
|
|
|
|
| 135 |
clean-all: clean ## Remove build artifacts and coverage
|
| 136 |
rm -rf dist build .coverage *.egg-info
|
| 137 |
|
| 138 |
+
# ==============================================================
|
| 139 |
+
# Observability Stack
|
| 140 |
+
# ==============================================================
|
| 141 |
+
.PHONY: obs-up obs-down obs-logs prom-up prom-check smoke grafana-import
|
| 142 |
|
| 143 |
+
prom-up: ## Bring up Prometheus + Grafana via Docker Compose
|
|
|
|
| 144 |
docker compose -f docker-compose.prom.yml up -d
|
| 145 |
|
| 146 |
+
prom-check: ## Validate Prometheus configs (local or Docker fallback)
|
|
|
|
| 147 |
@if command -v promtool >/dev/null 2>&1; then \
|
| 148 |
echo "π Running promtool locally..."; \
|
| 149 |
promtool check rules prometheus/rules.yml && promtool check config prometheus/prometheus.yml; \
|
|
|
|
| 155 |
promtool check config /etc/prometheus/prometheus.yml; \
|
| 156 |
fi
|
| 157 |
|
| 158 |
+
smoke: ## Generate sample traffic and print key metrics snapshot
|
|
|
|
| 159 |
./scripts/smoke_metrics.sh
|
| 160 |
|
| 161 |
+
obs-up: ## Start observability stack and verify readiness
|
|
|
|
| 162 |
@set -e; \
|
|
|
|
|
|
|
| 163 |
$(MAKE) prom-up; \
|
| 164 |
+
echo "β³ Waiting for Prometheus (http://localhost:9090)..."; \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
for i in $$(seq 1 30); do \
|
| 166 |
+
if curl -fsS http://localhost:9090/-/ready >/dev/null 2>&1; then echo "β
Prometheus is ready"; break; fi; \
|
| 167 |
+
if nc -z localhost 9090 >/dev/null 2>&1; then echo "β
Prometheus port is open (assuming ready)"; break; fi; \
|
| 168 |
+
sleep 3; if [ $$i -eq 30 ]; then echo "β Prometheus did not become ready in time"; exit 1; fi; \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
done; \
|
| 170 |
+
echo "β³ Waiting for Grafana (http://localhost:3000)..."; \
|
|
|
|
|
|
|
|
|
|
| 171 |
for i in $$(seq 1 30); do \
|
| 172 |
code=$$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/login || true); \
|
| 173 |
+
if [ "$$code" = "200" ] || [ "$$code" = "302" ]; then echo "β
Grafana is up"; break; fi; \
|
| 174 |
+
sleep 3; if [ $$i -eq 30 ]; then echo "β Grafana did not become ready in time"; exit 1; fi; \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
done; \
|
| 176 |
+
echo "π Running smoke traffic..."; \
|
|
|
|
|
|
|
| 177 |
$(MAKE) smoke; \
|
| 178 |
+
echo "π Observability stack is live β Prometheus: http://localhost:9090 , Grafana: http://localhost:3000"; \
|
|
|
|
| 179 |
$(MAKE) grafana-import
|
| 180 |
|
| 181 |
+
obs-down: ## Tear down the observability stack
|
|
|
|
| 182 |
docker compose -f docker-compose.prom.yml down
|
| 183 |
|
| 184 |
+
obs-logs: ## Tail logs of both services
|
|
|
|
| 185 |
docker compose -f docker-compose.prom.yml logs -f
|
| 186 |
|
| 187 |
+
grafana-import: ## Import Grafana dashboard via HTTP API
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
@set -e; \
|
| 189 |
echo "β³ Waiting for Grafana API to become ready..."; \
|
| 190 |
for i in $$(seq 1 30); do \
|
| 191 |
code=$$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/health || true); \
|
| 192 |
+
if [ "$$code" = "200" ]; then echo "β
Grafana API is ready"; break; fi; \
|
| 193 |
+
sleep 3; if [ $$i -eq 30 ]; then echo "β Grafana API did not become ready in time"; exit 1; fi; \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
done; \
|
| 195 |
+
echo "π¦ Importing dashboard..."; \
|
|
|
|
| 196 |
curl -s -X POST http://admin:admin@localhost:3000/api/dashboards/db \
|
| 197 |
-H "Content-Type: application/json" \
|
| 198 |
-d "{\"dashboard\": $$(cat prometheus/grafana_dashboard.json), \"overwrite\": true, \"folderId\": 0}" \
|