Skip to content

feat(parquet): add a durable audit sink over the §3.7 Parquet stream - #111

Merged
jensholdgaard merged 1 commit into
mainfrom
feat/parquet-audit-sink
Jun 4, 2026
Merged

feat(parquet): add a durable audit sink over the §3.7 Parquet stream#111
jensholdgaard merged 1 commit into
mainfrom
feat/parquet-audit-sink

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented Jun 4, 2026

Copy link
Copy Markdown
Owner

What

A durable ParquetAuditSink (AuditSink) that persists audit events to the RFC 0005 §3.7 audit Parquet stream — the concrete sink the ourios-server binary will hand the compactor (chosen over a NoOp placeholder so compaction audit events actually land on disk).

Design

  • emit(event) derives the event's audit partition (tenant + UTC day, RFC 0005 §3.4) and writes a single-event file (audit/tenant_id=…/year=…/month=…/day=…/<uuid>.parquet) via AuditWriter.
  • Infallible emit (the AuditSink contract) → write failures bump a write_failures counter rather than propagating, surfaced there until the logging/metrics bootstrap (CLAUDE.md §6.3).
  • File-per-event is acceptable for the low-volume compaction audit stream (≤ one event per compacted partition per sweep). Batching + the §6.4 crash-ordering barrier come with the WAL-backed sink (RFC 0005 §3.7 / RFC 0008), which supersedes this best-effort pre-WAL persistence — and the §6.4 barrier is moot for compaction (it commits before its audit event).

RFC note

RFC 0005 §3.7 routes durable+ordered audit through the WAL (post-MVP). This sink provides best-effort persistence using the already-specified §3.7 format in the meantime — strictly better than the "in-memory until the WAL" status quo, without changing the format the WAL path will also write.

Test

Emit a compaction event → read it back byte-for-byte from its derived audit partition via AuditReader.

Verification

cargo fmt --all --check, cargo clippy --all-targets --all-features -D warnings, cargo test -p ourios-parquet --all-features — all green.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added persistent audit event storage in Parquet format for durable recording to a configured location.
    • Write failures are handled gracefully with internal tracking, ensuring operations continue reliably without interruption.

`ParquetAuditSink` implements `ourios_core::audit::AuditSink` by
writing each event to the RFC 0005 §3.7 audit Parquet stream: derive
the event's audit partition (tenant + UTC day) and write a single-event
file under `audit/tenant_id=…/year=…/month=…/day=…/`.

`emit` is infallible per the trait, so a write failure increments a
`write_failures` counter rather than propagating (surfaced there until
the logging/metrics bootstrap can report it). Single-event files are
fine for the low-volume compaction audit stream (≤ one event per
compacted partition per sweep); batching and the §6.4 crash-ordering
barrier arrive with the WAL-backed sink (RFC 0005 §3.7 / RFC 0008),
which supersedes this best-effort pre-WAL persistence — the barrier is
moot for compaction anyway (it commits before its audit event).

Test: emit a compaction event, then read it back byte-for-byte from
its derived audit partition via `AuditReader`.

Verification: cargo fmt --all --check, clippy --all-targets
--all-features -D warnings, cargo test -p ourios-parquet --all-features
— all green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jensholdgaard
jensholdgaard requested a review from Copilot June 4, 2026 19:55
@jensholdgaard

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f303db6-598b-4dc2-9075-7686566b3d52

📥 Commits

Reviewing files that changed from the base of the PR and between f77767c and 637ad51.

📒 Files selected for processing (2)
  • crates/ourios-parquet/src/audit_sink.rs
  • crates/ourios-parquet/src/lib.rs

📝 Walkthrough

Walkthrough

This PR adds ParquetAuditSink, a new trait implementation for durable audit event persistence. Each audit event is written as a single-event Parquet file in an RFC 0005 audit partition layout. Write failures are handled gracefully via saturating counter increments rather than error propagation. The new sink is tested end-to-end and exposed via the crate's public API.

Changes

Audit Event Persistence to Parquet

Layer / File(s) Summary
ParquetAuditSink struct and persistence logic
crates/ourios-parquet/src/audit_sink.rs
ParquetAuditSink struct holds bucket_root and a write_failures saturating counter. Constructor and write_failures() accessor provide initialization and monitoring. try_write() helper derives the audit partition from the event and uses AuditWriter to open, append the single event, and close. AuditSink::emit trait implementation calls try_write() and increments the counter on error without propagating.
Audit event persistence integration test
crates/ourios-parquet/src/audit_sink.rs
Test creates a temporary bucket, emits a fixed compaction audit event, verifies write_failures remains zero, derives the expected partition path, locates the single written .parquet file, reads all events back via AuditReader, and asserts byte-for-byte equality with the original event.
Public API module and re-export
crates/ourios-parquet/src/lib.rs
New audit_sink module declaration and ParquetAuditSink re-export extend the crate's public API surface for audit sink functionality.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • jensholdgaard/ourios#110: The main PR's new ParquetAuditSink implements the same AuditSink trait that this PR's Compactor uses to emit per-compaction AuditEvents, so the two changes are directly connected in the audit-event persistence/emission flow.
  • jensholdgaard/ourios#46: Main PR's new ParquetAuditSink writes each AuditEvent by opening/append/closing Parquet via the AuditWriter/partition layout introduced in this PR, tying the sink directly into that audit writer/reader codepath.

Poem

🐰 A Parquet sink hops forth so fine,
Each audit event in its rightful line,
Failures count up, but never break the flow,
Persistence blooms where audit events go! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a durable audit sink implementation over the RFC 0005 §3.7 Parquet stream format.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering the what, design rationale, RFC context, testing approach, and verification steps performed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/parquet-audit-sink

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jensholdgaard

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant