Skip to content
Snippets Groups Projects
Unverified Commit 464e5da7 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Add logging for redis connection setup (#9590)

parent e55bd0e1
No related branches found
No related tags found
No related merge requests found
Add logging for redis connection setup.
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
""" """
from typing import Any, List, Optional, Type, Union from typing import Any, List, Optional, Type, Union
from twisted.internet import protocol
class RedisProtocol: class RedisProtocol:
def publish(self, channel: str, message: bytes): ... def publish(self, channel: str, message: bytes): ...
async def ping(self) -> None: ... async def ping(self) -> None: ...
...@@ -52,7 +54,7 @@ def lazyConnection( ...@@ -52,7 +54,7 @@ def lazyConnection(
class ConnectionHandler: ... class ConnectionHandler: ...
class RedisFactory: class RedisFactory(protocol.ReconnectingClientFactory):
continueTrying: bool continueTrying: bool
handler: RedisProtocol handler: RedisProtocol
pool: List[RedisProtocol] pool: List[RedisProtocol]
......
...@@ -20,6 +20,10 @@ from typing import TYPE_CHECKING, Generic, Optional, Type, TypeVar, cast ...@@ -20,6 +20,10 @@ from typing import TYPE_CHECKING, Generic, Optional, Type, TypeVar, cast
import attr import attr
import txredisapi import txredisapi
from twisted.internet.address import IPv4Address, IPv6Address
from twisted.internet.interfaces import IAddress, IConnector
from twisted.python.failure import Failure
from synapse.logging.context import PreserveLoggingContext, make_deferred_yieldable from synapse.logging.context import PreserveLoggingContext, make_deferred_yieldable
from synapse.metrics.background_process_metrics import ( from synapse.metrics.background_process_metrics import (
BackgroundProcessLoggingContext, BackgroundProcessLoggingContext,
...@@ -253,6 +257,37 @@ class SynapseRedisFactory(txredisapi.RedisFactory): ...@@ -253,6 +257,37 @@ class SynapseRedisFactory(txredisapi.RedisFactory):
except Exception: except Exception:
logger.warning("Failed to send ping to a redis connection") logger.warning("Failed to send ping to a redis connection")
# ReconnectingClientFactory has some logging (if you enable `self.noisy`), but
# it's rubbish. We add our own here.
def startedConnecting(self, connector: IConnector):
logger.info(
"Connecting to redis server %s", format_address(connector.getDestination())
)
super().startedConnecting(connector)
def clientConnectionFailed(self, connector: IConnector, reason: Failure):
logger.info(
"Connection to redis server %s failed: %s",
format_address(connector.getDestination()),
reason.value,
)
super().clientConnectionFailed(connector, reason)
def clientConnectionLost(self, connector: IConnector, reason: Failure):
logger.info(
"Connection to redis server %s lost: %s",
format_address(connector.getDestination()),
reason.value,
)
super().clientConnectionLost(connector, reason)
def format_address(address: IAddress) -> str:
if isinstance(address, (IPv4Address, IPv6Address)):
return "%s:%i" % (address.host, address.port)
return str(address)
class RedisDirectTcpReplicationClientFactory(SynapseRedisFactory): class RedisDirectTcpReplicationClientFactory(SynapseRedisFactory):
"""This is a reconnecting factory that connects to redis and immediately """This is a reconnecting factory that connects to redis and immediately
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment