-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat(TaskProducer): add metrics on queue size #681
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| from arroyo.types import BrokerValue, Topic | ||
|
|
||
| from taskbroker_client.constants import TASK_PRODUCER_MAX_PENDING_FUTURES | ||
| from taskbroker_client.metrics import MetricsBackend, NoOpMetricsBackend | ||
| from taskbroker_client.types import ProducerProtocol | ||
|
|
||
| # This is global as TaskWorker needs to be able to call TaskProducer.collect_futures() | ||
|
|
@@ -29,12 +30,22 @@ class TaskProducer: | |
| Otherwise, the activation will be retried. | ||
|
|
||
| Args: | ||
| name: Unique identifying name of this TaskProducer. Used in metric tags. | ||
| producer_factory: Callable that returns a producer object. | ||
| metrics_backend: Application metrics backend this producer should use. | ||
| Defaults to NoOpMetricsBackend. | ||
| """ | ||
|
|
||
| def __init__(self, producer_factory: Callable[[], ProducerProtocol]) -> None: | ||
| def __init__( | ||
| self, | ||
| name: str, | ||
| producer_factory: Callable[[], ProducerProtocol], | ||
| metrics_backend: MetricsBackend | None = None, | ||
| ) -> None: | ||
| self.name = name | ||
| self._producer_factory = producer_factory | ||
| self._inner_producer: ProducerProtocol | None = None | ||
| self.metrics = metrics_backend if metrics_backend is not None else NoOpMetricsBackend() | ||
|
|
||
| def _get(self) -> ProducerProtocol: | ||
| if self._inner_producer is None: | ||
|
|
@@ -43,6 +54,11 @@ def _get(self) -> ProducerProtocol: | |
|
|
||
| def track_future(self, future: ProducerFuture[BrokerValue[KafkaPayload]]) -> None: | ||
| _pending_futures.append(future) | ||
| self.metrics.gauge( | ||
| "task.producer.pending.futures", | ||
| len(_pending_futures), | ||
| tags={"producer_name": self.name}, | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Producer tag omits other producersMedium Severity The gauge uses Reviewed by Cursor Bugbot for commit 383993e. Configure here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| @staticmethod | ||
| def collect_futures() -> set[ProducerFuture[BrokerValue[KafkaPayload]]]: | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gauge stale after queue cleared
Medium Severity
task.producer.pending.futuresis updated only intrack_futurewhen a future is appended, butcollect_futuresclears_pending_futureswithout recording a gauge. After each activation (including when the queue is empty), dashboards can still show the last non-zero size and trigger false queue-pressure alerts.Additional Locations (1)
clients/python/src/taskbroker_client/worker/producer.py#L54-L61Reviewed by Cursor Bugbot for commit 383993e. Configure here.