Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlq: Add metrics on DLQ buffer to python-arroyo #426

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion arroyo/dlq.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TStrategyPayload,
Value,
)
from arroyo.utils.metrics import get_metrics

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -287,6 +288,11 @@ def __init__(self, dlq_policy: Optional[DlqPolicy[TStrategyPayload]]) -> None:
self.__buffered_messages: MutableMapping[
Partition, Deque[BrokerValue[TStrategyPayload]]
] = defaultdict(deque)
self.__metrics = get_metrics()

def report_partition_metrics(self, buffered: Deque[BrokerValue[TStrategyPayload]]) -> None:

self.__metrics.gauge("arroyo.consumer.dlq_buffer.len", len(buffered))

def append(self, message: BrokerValue[TStrategyPayload]) -> None:
"""
Expand All @@ -304,6 +310,7 @@ def append(self, message: BrokerValue[TStrategyPayload]) -> None:
buffered.popleft()

self.__buffered_messages[message.partition].append(message)
self.report_partition_metrics(self.__buffered_messages[message.partition])

def pop(
self, partition: Partition, offset: int
Expand All @@ -317,9 +324,14 @@ def pop(

while buffered:
if buffered[0].offset == offset:
return buffered.popleft()
msg = buffered.popleft()
self.report_partition_metrics(buffered)
return msg
if buffered[0].offset > offset:
self.report_partition_metrics(buffered)
break

self.report_partition_metrics(buffered)
self.__buffered_messages[partition].popleft()

return None
Expand Down
3 changes: 2 additions & 1 deletion arroyo/utils/metric_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@
"arroyo.strategies.filter.dropped_messages",
# Counter: how many messages are dropped due to errors producing to the dlq
"arroyo.consumer.dlq.dropped_messages",

# Gauge: Current length of the DLQ buffer deque
"arroyo.consumer.dlq_buffer.len",
]