
Quiet time between incidents
mediumQuiet time between incidents
Datadog SQL Interview Question
Datadog tracks how long a service stays quiet between pages, because a service that fails every two hours needs a rewrite while one that fails every two months needs a runbook. The gap is measured from one incident starting to the next one starting on the same service.
Return the service, the incident_id, when it began as started_at, and the hours since the previous incident on that service began as hours_since_previous, rounded to 2 decimal places. The first incident on a service has nothing before it, so leave its gap empty. Sort by service and then by started_at.
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 | incident_id | started_at | hours_since_previous |
|---|---|---|---|
| billing-worker | 6011 | 2024-10-01 12:00:00 | NULL |
| billing-worker | 6012 | 2024-10-01 12:30:00 | 0.5 |
| billing-worker | 6013 | 2024-10-01 15:40:00 | 3.17 |
| checkout-api | 6001 | 2024-10-01 02:10:00 | NULL |
| checkout-api | 6002 | 2024-10-01 03:05:00 | 0.92 |
| checkout-api | 6003 | 2024-10-01 06:00:00 | 2.92 |
Explanation
The first incident on each service has nothing before it, so its gap is empty. On the billing worker the second began 30 minutes after the first, which is 0.5 hours, and the third came 3.17 hours after that.
The example above is a small slice of the data. Your query runs against the full tables.
Company
Datadog
Difficulty
medium
Topic
window functions
Language
SQL
Your query
Starting the SQL engine...