Signals

Failures in a rolling window

Implement the event selection behind a rolling error counter.

In production

A rolling error window drives burn alerts. Including future or stale events changes whether you page.

What it must return

Count only events whose timestamps sit inside the inclusive window ending at now.

  • Events contain timestamp (integer seconds) and status. Count 500–599 when now-window < timestamp <= now. Events may be unsorted. window is positive.
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Exclude timestamps older than the window start.
  • Exclude timestamps after now.
  • Write both boundaries before looping.

Signature

window_errors(events, now, window)

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

solution.py · Python

Loading editor…

Boundary and future

events

[
  {
    "timestamp": 90,
    "status": 500
  },
  {
    "timestamp": 91,
    "status": 500
  },
  {
    "timestamp": 100,
    "status": 503
  },
  {
    "timestamp": 101,
    "status": 500
  }
]

now

100

window

10

Expected

2

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 12 in Signals passed in Python on this device.

Next: Error budget left