A monitoring screen gets flooded when a broken service fires the same alert over and over. Build a filter that shows an alert, then hides any repeat of that exact text for the next 10 seconds.
Build AlertMuter() with one method:
should_show(t: int, message: str) -> bool: an alert with textmessagearrives at integer secondt. ReturnTrue(and show it) if this text has never been shown, or was last shown at a timeswiths + 10 <= t. Otherwise returnFalse.
Hidden alerts don't restart the 10 seconds: only shown ones do. Across all calls t never decreases, and several alerts can arrive in the same second.
m = AlertMuter()
m.should_show(1, "disk full") # True
m.should_show(2, "cpu hot") # True
m.should_show(3, "disk full") # False (shown at 1)
m.should_show(8, "cpu hot") # False
m.should_show(11, "disk full") # True (1 + 10 <= 11)
m.should_show(11, "disk full") # False (just shown at 11)
m.should_show(12, "cpu hot") # True
Up to 300,000 calls with many different messages. Each call should take O(1) time on average (plus the length of the message); don't scan the history.
Show hint
For each message you only need one number: when it was last shown.