
Merged outage windows
hardMerged outage windows
Datadog SQL Interview Question
Datadog reports uptime to customers under a contract, so the number has to be minutes the service was actually down. Adding incident durations double counts every minute two alerts overlapped, which overstates the outage and can trigger a refund that was never owed.
Return one row per merged window: the service, the time it began as window_start, the time the service was finally healthy as window_end, and how many incidents it covers as incidents. A new window begins only when an incident starts after every earlier one on that service has been resolved. Sort by service and then by window_start.
Asked of
- Data Analyst
- Analytics Engineer
- Data Engineer
- Data Scientist
datadog_incidentsTable20 rows
| Column Name | Type |
|---|---|
| incident_id | BIGINT |
| service | VARCHAR |
| started_at | TIMESTAMP |
| resolved_at | TIMESTAMP |
| severity | VARCHAR |
datadog_incidentsExample Input
| incident_id | service | started_at | resolved_at | severity |
|---|---|---|---|---|
| 6001 | checkout-api | 2024-10-01 02:10:00 | 2024-10-01 03:40:00 | SEV2 |
| 6002 | checkout-api | 2024-10-01 03:05:00 | 2024-10-01 04:25:00 | SEV3 |
| 6003 | checkout-api | 2024-10-01 06:00:00 | 2024-10-01 06:45:00 | SEV1 |
| 6011 | billing-worker | 2024-10-01 12:00:00 | 2024-10-01 12:30:00 | SEV3 |
| 6012 | billing-worker | 2024-10-01 12:30:00 | 2024-10-01 13:15:00 | SEV2 |
| 6013 | billing-worker | 2024-10-01 15:40:00 | 2024-10-01 16:55:00 | SEV1 |
Example Output
| service | window_start | window_end | incidents |
|---|---|---|---|
| billing-worker | 2024-10-01 12:00:00 | 2024-10-01 13:15:00 | 2 |
| billing-worker | 2024-10-01 15:40:00 | 2024-10-01 16:55:00 | 1 |
| checkout-api | 2024-10-01 02:10:00 | 2024-10-01 04:25:00 | 2 |
| checkout-api | 2024-10-01 06:00:00 | 2024-10-01 06:45:00 | 1 |
Explanation
The two checkout incidents run into each other, so they merge into one window from 2:10 to 4:25 covering two incidents. The later one at 6:00 stands on its own. On the billing worker one incident ends exactly as the next begins, and since the service was never healthy in between those merge too.
The example above is a small slice of the data. Your query runs against the full tables.
Company
Datadog
Difficulty
hard
Topic
window functions
Language
SQL
Your query
Starting the SQL engine...