Phase 3 of docs/RUST_REWRITE.md: rust/collector/src/web (axum) serves what
the FastAPI app (src/web_api.py) served, so one process collects, forecasts,
notifies and serves. With WEB_LISTEN=0.0.0.0:8000 it runs inside
`ping-collector run`; `ping-collector serve` runs it alone.
Same routes, parameters, JSON fields and field order, status codes,
{"detail": ...} errors and pydantic-style 422 lists, Cache-Control, gzip
(>500 B), CORS, Umami API tracking, the dashboard and static files, and the
stale-while-revalidate response caches (now with byte budgets: a history
response can be 10 MB). /docs is the same Swagger UI (+ /redoc); its OpenAPI
document is built from the route table, whose per-route parameter
declarations also validate the requests, so docs and behaviour cannot drift.
Python output conventions are kept: isoformat(), round(), numpy's pairwise
sums (catchment means), Python's summation order (skill metrics).
scripts/api_parity.py compares the two servers route by route on one
database (53 cases incl. errors, admin and static files; query values vary
per run so FastAPI's caches answer fresh). Locally: 53 identical; the
station CRUD writes byte-identical stations.json files; the skill/trend
logic matches on 9 station/horizon pairs with synthetic model versions.
Intended differences: /health counts the ThaiWater telemetry of the same
gauges while RID lags (as the notifier); /scraping/status adds the collector
version and last forecast run; an old stored forecast is served marked
X-Data-Stale instead of recomputed; /sensors/thaiwater is cached a minute;
.geojson is served as application/geo+json. Load (local, 16 clients): the
dashboard's routes 1375 vs 552 req/s, uncached history 714 vs 53 req/s;
25 MB resident when serving only.
Matrix (MATRIX_*): the notifier sends the room the transitions ntfy gets
(per station, outlook, feed; not ntfy's per-topic summaries), each once,
with its own matrix: keys in notification_state, seeded from ntfy's on first
use so nothing already announced repeats. Checked against a fake homeserver.
It replaces the `run.py --alert-check` cron job (repeated alerts every 15
min), which install_collector.sh now comments out (crontab backup kept).
install_collector.sh: --check-api (ping-collector serve on :8001 next to
FastAPI, api_parity.py), --cutover-api (refuses on a difference; sets
WEB_LISTEN, stops and disables water-monitor.service), --rollback-api;
--rollback-forecast and --rollback bring the Python app back as server.
ping-collector.service: MemoryMax 512M. Config::from_vars for tests; route
tests against a throwaway schema.
40 lines
1.8 KiB
TOML
40 lines
1.8 KiB
TOML
[workspace]
|
|
resolver = "3"
|
|
members = ["collector", "forecast"]
|
|
|
|
[workspace.package]
|
|
# 1.88: edition 2024 let-chains, and dependencies (home, icu_*) need it. Distro
|
|
# cargo packages are older: install the toolchain with rustup (rust/README.md).
|
|
edition = "2024"
|
|
rust-version = "1.88"
|
|
license = "MIT"
|
|
publish = false
|
|
repository = "https://git.b4l.co.th/B4L/Northern-Thailand-Ping-River-Monitor"
|
|
|
|
[workspace.dependencies]
|
|
anyhow = "1"
|
|
axum = { version = "0.8", default-features = false, features = ["http1", "tokio", "query", "json", "matched-path", "original-uri"] }
|
|
chrono = { version = "0.4", default-features = false, features = ["std", "clock", "serde"] }
|
|
clap = { version = "4", features = ["derive"] }
|
|
flate2 = "1"
|
|
form_urlencoded = "1"
|
|
log = "0.4"
|
|
# native-tls (OpenSSL on Linux, SChannel on Windows), not rustls: app.rid.go.th (dams)
|
|
# offers only TLS 1.2 CBC suites (ECDHE-RSA-AES256-SHA384), which rustls refuses.
|
|
reqwest = { version = "0.12", default-features = false, features = ["native-tls", "json"] }
|
|
serde = { version = "1", features = ["derive"] }
|
|
# preserve_order: JSON objects keep the order they were built in (API
|
|
# responses list their fields in the same order as the FastAPI app did)
|
|
serde_json = { version = "1", features = ["float_roundtrip", "preserve_order"] }
|
|
sqlx = { version = "0.8", default-features = false, features = ["runtime-tokio", "tls-rustls", "postgres", "chrono", "macros"] }
|
|
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time", "signal", "net", "sync", "fs"] }
|
|
tower = { version = "0.5", default-features = false, features = ["util"] }
|
|
tower-http = { version = "0.6", features = ["compression-gzip", "cors", "fs"] }
|
|
tracing = "0.1"
|
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|
|
|
[profile.release]
|
|
lto = "thin"
|
|
codegen-units = 1
|
|
strip = true
|