feat(storage): add Redis RESP mailbox store, durable WAL recovery, and Prometheus /metrics

Open
#6 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, prometheus, redis, rust

Research direction

Start with src/storage.rs (the NodeSnapshot capture code) and src/http_server.rs lines 105-265, where KeyTransparencyLog and RelayQueue live in memory. The work has three separable parts: WAL append and recovery, a RESP client in a new src/redis_store.rs, and a GET /metrics route. Done means tests/milestone6_test.rs passes, existing endpoint responses are unchanged, and cargo test is green. The issue is a multi-part feature tied to a coordinator meta-issue, so confirm scope with the maintainer before starting.

Written by the indexing model from the issue text.

Description

area::node effort::l impact::critical priority::critical source::user status::review type::feature

Problem

Tracked under Coordinator Meta-Issue alfonsodg/sonaraim#8 (Milestone 6).
In sonaraim-node (692a933), src/storage.rs:1-96 serializes point-in-time NodeSnapshot JSON lines in memory, and src/http_server.rs:105-265 stores KeyTransparencyLog and RelayQueue only in RAM without writing/recovering a durable write-ahead log (WAL) on disk, syncing mailbox TTLs with REDIS_URL, or exposing a Prometheus GET /metrics endpoint.

Affected Files & Locations

  • src/storage.rs:1-96
  • src/redis_store.rs (new, < 180 lines)
  • src/http_server.rs:105-265
  • src/lib.rs:1-14
  • tests/milestone6_test.rs (new)

Evidence

// src/storage.rs:25-40
pub struct NodeSnapshot {
    pub log_size: usize,
    pub tree_head: String,
}

impl NodeSnapshot {
    #[must_use]
    pub fn capture(log: &KeyTransparencyLog) -> Self {
        Self {
            log_size: log.len(),
            tree_head: log.tree_head(),
        }
    }

Impact and Blast Radius

Enables crash-recoverable Key Transparency identity logs, optional live Redis RESP mailbox persistence when REDIS_URL is reachable, and Prometheus metrics scraping (GET /metrics).

Historical Context and Anti-Regression

Builds on commit 692a933 (develop, Issues #1–#5 in status::review, 8/8 tests passing). All existing endpoints (/health, /v1/identity, /v1/relay/envelopes, /v1/relay/mailboxes/{id}, /v1/media/presign, /v1/contacts/psi) must preserve their exact response contracts.

Proposed Solution

  1. Extend src/storage.rs with file-backed WAL append and recovery (append_wal_entry, load_wal_entries) using the directory of NODE_SIGNING_KEY_PATH.
  2. Create src/redis_store.rs implementing a zero-dependency TCP RESP client (RedisRespClient) supporting AUTH, SET key val EX ttl, GET, and DEL against REDIS_URL.
  3. Add GET /metrics in src/http_server.rs returning Prometheus text metrics (sonaraim_node_kt_entries_total, sonaraim_node_queued_envelopes).

Acceptance Criteria

  • L1 (Unit TDD): cargo fmt --check && cargo clippy -- -D warnings && cargo test passes with all src/*.rs files < 300 lines.
  • L2 (Integration): WAL file recovery restores KeyTransparencyLog entries across NodeState re-initialization, and GET /metrics returns valid Prometheus counters.
  • L3 (Container / GHCR): ghcr.io/alfonsodg/sonaraim-node:develop builds in GitHub Actions and deploys on sandbox-ud-ord.
  • L4 (E2E Sandbox): curl -fsS http://127.0.0.1:8031/metrics on sandbox-ud-ord returns live counters matching registered identities.
Dominant language
Rust
Stars
0
Forks
0
Avg merge
4m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from alfonsodg/sonaraim-node

All issues in alfonsodg/sonaraim-node

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.