SRE coding often involves transforming data between formats.
Common tasks:
- Parse CSV/JSON, output different format
- Aggregate metrics (sum, average, percentiles)
- Group data by key (time window, server, user)
- Filter and sort results
Example: Aggregate by time window
from collections import defaultdict
hourly_counts = defaultdict(int)
for entry in log_entries:
hour = entry['timestamp'][:13]
hourly_counts[hour] += 1
Interview tip: Think about memory usage. If processing large files, use streaming (line by line) instead of loading everything into memory.