From 627913193554801271d171bc29e520f5dda5d072 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 22 Jan 2024 01:31:30 -0600 Subject: [PATCH 1/5] Install mysqltuner.pl dependencies --- images/mariadb/10.11.Dockerfile | 1 + images/mariadb/10.4.Dockerfile | 1 + images/mariadb/10.5.Dockerfile | 1 + images/mariadb/10.6.Dockerfile | 1 + 4 files changed, 4 insertions(+) diff --git a/images/mariadb/10.11.Dockerfile b/images/mariadb/10.11.Dockerfile index d5d24d582..869b81897 100644 --- a/images/mariadb/10.11.Dockerfile +++ b/images/mariadb/10.11.Dockerfile @@ -43,6 +43,7 @@ RUN apk update \ mariadb=~10.11 \ mariadb-connector-c \ net-tools \ + perl-doc \ pwgen \ rsync \ tar \ diff --git a/images/mariadb/10.4.Dockerfile b/images/mariadb/10.4.Dockerfile index bd695f20e..310a47c3f 100644 --- a/images/mariadb/10.4.Dockerfile +++ b/images/mariadb/10.4.Dockerfile @@ -43,6 +43,7 @@ RUN apk update \ mariadb=~10.4 \ mariadb-connector-c \ net-tools \ + perl-doc \ pwgen \ rsync \ tar \ diff --git a/images/mariadb/10.5.Dockerfile b/images/mariadb/10.5.Dockerfile index e4b491337..7cc7a62cd 100644 --- a/images/mariadb/10.5.Dockerfile +++ b/images/mariadb/10.5.Dockerfile @@ -43,6 +43,7 @@ RUN apk update \ mariadb=~10.5 \ mariadb-connector-c \ net-tools \ + perl-doc \ pwgen \ rsync \ tar \ diff --git a/images/mariadb/10.6.Dockerfile b/images/mariadb/10.6.Dockerfile index 8429b0124..5223d7a04 100644 --- a/images/mariadb/10.6.Dockerfile +++ b/images/mariadb/10.6.Dockerfile @@ -43,6 +43,7 @@ RUN apk update \ mariadb=~10.6 \ mariadb-connector-c \ net-tools \ + perl-doc \ pwgen \ rsync \ tar \ From a1cc9af5927c84ea6e5cae25de8dd72fe356d9d0 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 22 Jan 2024 01:31:31 -0600 Subject: [PATCH 2/5] Add MARIADB_PERFORMANCE_SCHEMA env var and config --- .../entrypoints/150-mariadb-performance.bash | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/images/mariadb/entrypoints/150-mariadb-performance.bash b/images/mariadb/entrypoints/150-mariadb-performance.bash index c8b73b2d4..eb9835cb7 100755 --- a/images/mariadb/entrypoints/150-mariadb-performance.bash +++ b/images/mariadb/entrypoints/150-mariadb-performance.bash @@ -10,4 +10,17 @@ if [ "$LAGOON_ENVIRONMENT_TYPE" == "production" ]; then if [ -z ${MARIADB_INNODB_LOG_FILE_SIZE+x} ]; then export MARIADB_INNODB_LOG_FILE_SIZE=256M fi -fi \ No newline at end of file +fi + +if [ -n "$MARIADB_PERFORMANCE_SCHEMA" ]; then + echo "Enabling performance schema" + cat < /etc/mysql/conf.d/performance-schema.cnf +[mysqld] +performance_schema=ON +performance-schema-instrument='stage/%=ON' +performance-schema-consumer-events-stages-current=ON +performance-schema-consumer-events-stages-history=ON +performance-schema-consumer-events-stages-history-long=ON +EOF + +fi From 810e8f803acb39775a77b8ad80bc18e2361973b7 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 22 Jan 2024 01:31:31 -0600 Subject: [PATCH 3/5] Add more env vars to configure mariadb slow query log --- images/mariadb/entrypoints/100-mariadb-logging.bash | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/images/mariadb/entrypoints/100-mariadb-logging.bash b/images/mariadb/entrypoints/100-mariadb-logging.bash index 976d9218a..a12729c8a 100755 --- a/images/mariadb/entrypoints/100-mariadb-logging.bash +++ b/images/mariadb/entrypoints/100-mariadb-logging.bash @@ -3,17 +3,20 @@ set -eo pipefail if [ -n "$MARIADB_LOG_SLOW" ]; then - echo "MARIADB_LOG_SLOW set, logging to /etc/mysql/conf.d/log-slow.cnf" + echo "MARIADB_LOG_SLOW set, logging to /var/log/mariadb-slow.log" cat < /etc/mysql/conf.d/log-slow.cnf [mysqld] +log-output=file slow_query_log = 1 slow_query_log_file = /var/log/mariadb-slow.log +long_query_time = ${MARIADB_LONG_QUERY_TIME:-10} +log_slow_rate_limit = ${MARIADB_LOG_SLOW_RATE_LIMIT:1} EOF fi if [ -n "$MARIADB_LOG_QUERIES" ]; then - echo "MARIADB_LOG_QUERIES set, logging to /etc/mysql/conf.d/log-queries.cnf" + echo "MARIADB_LOG_QUERIES set, logging to /var/log/mariadb-queries.log" cat < /etc/mysql/conf.d/log-queries.cnf [mysqld] From 806ecda87bf492d98898048caf8f87ef921e87fd Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Wed, 24 Jan 2024 08:52:29 +1100 Subject: [PATCH 4/5] add tests to slow query and performance schema --- helpers/TESTING_service_images_dockercompose.md | 12 ++++++++++++ helpers/services-docker-compose.yml | 5 +++++ images/mariadb/entrypoints/100-mariadb-logging.bash | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/helpers/TESTING_service_images_dockercompose.md b/helpers/TESTING_service_images_dockercompose.md index 9a04b043b..895d17e63 100644 --- a/helpers/TESTING_service_images_dockercompose.md +++ b/helpers/TESTING_service_images_dockercompose.md @@ -163,6 +163,12 @@ docker-compose exec -T mariadb-10-6 sh -c "mysql -V" | grep "10.6" # mariadb-10-6 should be version 10.6 server docker-compose exec -T mariadb-10-6 sh -c "mysql -e \'SHOW variables;\'" | grep "version" | grep "10.6" +# mariadb-10-6 should have performance schema and slow logging disabled +docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "performance_schema" | grep "OFF" +docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "slow_query_log" | grep "OFF" +docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "long_query_time" | grep "10" +docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "log_slow_rate_limit" | grep "1" + # mariadb-10-6 should use default credentials docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW databases;\'" | grep lagoon @@ -176,6 +182,12 @@ docker-compose exec -T mariadb-10-11 sh -c "mysql -V" | grep "10.11" # mariadb-10-11 should be version 10.11 server docker-compose exec -T mariadb-10-11 sh -c "mysql -e \'SHOW variables;\'" | grep "version" | grep "10.11" +# mariadb-10-11 should have performance schema and slow logging enabled +docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "performance_schema" | grep "ON" +docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "slow_query_log" | grep "ON" +docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "long_query_time" | grep "30" +docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "log_slow_rate_limit" | grep "5" + # mariadb-10-11 should use default credentials docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW databases;\'" | grep lagoon diff --git a/helpers/services-docker-compose.yml b/helpers/services-docker-compose.yml index 4b5d70958..ec66981dc 100644 --- a/helpers/services-docker-compose.yml +++ b/helpers/services-docker-compose.yml @@ -32,6 +32,11 @@ services: image: uselagoon/mariadb-10.11:latest ports: - "3306" + environment: + - MARIADB_PERFORMANCE_SCHEMA=true + - MARIADB_LOG_SLOW=true + - MARIADB_LONG_QUERY_TIME=30 + - MARIADB_LOG_SLOW_RATE_LIMIT=5 << : *default-user # uses the defined user from top mongo-4: diff --git a/images/mariadb/entrypoints/100-mariadb-logging.bash b/images/mariadb/entrypoints/100-mariadb-logging.bash index a12729c8a..37bdfbb17 100755 --- a/images/mariadb/entrypoints/100-mariadb-logging.bash +++ b/images/mariadb/entrypoints/100-mariadb-logging.bash @@ -10,7 +10,7 @@ log-output=file slow_query_log = 1 slow_query_log_file = /var/log/mariadb-slow.log long_query_time = ${MARIADB_LONG_QUERY_TIME:-10} -log_slow_rate_limit = ${MARIADB_LOG_SLOW_RATE_LIMIT:1} +log_slow_rate_limit = ${MARIADB_LOG_SLOW_RATE_LIMIT:-1} EOF fi From 29b0c9c52201be00e08780ca59ee498392622acc Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Wed, 24 Jan 2024 08:59:20 +1100 Subject: [PATCH 5/5] fix typo in slow query test --- helpers/TESTING_service_images_dockercompose.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers/TESTING_service_images_dockercompose.md b/helpers/TESTING_service_images_dockercompose.md index 895d17e63..bcfd15092 100644 --- a/helpers/TESTING_service_images_dockercompose.md +++ b/helpers/TESTING_service_images_dockercompose.md @@ -165,7 +165,7 @@ docker-compose exec -T mariadb-10-6 sh -c "mysql -e \'SHOW variables;\'" | grep # mariadb-10-6 should have performance schema and slow logging disabled docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "performance_schema" | grep "OFF" -docker-compose exec -T mariadb-10-11 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "slow_query_log" | grep "OFF" +docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "slow_query_log" | grep "OFF" docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "long_query_time" | grep "10" docker-compose exec -T mariadb-10-6 sh -c "mysql -D lagoon -u lagoon --password=lagoon -e \'SHOW GLOBAL VARIABLES;\'" | grep "log_slow_rate_limit" | grep "1"