Sampling
Retention and sampling are core control mechanisms in AuditAuth observability.
They determine:
- Whether data is stored
- How long data is retained
- How much data is ingested
Both mechanisms are plan-aware and applied at ingestion time.
Ingestion-Time Enforcement
Retention and sampling are evaluated before persistence.
When a metric is received:
- Plan configuration is resolved.
feature_access.metricsis checked.metrics.retention_daysis evaluated.metrics.samplingis applied.expires_atis computed.- Event is persisted or discarded.
There is no post-processing enforcement layer.
All decisions occur deterministically during ingestion.
Retention Model
Retention is defined by:
metrics.retention_days
auditlog.retention_daysFor each stored event:
expires_atis calculated at creation time.- A TTL index on
expires_atenforces deletion.
Deletion characteristics:
- Physical deletion
- Automatic via MongoDB TTL monitor
- No custom cleanup worker
- No logical-only filtering
When retention_days = 0:
- Events are not stored.
Retention applies only to newly ingested events.
Historical expiration timestamps are not recalculated on plan change.
Sampling Model
Sampling is defined by:
metrics.samplingSampling characteristics:
- Applied at ingestion time
- Probabilistic
- Based on
Math.random() - Evaluated per event
If sampling = 0:
- Metrics are not stored.
If sampling < 1:
- A subset of events is stored.
Sampling:
- Is not deterministic per session
- Is not stored in event metadata
- Does not affect historical events
- Applies only to new events after plan change
Sampling reduces storage and aggregation load.
Plan Upgrade Behavior
When plan is upgraded:
- New retention_days apply to new events.
- New sampling rate applies to new events.
- Historical events keep their original
expires_at.
Retention extension is not retroactive.
Sampling increase does not restore discarded events.
Plan Downgrade Behavior
When plan is downgraded:
- New retention_days apply to new events.
- New sampling rate applies to new events.
- Historical events retain original expiration.
Dashboard visibility may change based on:
feature_access.dashboard_*Stored data may still exist but become inaccessible via UI.
Audit Log Retention
Audit logs follow similar retention logic:
auditlog.retention_days- TTL-based deletion
Audit logs are never sampled.
They are always stored (subject to retention > 0).
Audit logs may contain PII.
Retention enforcement ensures bounded governance storage.
Enforcement Guarantees
Retention & sampling provide:
- Predictable storage limits
- Plan-bound observability
- Deterministic ingestion behavior
- No background reconciliation
They do not provide:
- Retroactive retention extension
- Historical sampling recalculation
- Multi-tier storage migration
The system favors simplicity and deterministic rules.
Operational Implications
Retention and sampling impact:
- Storage footprint
- Dashboard fidelity
- Aggregation accuracy
- Long-term trend analysis
Applications requiring high-fidelity analytics should:
- Use higher-tier plans
- Avoid aggressive sampling
- Export data externally if needed
AuditAuth observability is designed to complement, not replace, full analytics platforms.
Next Step
To understand how sessions and requests are aggregated and interpreted, continue with:
- Session & Request Analytics