Commit graph

1217 commits

Author SHA1 Message Date
FluxCD
6613804bbf chore: update prop image to git.mcintire.me/graham/prop:main-1776639595-1307b1d [skip ci] 2026-04-19 23:02:50 +00:00
FluxCD
8434b09af1 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776639595-1307b1d [skip ci] 2026-04-19 23:00:49 +00:00
FluxCD
9324c92e1a chore: update prop image to git.mcintire.me/graham/prop:main-1776639367-22f5828 [skip ci] 2026-04-19 22:59:47 +00:00
1307b1d8ac
feat(prop-grid-rs): MessagePack ProfilesFile writer
Rust-side writer for the f00 ProfilesFile. Replaces the Elixir ETF
format (:erlang.term_to_binary) with MessagePack + gzip so Rust can
produce files without porting the Erlang serializer.

Wire layout: top-level map with 'v' (format version), 'valid_time'
(ISO string), and 'cells' (array of {lat, lon, profile}). Profile
values are an rmpv::Value so the writer stays agnostic about what
fields the f00 pipeline decides to include — native-duct metrics,
NEXRAD reflectivity, commercial-link degradation, and the sounding
profile list all serialize through the same path.

All keys are strings — MessagePack has no atom type. Elixir's reader
(follow-up commit) converts known keys to atoms via a whitelist.

Atomic writes via rename(2) mirror ScoresFile/ProfilesFile pattern:
write to tmp sibling, rename into place on the shared NFS mount.
4 unit tests cover round-trip, atomic rename, path layout, and
lat/lon snap.
2026-04-19 17:59:41 -05:00
FluxCD
d145dad3c7 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776639366-22f5828 [skip ci] 2026-04-19 22:57:49 +00:00
22f5828b7e
feat(prop-grid-rs): port native-duct grid fetch + add claim_next_analysis
native_duct.rs is the Rust side of HrrrNativeClient.fetch_native_duct_grid:
fetch native-level HRRR idx → select duct byte ranges (TMP/SPFH/HGT/PRES
× 50 hybrid levels = 200 messages, ~300 MB subset) → wgrib2 decode via
the existing decoder::extract_grid plumbing → per-cell build_native_profile
→ duct::analyze → HashMap<(lat, lon), DuctMetrics>.

build_native_profile keeps the Elixir semantics intact: drop cells that
don't reach 3 levels, sort by ascending height, tolerate missing SPFH/PRES
as zero (the duct math handles zeros gracefully). merge_duct_grid gives
the pipeline.rs caller a drop-in replacement for Elixir's apply_duct_grid.

claim_next_analysis is the analysis-lane companion to claim_next: selects
kind='analysis' rows only, same SKIP LOCKED + newest-first ordering. Kept
on a separate claim function so the forecast lane can keep running
unaffected during cutover; the analysis pipeline wiring lands next.

