Longest incident per service

ranking

Longest incident per service

PagerDuty Pandas Interview Question

A PagerDuty customer review opens with the single worst incident of the period, not the average, because the average is held down by the pages that resolved in ten minutes while the escalation everybody remembers ran for hours.

Using the incidents DataFrame, find each service, the incident_id of its longest incident, and how long that one took in hours as hours_open, rounded to 2 decimal places. Assign the answer to result.

Asked of

  • Data Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist

incidentsDataFrame20 rows

Column NameType
incident_idint64
servicestr
started_atstr
resolved_atstr
severitystr

incidentsExample Input

incident_idservicestarted_atresolved_atseverity
6001checkout-api2024-10-01 02:10:002024-10-01 03:40:00SEV2
6002checkout-api2024-10-01 03:05:002024-10-01 04:25:00SEV3
6003checkout-api2024-10-01 06:00:002024-10-01 06:45:00SEV1
6004checkout-api2024-10-02 09:30:002024-10-02 10:15:00SEV3
6005checkout-api2024-10-02 10:10:002024-10-02 11:50:00SEV2
6011billing-worker2024-10-01 12:00:002024-10-01 12:30:00SEV3
6012billing-worker2024-10-01 12:30:002024-10-01 13:15:00SEV2
6013billing-worker2024-10-01 15:40:002024-10-01 16:55:00SEV1
6014billing-worker2024-10-03 08:05:002024-10-03 08:35:00SEV3
6020checkout-api2024-10-04 07:00:002024-10-04 07:25:00SEV3

Example Output

serviceincident_idhours_open
billing-worker60131.25
checkout-api60051.67

Explanation

In the example the billing worker's longest incident is 6013, which ran an hour and a quarter. The checkout service has six incidents and 6005 is the longest at 1.67 hours, even though two of the others started earlier in the day.

The example above is a small slice of the data. Your code runs against the full DataFrames.