Error Rate Monitor
MediumSliding Window · Netflix
A service emits status events events, each [timestamp, kind], in non-decreasing timestamp order. kind is a string; only the exact string "error" counts as an error.
After each event at time t, look at the rolling window: all events processed so far (including the current one) whose timestamp e satisfies t - e < window. Events at least window time units old have expired.
The window is alerting if the percentage of its events that are errors is at least threshold percent, i.e. 100 * errors >= threshold * total.
Return a list with one boolean per event, in order: True if the window is alerting right after that event, False otherwise.
Example 1
- Input:
- events = [[0, "ok"], [2, "error"], [3, "error"], [6, "ok"], [9, "ok"]], window = 5, threshold = 50
- Output:
- [False, True, True, True, False]
- Explanation
- At time 2 the window holds 1 error out of 2 events, exactly 50 percent, so it alerts. At time 6 the event at 0 has expired and 2 of the 3 events are errors. At time 9 only the events at 6 and 9 remain, neither an error.
Example 2
- Input:
- events = [[5, "error"], [5, "ok"], [5, "ok"]], window = 1, threshold = 40
- Output:
- [True, True, False]
- Explanation
- All three events share a timestamp, so they stay in the window together. The rate falls from 100 percent to 50 percent and then to 33 percent, which is below 40.
Example 3
- Input:
- events = [[0, "error"], [10, "ok"]], window = 10, threshold = 50
- Output:
- [True, False]
- Explanation
- At time 10 the error at time 0 is exactly 10 units old, so it has expired and the window holds only the
okevent.
Constraints
0 <= events.length <= 10^50 <= timestamp <= 10^9, timestamps are non-decreasing1 <= window <= 10^90 <= threshold <= 100