feat(chaos): audit trail for injection events (#44)#245
Open
mvillmow wants to merge 1 commit into
Open
Conversation
Closes #44 Adds `ChaosAuditLog`, a header-only structured JSON-lines audit trail that records every chaos fault injection and removal so chaos test outcomes are no longer ephemeral. Each record captures timestamp (ISO-8601 UTC ms), action (inject|remove), fault_type, fault_id, target Agamemnon URL, HTTP status, requester identity, and the verbatim Agamemnon response body. Destination is controlled by `CHAOS_AUDIT_LOG` (file path; `-`/`stderr`/ unset emit to stderr). Requester identity comes from `CHAOS_AUDIT_REQUESTER`, falling back to `$USER` then "unknown". Emission is best-effort: a bad audit-log path falls back to stderr with a warning rather than failing the test, and writes are mutex-serialised so a single instance is safe across threads. `test_chaos_api.cpp` (E01-E04) is wired through `inject()` / `remove_fault()` helpers that emit audit records around every Agamemnon API call. Six new unit tests in `test_chaos_audit_unit.cpp` exercise envelope shape, inject/remove distinction, multi-line ordering, and stderr-fallback paths without requiring Agamemnon or NATS. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Closes #44. Adds
ChaosAuditLog, a header-only structured JSON-lines audit trail that records every chaos fault injection and removal so chaos test outcomes are no longer ephemeral.Each record captures:
timestamp— ISO-8601 UTC with millisecond precisionaction—inject|removefault_type—network-partition,latency,kill,queue-starve, ...fault_id— id returned by Agamemnontarget— Agamemnon base URL the fault was sent tostatus— HTTP status returned by Agamemnon (0 on transport failure)requester—CHAOS_AUDIT_REQUESTERenv, falling back to$USER, thenunknowndetails— verbatim Agamemnon response bodyschema_version—1Configuration
CHAOS_AUDIT_LOGstderr-,stderr, or unset emit to stderr. Any other value is appended to that file path.CHAOS_AUDIT_REQUESTER$USERorunknownrequesterfield.If the requested file path cannot be opened the class falls back to stderr with a one-line warning rather than crashing the test process — audit emission is best-effort telemetry and must never break a chaos test. Writes are mutex-serialised, so one instance is safe across threads.
Why a file-based JSONL log (not NATS)?
The issue body asks for persistence "to stderr or a dedicated file". A header-only JSONL emitter:
hi.logs.>Promtail pipeline by tailing the file (or capturing stderr from the test runner) — no nats.c FetchContent needed.A future ticket can layer NATS publishing on top by reusing the same envelope.
Changes
include/projectcharybdis/chaos_audit.hpp— new header-onlyChaosAuditLog.test/src/test_chaos_audit_unit.cpp— 6 unit tests covering envelope shape, inject vs remove, multi-line ordering, and stderr-fallback paths.test/src/test_chaos_api.cpp— E01–E04 routed throughinject()/remove_fault()helpers that emit audit records around every Agamemnon API call.cmake/SourcesAndHeaders.cmake,test/CMakeLists.txt— wire the new header and unit test into the build.README.md— documentsCHAOS_AUDIT_LOGandCHAOS_AUDIT_REQUESTER.Test plan
stddef.htoolchain issue on this host, unrelated to this PR — affects unchangedsrc/http_test_client.cpponmaintoo):ProjectCharybdis_testsandProjectCharybdis_integration_testsboth link clean.HttpTestClientUnit.MalformedUrlFallsBackToDefaults, fails onmaintoo on hosts where something happens to listen onlocalhost:8080).cmake --preset cibuild with-Werror, clang-tidy, cppcheck.🤖 Generated with Claude Code