Audit logging in Elasticsearch - Time & Space Complexity
Audit logging in Elasticsearch tracks user actions and system events. Understanding time complexity helps us see how logging affects system speed as more events happen.
We want to know how the cost of logging grows when the number of events increases.
Analyze the time complexity of the following audit logging configuration snippet.
PUT /_cluster/settings
{
"persistent": {
"xpack.security.audit.enabled": true,
"xpack.security.audit.logfile.events.include": ["access_granted", "access_denied"]
}
}
This snippet enables audit logging for access granted and denied events in Elasticsearch.
Audit logging repeats for every event that matches the filter.
- Primary operation: Writing a log entry for each matching event.
- How many times: Once per relevant event occurring in the system.
As the number of events increases, the number of log writes grows at the same pace.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 events | 10 log writes |
| 100 events | 100 log writes |
| 1000 events | 1000 log writes |
Pattern observation: The work grows directly with the number of events logged.
Time Complexity: O(n)
This means the time to log grows linearly with the number of events to record.
[X] Wrong: "Audit logging happens once and does not depend on event count."
[OK] Correct: Each event triggers a logging action, so more events mean more logging work.
Knowing how audit logging scales helps you design systems that stay responsive even as activity grows. This skill shows you understand real-world system behavior.
"What if we added filters to log only error events? How would that change the time complexity?"