From 36e504f21f0438d4ba9d2ec4341d848f7e836318 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Tue, 19 Nov 2019 10:44:24 -0800 Subject: [PATCH] integration: log slow queries and check for them (#4554) I couldn't get this to work cleanly with `--log-queries-not-using-indexes` because a couple of queries show up during integration test runs, seemingly because the tables involved are small enough that the optimizer finds it faster to skip the index. Some possible followups: - Allow list those queries, or - Preload the DB with a certain number of certificates before the start of testing. --- docker-compose.yml | 7 ++++++- test/integration-test.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 27977954a..ee7982762 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -73,7 +73,12 @@ services: - boulder-mysql environment: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" - command: mysqld --bind-address=0.0.0.0 + # Send slow queries to a table so we can check for them in the + # integration tests. For now we ignore queries not using indexes, + # because that seems to trigger based on the optimizer's choice to not + # use an index for certain queries, particularly when tables are still + # small. + command: mysqld --bind-address=0.0.0.0 --slow-query-log --log-output=TABLE --log-queries-not-using-indexes=OFF logging: driver: none netaccess: diff --git a/test/integration-test.py b/test/integration-test.py index 3c7ae30b7..99b3757a4 100644 --- a/test/integration-test.py +++ b/test/integration-test.py @@ -308,9 +308,22 @@ def main(): if not startservers.check(): raise Exception("startservers.check failed") + check_slow_queries() + global exit_status exit_status = 0 +def check_slow_queries(): + """Checks that we haven't run any slow queries during the integration test. + + This depends on flags set on mysqld in docker-compose.yml. + """ + output = run("mysql -h boulder-mysql -D boulder_sa_integration -e " + + "'select * from mysql.slow_log where user_host not like \"test_setup%\" \G'") + if len(output) > 0: + print(output) + raise Exception("Found slow queries in the slow query log") + def run_chisel(test_case_filter): for key, value in inspect.getmembers(v1_integration): if callable(value) and key.startswith('test_') and re.search(test_case_filter, key):