From ddd340edb570773236c681f495853224b980166f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ariel=20Gerardo=20R=C3=ADos?= Date: Wed, 2 Nov 2022 16:05:25 -0300 Subject: [PATCH] Adds metrics for origin and destination in message. --- docs/api.rst | 4 ++++ pysoa/common/transport/redis_gateway/server.py | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index eecfeb1..bcd48f5 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1124,6 +1124,8 @@ These are all the metrics recorded in PySOA: ``sentinel_failover_retries`` is enabled) - ``server.transport.redis_gateway.send``: A timer indicating how long it takes the Redis Gateway server transport to send a response +- ``server.transport.redis_gateway.send_context``: A counter with fields ``from`` and ``to`` detailing origin and + destination of the response, for usage instrumentation. - ``server.transport.redis_gateway.send.message_size``: A histogram indicating the total size of the response sent back to the client. - ``server.transport.redis_gateway.send.error.missing_reply_queue``: A counter incremented each time the Redis Gateway @@ -1152,6 +1154,8 @@ These are all the metrics recorded in PySOA: encounters an unknown error (logged) sending a message - ``server.transport.redis_gateway.receive``: A timer indicating how long it takes the Redis Gateway server transport to receive a response (however, this includes time waiting for an incoming request, so it may not be meaningful) +- ``server.transport.redis_gateway.receive_context``: A counter with fields ``from`` and ``to`` indicating the origin + and destination of it, for usage instrumentation. - ``server.transport.redis_gateway.receive.get_redis_connection``: A timer indicating how long it takes the Redis Gateway transport to get a connection to the Redis cluster or sentinel - ``server.transport.redis_gateway.receive.pop_from_redis_queue``: A timer indicating how long it takes the Redis diff --git a/pysoa/common/transport/redis_gateway/server.py b/pysoa/common/transport/redis_gateway/server.py index 31ebc8a..98b9d20 100644 --- a/pysoa/common/transport/redis_gateway/server.py +++ b/pysoa/common/transport/redis_gateway/server.py @@ -50,14 +50,21 @@ def receive_request_message(self): timer = self.metrics.timer('server.transport.redis_gateway.receive', resolution=TimerResolution.MICROSECONDS) timer.start() stop_timer = True + message = None try: - return self.core.receive_message(self._receive_queue_name) + message = self.core.receive_message(self._receive_queue_name) except MessageReceiveTimeout: stop_timer = False raise finally: if stop_timer: timer.stop() + if message: + self.metrics.counter('server.transport.redis_gateway.receive_context', tags={ + 'from': message.meta['reply_to'], + 'to': self.service_name, + }).increment() + return message def send_response_message(self, request_id, meta, body): # type: (int, Dict[six.text_type, Any], Dict[six.text_type, Any]) -> None @@ -69,3 +76,8 @@ def send_response_message(self, request_id, meta, body): with self.metrics.timer('server.transport.redis_gateway.send', resolution=TimerResolution.MICROSECONDS): self.core.send_message(queue_name, request_id, meta, body) + + self.metrics.counter('server.transport.redis_gateway.send_context', tags={ + 'from': self.service_name, + 'to': queue_name, + }).increment()