Skip to content
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
27 changes: 16 additions & 11 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ def _execute_command(self, target_node, *args, **kwargs):
self._record_command_metric(
command_name=command,
duration_seconds=time.monotonic() - start_time,
connection=connection,
connection=e.connection,
error=e,
)
raise
Expand All @@ -1576,7 +1576,7 @@ def _execute_command(self, target_node, *args, **kwargs):
self._record_command_metric(
command_name=command,
duration_seconds=time.monotonic() - start_time,
connection=connection,
connection=e.connection,
error=e,
)
raise
Expand Down Expand Up @@ -1615,11 +1615,10 @@ def _execute_command(self, target_node, *args, **kwargs):

# DON'T set redis_connection = None - keep the pool for reuse
self.nodes_manager.initialize()
e.connection = connection
self._record_command_metric(
command_name=command,
duration_seconds=time.monotonic() - start_time,
connection=connection,
connection=e.connection,
error=e,
)
raise e
Expand Down Expand Up @@ -1723,17 +1722,19 @@ def _execute_command(self, target_node, *args, **kwargs):
self._record_command_metric(
command_name=command,
duration_seconds=time.monotonic() - start_time,
connection=connection,
connection=e.connection,
error=e,
)
raise
except ResponseError as e:
# this is used to report the metrics based on host and port info
e.connection = connection
# ResponseError typically happens after get_connection() succeeds,
# so connection should be available
e.connection = connection if connection else target_node
self._record_command_metric(
command_name=command,
duration_seconds=time.monotonic() - start_time,
connection=connection,
connection=e.connection,
error=e,
)
raise
Expand All @@ -1748,7 +1749,7 @@ def _execute_command(self, target_node, *args, **kwargs):
self._record_command_metric(
command_name=command,
duration_seconds=time.monotonic() - start_time,
connection=connection,
connection=e.connection,
error=e,
)
raise e
Expand Down Expand Up @@ -1780,12 +1781,16 @@ def _record_command_metric(
"""
Records operation duration metric directly.
"""
host = connection.host if connection else "unknown"
port = connection.port if connection else 0
db = str(connection.db) if connection and hasattr(connection, "db") else "0"

record_operation_duration(
command_name=command_name,
duration_seconds=duration_seconds,
server_address=connection.host,
server_port=connection.port,
db_namespace=str(connection.db),
server_address=host,
server_port=port,
db_namespace=db,
error=error,
)

Expand Down
Loading
Loading