feat(packets): full-history archive browser + month-partition the mqtt_messages table#479
Merged
Conversation
…ad, auto-rolled partitions, in-place migration
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes the mqtt_messages packet archive both user-queryable (full-history browser with keyset pagination + deeplinks) and operationally scalable (monthly range partitioning + lz4 compression), while also improving enrichment provider handling and Postgres ops documentation.
Changes:
- Added a new
/v1/packetskeyset-paginated API (plus/v1/packets/{id}) and rewired the frontend Logs page to browse full history with infinite scroll, URL↔state sync, and packet deeplinks. - Converted
mqtt_messagesto a month-RANGE partitioned table on fresh installs and added an in-place migration script for existing DBs; added runtime partition roll-forward. - Hardened JSONB writes against
datetime-containing payloads and updated enrichment provider configuration (Meshview bulk support; dead legacy providers dropped).
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
storage/db/postgres.py |
Adds JSON serialization fallback, cursor pagination helpers, partition roll-forward, and packet archive query/deeplink support. |
api/api.py |
Adds /v1/packets + /v1/packets/{id} and updates node packets response to include cursors. |
frontend/src/pages/Log.tsx |
Rebuilds Logs into a full-history packet browser with infinite scroll, filters, and deeplink banner. |
frontend/src/slices/apiSlice.ts |
Adds RTK Query endpoints/types for packet archive pagination and single-packet fetch. |
postgres/sql/schema.sql |
Creates partitioned+compressed mqtt_messages on fresh installs and keeps legacy installs untouched. |
scripts/migrate-mqtt-partitioning.sh |
Provides one-time transactional migration of existing mqtt_messages into monthly partitions. |
main.py |
Renames/extends prune loop into maintenance loop and adds periodic partition roll-forward. |
data_store.py |
Removes presets, adds dead-legacy provider handling, and adds Meshview bulk enrichment path. |
tests/test_postgres_helpers.py |
Adds unit tests for cursor codec, JSON default serialization, page building, and partition spec generation. |
tests/test_enrichment_providers.py |
Updates provider-resolution tests for dead legacy providers and Meshview provider kind. |
POSTGRES.md |
Documents memory tuning knobs and the mqtt_messages partitioning/migration workflow. |
docker-compose.yml |
Adds env-overridable Postgres memory tuning settings. |
docker-compose-dev.yml |
Adds env-overridable Postgres memory tuning settings for dev compose. |
API.md |
Documents keyset pagination and deeplinks for packets endpoints. |
config.toml.sample |
Updates enrichment provider examples to Meshview bulk + explicit URL templates. |
config.py |
Updates default enrich provider list to empty (no shipped presets). |
.env.sample |
Adds sample Postgres memory tuning env vars. |
postgres/sql/meshinfo.sql |
Removes obsolete SQL file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Makes the raw-packet archive (
mqtt_messages) both queryable for users andoperationally scalable. Adds a full-history packet browser backed by keyset
pagination, and converts
mqtt_messages(98%+ of the DB) to a month-RANGEpartitioned, lz4-compressed table so date-range queries prune to the relevant
months and maintenance runs at partition scale.
What's included
Packet archive browser
GET /v1/packets: keyset/cursor pagination with absolutestart/end(epoch) date-range filtering +
q/topicfilters;GET /v1/packets/{id}for per-packet deeplinks. Response:
{messages, next_cursor}.pills, deeplinked single-packet banner, URL↔state sync.
mqtt_messagespartitioning + lz4(id, created_at),payloadlz4-compressed) via a guarded block inschema.sql.ensure_mqtt_partitions()rolls current + next 2 months' partitions forward(at startup and hourly from the renamed
maintenance_loop).scripts/migrate-mqtt-partitioning.sh: one-time in-place conversion forexisting DBs — single atomic transaction (rename → create → copy → verify row
count → rebuild indexes → re-home sequence → reinstall trigger), with a 3×
disk pre-flight and the original kept as
mqtt_messages_oldfor rollback.Enrichment / fixes
drops the broken
baymepreset (legacy configs warn + skip).dropped the write).
defaults).
Migration / ops notes
bash scripts/migrate-mqtt-partitioning.shonce (stackup). Idempotent; transactional; keeps
mqtt_messages_olduntil you drop it.postgres:18image provides it).
mark_nodes_inactive_by_age("prune") only flips anactiveflag; partitioning copies + row-count-verifies before commit.
Testing / verification
pytest: 114 passed.compression = lz4, partition pruning confirmed (
Subplans Removed), 0 rowsin
default, migration integrity intact, rollback copy retained./v1/packets/{id}deeplink + 404, date-range into historical months.relkindfix end-to-end: app auto-creates the current+2partition on startup.