Skip to content

feat: add feature flag state change audit log for compliance traceability#915

Open
Xaxxoo wants to merge 1 commit into
rinafcode:mainfrom
Xaxxoo:feat/858-feature-flag-audit
Open

feat: add feature flag state change audit log for compliance traceability#915
Xaxxoo wants to merge 1 commit into
rinafcode:mainfrom
Xaxxoo:feat/858-feature-flag-audit

Conversation

@Xaxxoo

@Xaxxoo Xaxxoo commented Jun 27, 2026

Copy link
Copy Markdown

Closes #858

Summary

  • Creates FeatureFlagAuditService (src/config/feature-flag-audit.service.ts) that wraps runtime flag reads and writes with a full audit trail
  • On startup, in-process state is seeded from environment variables via loadFeatureFlags()
  • setFlag(key, value, actor) updates the runtime value, records old→new diff, and emits a CONFIG_CHANGED entry to AuditLogService (actor ID, email, entity type FeatureFlag, diff payload)
  • Audit log failures are swallowed and logged — a broken audit store never blocks a flag toggle
  • Ring buffer keeps the last 100 changes in memory (FeatureFlagAuditService.MAX_HISTORY)
  • FeatureFlagAuditController exposes three admin-only endpoints:
    • GET /feature-flags — current state snapshot
    • GET /feature-flags/audit — last 100 changes for compliance review
    • PATCH /feature-flags/:key — runtime toggle with immediate audit emission
  • FeatureFlagAuditModule imports AuditLogModule and is registered in AppModule

Test plan

  • getFlag returns initial value from env config
  • setFlag updates runtime state
  • setFlag records change in audit history with old/new values
  • logDataChange is called on every toggle
  • Each separate toggle emits its own audit entry
  • Service does not throw when AuditLogService fails
  • History is returned newest-first
  • History is capped at MAX_HISTORY (100) entries
  • getAuditHistory() returns an immutable snapshot
  • All 12 unit tests pass (npm test)

…de#858)

Introduce FeatureFlagAuditService that wraps runtime feature flag reads
and writes with a full audit trail.

- Initialises in-process flag state from environment variables at startup
- setFlag() updates the runtime value and emits a CONFIG_CHANGED entry
  via AuditLogService (actor, old value, new value, timestamp)
- Maintains a ring buffer of the last 100 changes (MAX_HISTORY)
- Audit log failure is caught and logged so it never interrupts a toggle
- Expose GET /feature-flags/audit (admin-only) returning the change history
- Expose GET /feature-flags for a current-state snapshot
- Expose PATCH /feature-flags/:key for runtime toggling with audit trail
- Register FeatureFlagAuditModule in AppModule
- 12 unit tests covering reads, writes, audit emission, failure isolation,
  ring-buffer capping, and snapshot immutability
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@Xaxxoo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Great job so far

There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass?

Happy to review again once that’s done.

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.

Add feature flag state change audit log for compliance traceability

2 participants