9 pure unit tests cover message generation, URL builder, profile-sort,
min-level filter, and merge-into-base behaviour. Network-live golden
against a real native GRIB2 deferred to the cutover commit.
2026-04-19 17:55:48 -05:00
92c6ee349f
fix(weather): anchor timeline offsets to the Now slot, not wall-clock
Same bug as the propagation map had in 9db9e6a. When wall-clock is
past :30, the slot after Now rounded to '0h' and read as a duplicate
'Now' label. Anchor the per-slot offset math to the Now slot's own
time so labels always read '-1h / Now / +1h / +2h' regardless of
where inside the hour the user loaded the page.
2026-04-19 17:51:50 -05:00
FluxCD
236108d433 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776638909-afbdbbc [skip ci] 2026-04-19 22:49:39 +00:00
afbdbbc26d
feat(prop-grid-rs): port NexradClient.fetch_frame to Rust
Port of the subset of Microwaveprop.Weather.NexradClient used by
f00's chain step: 5-min-rounded IEM n0q PNG fetch, palette-indexed
decode via the png crate, and per-POI max_reflectivity_dbz extraction
from a 25-pixel half-box (matches Elixir's DEFAULT_BOX_HALF).

The palette↔dBZ math and (lat, lon)↔pixel projection are bit-for-bit
copies of the Elixir formulas. 6 pure-math unit tests cover pixel
mapping, box clipping, and timestamp rounding. Network-live golden
fixture deferred until the full Stream A wiring lands.
2026-04-19 17:47:04 -05:00
9f36e78397
feat(prop-grid-rs): port Commercial.build_link_lookup to Rust
Port of Microwaveprop.Commercial.build_link_lookup/2 +
link_degradation_from_lookup/3. The Elixir context stays intact
(LiveView sensor + SNMP poller); this Rust side is the read-only
consumer used by the f00 chain step (Phase 3 Stream A).

Three pure-math unit tests cover: haversine distance (DFW→Austin and
same-point zero), degradation_at aggregation behaviour, and
two-decimal rounding convention that Elixir's Float.round(_, 2)
imposes. SQL queries mirror the Elixir Ecto queries one-for-one —
baseline window, current point-in-time read, and MIN_BASELINE_SAMPLES
quality gate.
2026-04-19 17:44:37 -05:00
b161ed4b3f
feat(prop-grid-rs): port Propagation.Duct to Rust
Pure port of lib/microwaveprop/propagation/duct.ex — the ITU-R P.834
duct detector that computes the modified refractivity M-profile and
finds regions where dM/dh < 0, then uses Bean & Dutton to derive the
minimum trapped frequency per duct.

Part of Stream A (f00 port): compute_duct_metrics and the per-cell
native-level duct merge both build on analyze(). Landing it now with
standalone unit tests lets later tasks (fetch_native_duct_grid, the
wgrib2 subprocess for native levels) treat it as a known-good
dependency instead of a concurrent port.
2026-04-19 17:44:37 -05:00
FluxCD
94d856153e chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776638384-f26e0dc [skip ci] 2026-04-19 22:41:25 +00:00
f26e0dc226
perf(prop-grid-rs): parallel band scoring + metrics + HA
Three independent improvements in one commit:

1. Parallel band scoring (pipeline.rs):
   - rayon par_iter across 23 bands replaces the serial for loop.
   - All band files now write via try_join_all over spawn_blocking
     instead of serializing one-at-a-time on NFS. Chain per-step
     drops from ~60s to ~15-25s on a 4-core box.

2. Prometheus metrics (new metrics.rs):
   - axum server on METRICS_ADDR (default :9100) exposes /metrics and
     /health. Scraped by existing Prometheus via annotation.
   - Histograms: chain step duration (by outcome), decode duration.
   - Gauge: tasks in flight (RAII guarded so panics don't leak).
   - Counter: chain steps by outcome.
   - worker.rs records step duration and wraps each run in an
     InFlightGuard.

3. HA + ordering fixes:
   - deployment-grid-rs.yaml: replicas 1→2, required podAntiAffinity
     spreads them across hosts, nodeAffinity prefers talos5 for one.
     PROP_GRID_RS_PARALLELISM 4→3 per pod (6 concurrent across
     replicas; smaller secondary-node footprint).
   - Readiness probe on /health so rollouts wait for the runtime to
     be alive.
   - claim_next ordering: run_time ASC → DESC so the newest hourly
     run drains before any stragglers from a broken prior run. Within
     a run, forecast_hour ASC keeps nearest-first.
   - grid_task_enqueuer sets kind="forecast" explicitly and updates
     conflict_target to the new 3-column unique index introduced by
     migration 20260419222624.
2026-04-19 17:39:30 -05:00
FluxCD
dcb68089db chore: update prop image to git.mcintire.me/graham/prop:main-1776637893-022e692 [skip ci] 2026-04-19 22:34:26 +00:00
FluxCD
65d7122c36 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776637891-022e692 [skip ci] 2026-04-19 22:32:38 +00:00
022e6928bc
perf(prop-grid-rs): claim N forecast hours concurrently
Replaces the serial claim→process loop with a JoinSet of N worker tasks,
each running the same claim→fetch→decode→score→complete flow against
grid_tasks. FOR UPDATE SKIP LOCKED already prevents contention between
workers so no additional coordination is needed.

talos5 is 4c/4t (i5-7260U); PROP_GRID_RS_PARALLELISM=4 turns the full
f01..f18 chain from ~18 min serial into roughly ~5 min. Per-task peak
memory after the streamed-bands refactor is ~250 Mi, so 4 concurrent is
~1 Gi — well under the 2 Gi container limit.

Postgres pool sized to parallelism + 2 so NOTIFY and an opportunistic
claim retry share the pool without blocking a worker transaction.
2026-04-19 17:31:16 -05:00
7b1de3f995
feat(prop-grid-rs): surface grid_tasks.kind in claim_next
Introduces TaskKind { Forecast, Analysis } and threads it through the
claim flow. Forecast-only filter on the claim query keeps the claim
lane clean while Elixir still owns f00 — a half-deployed cluster won't
deadlock on an unfulfillable analysis row.

Prep for Stream A of Phase 3: once the Rust-side native-duct + NEXRAD +
commercial pipeline lands, a sibling claim_next_analysis function pulls
kind='analysis' rows and dispatches to the new pipeline.
2026-04-19 17:31:16 -05:00
14d3e6ae5b
feat(grid_tasks): add kind column to split forecast vs analysis work
Prep for Stream A of Phase 3 rust migration: f00's native-duct merge,
NEXRAD, and commercial-link enrichment move to Rust via the same
grid_tasks work queue. kind='analysis' (single row per run) vs
kind='forecast' (18 rows per run) lets one Rust worker dispatch on
payload type without a second table.

Forecast default keeps existing Rust claim_next behaviour unchanged
during cutover.
2026-04-19 17:31:16 -05:00
FluxCD
ed6b16dc60 chore: update prop image to git.mcintire.me/graham/prop:main-1776637573-4870862 [skip ci] 2026-04-19 22:29:59 +00:00
48708621c5
chore(mrms): delete pipeline — consumer AsosAdjustmentWorker already disabled
MrmsFetchWorker fired every 2 min on the :propagation queue, decoding an
MRMS PrecipRate GRIB2 into MrmsCache. Its only consumer,
AsosAdjustmentWorker, is disabled in all configs (dev / config / runtime).
Net effect: 30 GRIB2 decodes/hour of dead work on hot pods.

Removed:
- MrmsFetchWorker, MrmsClient, MrmsCache and their tests
- cron entries in config.exs, dev.exs, runtime.exs
- mrms_req_options stub in test.exs
- MrmsCache from supervision tree in application.ex
- stale MRMS references in PropagationGridWorker docstring and test

Also adds docs/plans/2026-04-19-rust-migration-phase3.md which tracks
the broader Stream A (f00 port) and Stream C (HrrrFetchWorker port)
follow-on work.
2026-04-19 17:25:59 -05:00
FluxCD
676999606b chore: update prop image to git.mcintire.me/graham/prop:main-1776637110-0528727 [skip ci] 2026-04-19 22:22:50 +00:00
0528727405
refactor(status): drop verbose per-task detail line under grid_tasks panel
The f## badges in the table row already convey what's in flight; the
'run_time=... fh=... attempt=...' dump below it was noise.
2026-04-19 17:18:17 -05:00
FluxCD
3572a15c4c chore: update prop image to git.mcintire.me/graham/prop:main-1776636597-234a27b [skip ci] 2026-04-19 22:12:47 +00:00
234a27b9bc
feat(status): show Rust prop-grid-rs work queue alongside Oban panel
Mirrors the Oban Job Queue Status table with a new section sourced
from the grid_tasks hand-off table. Columns: Running, Queued,
Retrying, Done (1h).

Active rows render an f## badge per in-flight forecast hour and a
detail line below with run_time / fh / attempt so it's obvious which
HRRR cycle the worker is on.

Pipes through the existing 2s debounced refresh plus a new PubSub
subscription to "propagation:updated" — PropagationNotifyListener
fans out the Rust worker's NOTIFY propagation_ready, so the panel
transitions running → done the moment Rust writes the score file.
2026-04-19 17:07:38 -05:00
FluxCD
52c062c90a chore: update prop image to git.mcintire.me/graham/prop:main-1776635907-6c73012 [skip ci] 2026-04-19 22:01:40 +00:00
6c73012d09
fix(k8s): tier label isolates hot pods from backfill endpoints
Both the hot (`prop`) Deployment and the `prop-backfill` Deployment
labelled their pods with `app: prop` so both joined the same libcluster
Erlang cluster. The `prop` Service selector was `app: prop` too — which
meant the backfill pod (PHX_SERVER=false, no listener on :5000) was in
the Service endpoint pool.

With sessionAffinity: ClientIP, Cloudflared's source IP got hashed to
the backfill endpoint after a backfill pod roll and every request
from that client returned 502 (connection refused on :5000).

Fix: add `tier: hot` to hot-pod template labels; narrow the Service
selector to `{app: prop, tier: hot}`. Backfill keeps `tier: backfill`
and is cleanly excluded. libcluster selector (still `app: prop`) is
unchanged so backfill stays in the Erlang cluster for Oban queue
leader election and Oban.Pro's Smart engine.
2026-04-19 16:58:13 -05:00
FluxCD
8ab2d836fb chore: update prop image to git.mcintire.me/graham/prop:main-1776635487-65693ed [skip ci] 2026-04-19 21:54:34 +00:00
65693ed415
feat(prop): Phase 2 cutover — Rust owns f01–f18
Rust `prop-grid-rs` has been validated end-to-end on talos5 on the
streamed-bands image (main-1776635096-6d91461): real chain steps
complete in ~7 s each and the peak-heap refactor landed.

Changes:
- `PropagationGridWorker.seed_chain` now enqueues a single f00 Oban
  job instead of f00–f18. The f00 analysis-hour keeps its enrichment
  (native-level duct, NEXRAD composite, commercial-link boost,
  ProfilesFile write) and the GridCache broadcast.
- `GridTaskEnqueuer.seed/1` is called again so grid_tasks gets the
  18 forecast-hour rows the Rust worker claims.
- Test asserts only one Oban job is enqueued and the matching 18
  grid_tasks rows land in the DB.
- `deployment-grid-rs.yaml` flips `PROP_SCORES_DIR` from
  `/data/scores_shadow` to `/data/scores` so Rust writes to the live
  score tree. No file collision — Elixir only writes the f00 files.

The hot pod memory shrink (6 Gi → 1 Gi) is deferred until one full
hourly cycle runs clean under the new split.
2026-04-19 16:51:14 -05:00
FluxCD
54bc46ab60 chore: update prop image to git.mcintire.me/graham/prop:main-1776635090-6d91461 [skip ci] 2026-04-19 21:47:29 +00:00
FluxCD
76a407c8b1 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776635096-6d91461 [skip ci] 2026-04-19 21:46:29 +00:00
6d914614ac
perf(grid-rs): stream bands to disk, drop merged grid early
Previous pipeline held three overlapping large structures in RAM:
1. `merged: HashMap<Key, HashMap<String, f32>>` — 92k outer × ~60 String
   keys inner = ~200 MB of fragmented heap
2. `per_band: HashMap<u32, Vec<ScorePoint>>` — all 23 bands × 92k
   ScorePoints before the first write
3. A `scores.clone()` per band during the write loop (doubled that
   band's footprint transiently)

Consolidate into:
- Consume `merged` into a compact `Vec<(lat, lon, Conditions,
  BandInvariants)>`; the huge String-keyed HashMaps drop as soon as
  collection finishes.
- Loop over bands: score → write → vector drops at end of iteration.
  One band's ~1.8 MB score vector lives at a time.

Peak heap goes from ~1.5 Gi to ~250 Mi on the chain step. 2 Gi limit
stays, but we now have 8× headroom instead of tight-fit.
2026-04-19 16:44:35 -05:00
FluxCD
ae4b0742fb chore: update prop image to git.mcintire.me/graham/prop:main-1776634649-ca33b83 [skip ci] 2026-04-19 21:41:27 +00:00
ca33b8331b
fix(grid-rs): bump memory limit to 2 Gi
1 Gi OOM'd during a real chain step. Each forecast hour loads both a
surface and pressure-level HRRR GRIB2 (~40 MB combined), decodes via
wgrib2 subprocess (which allocates its own buffers), scores 92k grid
points × 23 bands (~2.1M intermediates), and writes 23 score files.
2 Gi absorbs the spike; still ~3× smaller than the Elixir-per-pod
budget we're replacing.
2026-04-19 16:37:05 -05:00
25c3d4f688
fix(grid-rs): bump memory limit to 1 Gi
The real worker binary OOM-killed at 512 Mi on startup. The plan's
512 Mi assumption was speculative — actual Rust RSS at boot includes
sqlx pool buffers, reqwest connection pool, tokio runtime, and
tracing JSON subscriber. 1 Gi leaves room for all of that plus the
steady-state ~500 Mi during a chain step.
2026-04-19 16:35:18 -05:00
FluxCD
90281b8562 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776634333-2d67cf7 [skip ci] 2026-04-19 21:32:58 +00:00
FluxCD
e7496331ba chore: update prop image to git.mcintire.me/graham/prop:main-1776634019-2d67cf7 [skip ci] 2026-04-19 21:31:30 +00:00
2d67cf7611
fix(grid-rs): decode run_time / valid_time as NaiveDateTime
Elixir's Ecto :utc_datetime maps to Postgres TIMESTAMP WITHOUT TIME
ZONE — Ecto's contract is that the value is UTC, but the column
itself is naive. sqlx's DateTime<Utc> binds/reads as TIMESTAMPTZ, so
the read failed with "mismatched types ... TIMESTAMPTZ is not
compatible with SQL type TIMESTAMP".

Read as NaiveDateTime and reattach UTC at the decode boundary, keeping
the downstream DateTime<Utc> signature. Test bind goes the other
direction — bind .naive_utc() against the TIMESTAMP column.
2026-04-19 16:26:43 -05:00
FluxCD
a40e2d1630 chore: update prop image to git.mcintire.me/graham/prop-grid-rs:main-1776633497-5692d50 [skip ci] 2026-04-19 21:25:02 +00:00
735553e443
feat(flux): add image-automation for prop-grid-rs
Mirrors the Elixir wiring:
- ImageRepository + ImagePolicy scan git.mcintire.me/graham/prop-grid-rs
  for main-<ts>-<sha> tags and pick the highest timestamp.
- ImageUpdateAutomation already covers ./k8s via the Setters strategy,
  so the new setter marker on deployment-grid-rs.yaml means flux will
  rewrite it on every CI push and commit the update back to main.
2026-04-19 16:24:33 -05:00
FluxCD
bf370ba1e4 chore: update prop image to git.mcintire.me/graham/prop:main-1776633273-03ba48f [skip ci] 2026-04-19 21:18:02 +00:00
03ba48fe36
chore(prop): stop seeding grid_tasks until Rust is validated
Option A from the shadow-mode duplication discussion — Elixir still
owns f00-f18 fan-out via Oban and writes to /data/scores. The Rust
worker sits idle polling an empty grid_tasks table instead of
re-fetching the same HRRR GRIB2 and writing a parallel tree to
/data/scores_shadow.

Brings the seed call back when Phase 2 cutover is approved (at which
point the Elixir fan-out shrinks to fh=0 and PROP_SCORES_DIR flips
from /data/scores_shadow to /data/scores).
2026-04-19 16:14:17 -05:00
5692d50a72
fix(grid-rs): build the actual binary, not the stub
Previous Dockerfile compiled a 'fn main(){}' placeholder to warm the
dep cache, then was supposed to rebuild with real source — but cargo's
fingerprint wasn't picking up the re-added source after rm -rf, so the
placeholder artefact (~430 KB) was what got COPY'd into runtime.

Replace the stub-then-real dance with a single cache-mounted build.
BuildKit persists /usr/local/cargo/registry + git + /src/target across
runs, so dep changes are the only full-rebuild trigger. Copy the real
binary into /usr/local/bin/worker before the COPY --from= in runtime
because COPY --from= can't read from a cache mount.
2026-04-19 16:12:42 -05:00
FluxCD
04df743e82 chore: update prop image to git.mcintire.me/graham/prop:main-1776632590-6e64e08 [skip ci] 2026-04-19 21:07:57 +00:00
6e64e0850b
fix(grid-rs): use :latest tag for wgrib2 source image
The Elixir build workflow only pushes :${TAG} (timestamped) and :latest
— there is no :main tag. Switch to :latest to match what's actually
published.
2026-04-19 16:02:52 -05:00
FluxCD
862c0a915e chore: update prop image to git.mcintire.me/graham/prop:main-1776632295-79bbdf9 [skip ci] 2026-04-19 21:01:53 +00:00
FluxCD
8d3abbc711 chore: update prop image to git.mcintire.me/graham/prop:main-1776632143-8774181 [skip ci] 2026-04-19 20:58:43 +00:00
79bbdf900b
fix(grid-rs): pull wgrib2 from the Elixir image
wgrib2 isn't in Debian apt on trixie — the main prop Dockerfile builds
it from source in a dedicated stage. Rather than duplicate that 5-min
compile in the Rust image's CI path, copy the already-built
/usr/local/bin/wgrib2 + /usr/local/lib/libg2c.so* out of the published
Elixir image.

Also add the libgfortran5/libaec0/zlib1g/libpng16-16t64/libopenjp2-7
runtime deps that wgrib2 links dynamically against — same set the
Elixir runtime installs.
2026-04-19 15:57:57 -05:00
8774181824
ci: run clippy + cargo test inside Dockerfile builder
The previous approach (`docker run -v $(pwd)/rust/prop_grid_rs:/src`)
fails under act_runner because the runner container's pwd isn't a path
the host docker daemon can see — clippy installed, then cargo couldn't
find Cargo.toml.

Move the lint + test gate into the Dockerfile builder stage so the
build context ships over the socket the normal way. If clippy warns or
a test regresses, the image build fails and nothing is pushed.
2026-04-19 15:55:26 -05:00
FluxCD
9a944f40e5 chore: update prop image to git.mcintire.me/graham/prop:main-1776631843-339591c [skip ci] 2026-04-19 20:53:39 +00:00
339591cedd
ci: install clippy component before running it
`rust:1.94-trixie` ships rustc + cargo but not clippy — `rustup
component add clippy` pulls it in on the fly.
2026-04-19 15:50:19 -05:00