Log parsing is a staple of SRE interviews. You'll extract information from unstructured text.
Common tasks:
- Count occurrences of errors
- Extract timestamps and calculate durations
- Find the most frequent IP addresses
- Aggregate metrics by time window
Example: Count error types
from collections import Counter
errors = Counter()
with open('app.log') as f:
for line in f:
if 'ERROR' in line:
error_type = extract_error_type(line)
errors[error_type] += 1
Interview tip: Ask about log format before coding. Clarify what output is expected. Consider edge cases like malformed lines