Hotfixes: Revert `commit()` OpenTracing hackery (#11906)

pull/12117/head
reivilibre 2022-02-04 10:54:35 +00:00 committed by GitHub
parent 6705391eec
commit 3bf466698f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 39 deletions

View File

@ -41,7 +41,6 @@ from prometheus_client import Histogram
from typing_extensions import Literal from typing_extensions import Literal
from twisted.enterprise import adbapi from twisted.enterprise import adbapi
from twisted.python import reflect
from synapse.api.errors import StoreError from synapse.api.errors import StoreError
from synapse.config.database import DatabaseConnectionConfig from synapse.config.database import DatabaseConnectionConfig
@ -91,20 +90,6 @@ UNIQUE_INDEX_BACKGROUND_UPDATES = {
} }
class NastyConnectionWrapper:
def __init__(self, connection):
self._connection = connection
self._synapse_parent_context = None
def commit(self, *args, **kwargs):
with LoggingContext("db_commit", parent_context = self._synapse_parent_context):
with opentracing.start_active_span("db.conn.commit"):
self._connection.commit(*args, **kwargs)
def __getattr__(self, item):
return getattr(self._connection, item)
def make_pool( def make_pool(
reactor, db_config: DatabaseConnectionConfig, engine: BaseDatabaseEngine reactor, db_config: DatabaseConnectionConfig, engine: BaseDatabaseEngine
) -> adbapi.ConnectionPool: ) -> adbapi.ConnectionPool:
@ -120,28 +105,9 @@ def make_pool(
# etc. # etc.
with LoggingContext("db.on_new_connection"): with LoggingContext("db.on_new_connection"):
engine.on_new_connection( engine.on_new_connection(
LoggingDatabaseConnection( LoggingDatabaseConnection(conn, engine, "on_new_connection")
conn, engine, "on_new_connection"
)
) )
# HACK Patch the connection's commit function so that we can see
# how long it's taking from Jaeger. To do that, we need to patch the
# dbapi module's 'connect' method so that it returns a wrapped 'Connection'
# object to the connection pool. (psycopg2's Connection class is a C thing
# which we can't monkey-patch directly).
dbapiname = db_config.config["name"]
dbapi = reflect.namedModule(dbapiname)
if not getattr(dbapi, "_synapse_wrapped_dbapi", False):
real_connect = dbapi.connect
def wrapped_connect(*args, **kwargs):
conn = real_connect(*args, **kwargs)
return NastyConnectionWrapper(conn)
dbapi.connect = wrapped_connect
dbapi._synapse_wrapped_dbapi = True
connection_pool = adbapi.ConnectionPool( connection_pool = adbapi.ConnectionPool(
db_config.config["name"], db_config.config["name"],
cp_reactor=reactor, cp_reactor=reactor,
@ -839,10 +805,6 @@ class DatabasePool:
# pool). # pool).
assert not self.engine.in_transaction(conn) assert not self.engine.in_transaction(conn)
# HACK: record the parent context in 'conn' so that we can tie later commits
# back to it
conn._connection._synapse_parent_context = parent_context
with LoggingContext( with LoggingContext(
str(curr_context), parent_context=parent_context str(curr_context), parent_context=parent_context
) as context: ) as context: