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

ref(metrics): Add pause/resume counters [INC-626] #338

Merged
merged 2 commits into from
Feb 9, 2024
Merged
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
4 changes: 4 additions & 0 deletions arroyo/processing/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class InvalidStateError(RuntimeError):
ConsumerCounter = Literal[
"arroyo.consumer.run.count",
"arroyo.consumer.invalid_message.count",
"arroyo.consumer.pause",
"arroyo.consumer.resume",
]


Expand Down Expand Up @@ -421,6 +423,7 @@ def _run_once(self) -> None:
elif not self.__is_paused and (
time.time() - self.__backpressure_timestamp > 1
):
self.__metrics_buffer.incr_counter("arroyo.consumer.pause", 1)
logger.debug(
"Caught %r while submitting %r, pausing consumer...",
e,
Expand All @@ -438,6 +441,7 @@ def _run_once(self) -> None:
else:
# Resume if we are currently in a paused state
if self.__is_paused:
self.__metrics_buffer.incr_counter("arroyo.consumer.resume", 1)
self.__consumer.resume([*self.__consumer.tell().keys()])
self.__is_paused = False

Expand Down
8 changes: 8 additions & 0 deletions arroyo/utils/metric_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
# Time (unitless) spent in shutting down the consumer. This metric's
# Consumer latency in seconds. Recorded by the commit offsets strategy.
"arroyo.consumer.latency",
# Counter metric for when the underlying rdkafka consumer is being paused.
#
# This flushes internal prefetch buffers.
"arroyo.consumer.pause",
# Counter metric for when the underlying rdkafka consumer is being resumed.
#
# This might cause increased network usage as messages are being re-fetched.
"arroyo.consumer.resume",
# Queue size of background queue that librdkafka uses to prefetch messages.
"arroyo.consumer.librdkafka.total_queue_size",
# Counter metric to measure how often the healthcheck file has been touched.
Expand Down
2 changes: 2 additions & 0 deletions tests/processing/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def test_stream_processor_lifecycle() -> None:
(Timing, "arroyo.consumer.shutdown.time"),
(Timing, "arroyo.consumer.callback.time"),
(Timing, "arroyo.consumer.poll.time"),
(Increment, "arroyo.consumer.pause"),
Copy link
Member Author

@untitaker untitaker Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random thought: i think this test is kind of bs and annoying when i just want to add a metric, but at teh same time it's somewhat interesting to see that we apply backpressure when a consumer is shutting down

(Increment, "arroyo.consumer.run.count"),
(Increment, "arroyo.consumer.resume"),
]


Expand Down
Loading