Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/metrics/dlq_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Dead-Letter Queue (DLQ) Eviction Metric Counter
Maintains cumulative metric counters for failed or expired background task payloads.
"""
from typing import Dict, Any

class DLQEvictionCounter:
def __init__(self):
self._counts: Dict[str, int] = {}

def record_eviction(self, reason: str) -> None:
self._counts[reason] = self._counts.get(reason, 0) + 1

def get_metrics(self) -> Dict[str, Any]:
return {
"total_evictions": sum(self._counts.values()),
"by_reason": dict(self._counts)
}

if __name__ == "__main__":
c = DLQEvictionCounter()
c.record_eviction("TTL_EXPIRED")
c.record_eviction("TTL_EXPIRED")
c.record_eviction("MAX_RETRIES_EXCEEDED")
m = c.get_metrics()
assert m["total_evictions"] == 3
assert m["by_reason"]["TTL_EXPIRED"] == 2
print("DLQ eviction counter unit tests passed!")
Loading