Skip to content

Commit

Permalink
feat(RHINENG-5449): add new prometheus metrics (#1613)
Browse files Browse the repository at this point in the history
* feat(RHINENG-5449): add new prometheus metrics

* fix utf8 typos

* Fix typo

---------

Co-authored-by: Asa Price <[email protected]>
  • Loading branch information
FabriciaDinizRH and kruai authored Feb 13, 2024
1 parent a4022a1 commit e682e88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/queue/event_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from app.instrumentation import message_not_produced
from app.instrumentation import message_produced
from app.logging import get_logger
from app.queue.metrics import produce_large_message_failure
from app.queue.metrics import produced_message_size

logger = get_logger(__name__)

Expand All @@ -27,8 +29,10 @@ def on_delivered(self, error, message):
if error:
if error.code() == KafkaError.MSG_SIZE_TOO_LARGE:
message_to_send = message
produce_large_message_failure.inc()
message_not_produced(logger, error, self.topic, self.event, self.key, self.headers, message_to_send)
else:
produced_message_size.observe(len(str(message).encode("utf-8")))
message_produced(logger, message, self.headers)


Expand Down
5 changes: 5 additions & 0 deletions app/queue/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
ingress_message_handler_time = Summary(
"inventory_ingress_message_handler_seconds", "Total time spent handling messages from the ingress queue"
)
consumed_message_size = Summary("inventory_consumed_message_size", "Size of incoming messages in bytes")
produced_message_size = Summary("inventory_produced_message_size", "Size of outgoing messages in bytes")
produce_large_message_failure = Counter(
"inventory_produce_large_message_failures", "Total amount of failures producing messages due to their size"
)
version = Info("inventory_mq_service_version", "Build version for the inventory message queue service")
version.info({"version": get_build_version()})
event_producer_success = Counter(
Expand Down
1 change: 1 addition & 0 deletions app/queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def event_loop(consumer, flask_app, event_producer, notification_event_producer,

try:
handler(msg.value(), event_producer, notification_event_producer=notification_event_producer)
metrics.consumed_message_size.observe(len(str(msg).encode("utf-8")))
metrics.ingress_message_handler_success.inc()
except OperationalError as oe:
"""sqlalchemy.exc.OperationalError: This error occurs when an
Expand Down

0 comments on commit e682e88

Please sign in to comment.