Skip to content

Commit

Permalink
Conditional show of slow SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Dec 16, 2019
1 parent af325c4 commit a26f1a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion data/src/entity_mysql/system.py
Expand Up @@ -158,6 +158,7 @@ def connect(self, connection, parameters = {}):
database = colony.conf("DB_NAME", database)
isolation = colony.conf("DB_ISOLATION", isolation)
show_sql = colony.conf("SHOW_SQL", False)
show_slow_sql = colony.conf("SHOW_SLOW_SQL", True)
connection._connection = MysqlConnection(
host = host,
user = user,
Expand All @@ -171,6 +172,7 @@ def connect(self, connection, parameters = {}):
connection._database = database
connection._isolation = isolation
connection._show_sql = show_sql
connection._show_slow_sql = show_slow_sql
connection.open()

def disconnect(self, connection):
Expand Down Expand Up @@ -404,7 +406,8 @@ def execute_query(self, query, cursor = None, retries = 3):
# message as this may condition the way the system behaves
delta = int((final - initial) * 1000)
is_slow = delta > SLOW_QUERY_TIME
if is_slow: self.mysql_system.info("[%s] [%s] [%d ms] %s" % (ENGINE_NAME, database, delta, query))
if is_slow and connection._show_slow_sql:
self.mysql_system.info("[%s] [%s] [%d ms] %s" % (ENGINE_NAME, database, delta, query))

# triggers a notification about the SQL query execution that
# has just been performed (should contain also the time in ms)
Expand Down
5 changes: 4 additions & 1 deletion data/src/entity_pgsql/system.py
Expand Up @@ -145,6 +145,7 @@ def connect(self, connection, parameters = {}):
database = colony.conf("DB_NAME", database)
isolation = colony.conf("DB_ISOLATION", isolation)
show_sql = colony.conf("SHOW_SQL", False)
show_slow_sql = colony.conf("SHOW_SLOW_SQL", True)
connection._connection = PgsqlConnection(
host = host,
user = user,
Expand All @@ -158,6 +159,7 @@ def connect(self, connection, parameters = {}):
connection._database = database
connection._isolation = isolation
connection._show_sql = show_sql
connection._show_slow_sql = show_slow_sql
connection.open()

def disconnect(self, connection):
Expand Down Expand Up @@ -368,7 +370,8 @@ def execute_query(self, query, cursor = None):
# message as this may condition the way the system behaves
delta = int((final - initial) * 1000)
is_slow = delta > SLOW_QUERY_TIME
if is_slow: self.pgsql_system.info("[%s] [%s] [%d ms] %s" % (ENGINE_NAME, database, delta, query))
if is_slow and connection._show_slow_sql:
self.pgsql_system.info("[%s] [%s] [%d ms] %s" % (ENGINE_NAME, database, delta, query))

# triggers a notification about the SQL query execution that
# has just been performed (should contain also the time in ms)
Expand Down
5 changes: 4 additions & 1 deletion data/src/entity_sqlite/system.py
Expand Up @@ -117,6 +117,7 @@ def connect(self, connection, parameters = {}):
cache_size = parameters.get("cache_size", 200000)
synchronous = parameters.get("synchronous", 2)
show_sql = colony.conf("SHOW_SQL", False)
show_slow_sql = colony.conf("SHOW_SLOW_SQL", True)
file_path = colony.conf("DB_FILE", file_path)
file_path = file_path or self._get_temporary()
connection._connection = SqliteConnection(
Expand All @@ -125,6 +126,7 @@ def connect(self, connection, parameters = {}):
synchronous = synchronous
)
connection._show_sql = show_sql
connection._show_slow_sql = show_slow_sql
connection.open()

def disconnect(self, connection):
Expand Down Expand Up @@ -281,7 +283,8 @@ def execute_query(self, query, cursor = None):
# message as this may condition the way the system behaves
delta = int((final - initial) * 1000)
is_slow = delta > SLOW_QUERY_TIME
if is_slow: self.sqlite_system.info("[%s] [%s] [%d ms] %s" % (ENGINE_NAME, database, delta, query))
if is_slow and connection._show_slow_sql:
self.sqlite_system.info("[%s] [%s] [%d ms] %s" % (ENGINE_NAME, database, delta, query))

# triggers a notification about the SQL query execution that
# has just been performed (should contain also the time in ms)
Expand Down

0 comments on commit a26f1a6

Please sign in to comment.