Skip to content

Commit ccc92ec

Browse files
authored
Merge pull request #10 from mackerelio/add-integration-test-1
add tests/read-replica-mysql8
2 parents d6a364d + 782522d commit ccc92ec

11 files changed

Lines changed: 237 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mackerel-plugin-mysql
2+
bin/*

test.sh

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,31 @@
11
#!/bin/sh
22

3-
go install github.com/lufia/graphitemetrictest/cmd/graphite-metric-test@latest || exit
3+
set -eu
44

5-
prog=$(basename "$0")
6-
if ! [ -S /var/run/docker.sock ]
7-
then
8-
echo "$prog: there are no running docker" >&2
9-
exit 2
10-
fi
5+
cd $(dirname "$0")
116

12-
cd "$(dirname "$0")" || exit
13-
PATH=$(pwd):$PATH
14-
plugin=$(basename "$(pwd)")
15-
if ! which "$plugin" >/dev/null
16-
then
17-
echo "$prog: $plugin is not installed" >&2
18-
exit 2
19-
fi
7+
mkdir -p bin
8+
export GOBIN="$(pwd)/bin"
9+
export PATH=$GOBIN:$PATH
10+
go install github.com/lufia/graphitemetrictest/cmd/graphite-metric-test@latest
11+
go build -o "$GOBIN/mackerel-plugin-mysql" github.com/mackerelio/mackerel-plugin-mysql
2012

21-
password=passpass
22-
port=13306
23-
image=mysql:8
24-
rule=rule_mysql8_extend.txt
13+
runtest()
14+
{
15+
local d=$(dirname "$1")
16+
local f=$(basename "$1")
17+
(cd "$d" && ./"$f")
18+
}
2519

26-
docker run -d \
27-
--name "test-$plugin" \
28-
-p $port:3306 \
29-
-e MYSQL_ROOT_PASSWORD=$password \
30-
"$image" --default-authentication-plugin=mysql_native_password
31-
trap 'docker stop test-$plugin; docker rm test-$plugin; exit' 1 2 3 15 EXIT
32-
sleep 10
33-
34-
#export MACKEREL_PLUGIN_WORKDIR=tmp
35-
36-
# wait until bootstrap mysqld..
37-
for i in $(seq 5)
20+
failtests=0
21+
for i in tests/*/test.sh
3822
do
39-
echo "Connecting $i..."
40-
if $plugin -port $port -password $password -enable_extended >/dev/null 2>&1
23+
if runtest "$i"
4124
then
42-
break
25+
echo "$i: OK"
26+
else
27+
echo "$i: FAIL"
28+
failtests=1
4329
fi
44-
sleep 3
4530
done
46-
sleep 1
47-
48-
# to store previous value to calculate a diff of metrics
49-
$plugin -port $port -password $password -enable_extended >/dev/null 2>&1
50-
sleep 1
51-
52-
$plugin -port $port -password $password -enable_extended | graphite-metric-test -f "$rule"
31+
exit $failtests
File renamed without changes.

tests/extend-mysql8/test.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
prog=$(basename "$0")
4+
if ! [ -S /var/run/docker.sock ]
5+
then
6+
echo "$prog: there are no running docker" >&2
7+
exit 2
8+
fi
9+
10+
cd "$(dirname "$0")" || exit
11+
PATH=$(pwd):$PATH
12+
plugin=mackerel-plugin-mysql
13+
if ! which "$plugin" >/dev/null
14+
then
15+
echo "$prog: $plugin is not installed" >&2
16+
exit 2
17+
fi
18+
19+
password=passpass
20+
port=13306
21+
image=mysql:8
22+
rule=rule_mysql8_extend.txt
23+
24+
docker run -d \
25+
--name "test-$plugin" \
26+
-p $port:3306 \
27+
-e MYSQL_ROOT_PASSWORD=$password \
28+
"$image" --default-authentication-plugin=mysql_native_password
29+
trap 'docker stop test-$plugin; docker rm test-$plugin; exit' 1 2 3 15 EXIT
30+
sleep 10
31+
32+
#export MACKEREL_PLUGIN_WORKDIR=tmp
33+
34+
# wait until bootstrap mysqld..
35+
for i in $(seq 5)
36+
do
37+
echo "Connecting $i..."
38+
if $plugin -port $port -password $password -enable_extended >/dev/null 2>&1
39+
then
40+
break
41+
fi
42+
sleep 3
43+
done
44+
sleep 1
45+
46+
# to store previous value to calculate a diff of metrics
47+
$plugin -port $port -password $password -enable_extended >/dev/null 2>&1
48+
sleep 1
49+
50+
$plugin -port $port -password $password -enable_extended | graphite-metric-test -f "$rule"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3'
2+
services:
3+
sourcedb:
4+
hostname: sourcedb
5+
image: mysql:8
6+
ports:
7+
- '3306:3306'
8+
environment:
9+
MYSQL_ROOT_PASSWORD: passpass
10+
MYSQL_USER: test
11+
MYSQL_PASSWORD: passpass
12+
volumes:
13+
- ./sourcedb/init.d:/docker-entrypoint-initdb.d
14+
- ./sourcedb/conf.d:/etc/mysql/conf.d
15+
replicadb:
16+
hostname: replicadb
17+
image: mysql:8
18+
ports:
19+
- '3307:3306'
20+
environment:
21+
MYSQL_ROOT_PASSWORD: passpass
22+
volumes:
23+
- ./replicadb/init.d:/docker-entrypoint-initdb.d
24+
- ./replicadb/conf.d:/etc/mysql/conf.d
25+
depends_on:
26+
- sourcedb
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mysqld]
2+
server-id = 2
3+
log-bin
4+
enforce-gtid-consistency=ON
5+
gtid-mode=ON
6+
read_only
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CHANGE REPLICATION SOURCE TO SOURCE_HOST='sourcedb',
2+
SOURCE_PORT=3306,
3+
SOURCE_USER='replica',
4+
SOURCE_PASSWORD='replica',
5+
SOURCE_AUTO_POSITION = 1,
6+
SOURCE_SSL = 1;
7+
8+
START REPLICA;

tests/read-replica-mysql8/rule.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
mysql.innodb_buffer_pool.pool_size >=0
2+
mysql.innodb_buffer_pool.database_pages >=0
3+
mysql.innodb_buffer_pool.free_pages >=0
4+
mysql.innodb_buffer_pool.modified_pages >=0
5+
mysql.innodb_io_pending.pending_normal_aio_reads >=0
6+
mysql.innodb_io_pending.pending_normal_aio_writes >=0
7+
mysql.innodb_io_pending.pending_log_flushes >=0
8+
mysql.innodb_io_pending.pending_buf_pool_flushes >=0
9+
mysql.innodb_log.log_bytes_written >=0
10+
mysql.innodb_log.log_bytes_flushed >=0
11+
mysql.innodb_log.unflushed_log >=0
12+
mysql.innodb_log.innodb_log_buffer_size >=0
13+
mysql.innodb_row_lock_waits.Innodb_row_lock_waits >=0
14+
mysql.innodb_buffer_pool_read.read_ahead >=0
15+
mysql.innodb_buffer_pool_read.read_evicted >=0
16+
mysql.innodb_buffer_pool_read.read_random_ahead >=0
17+
mysql.innodb_transactions.history_list >=0
18+
mysql.innodb_transactions.innodb_transactions >=0
19+
mysql.connections.max_connections >=0
20+
mysql.connections.Max_used_connections >=0
21+
mysql.connections.Connections >=0
22+
mysql.connections.Threads_connected >=0
23+
mysql.connections.Aborted_clients >=0
24+
mysql.connections.Aborted_connects >=0
25+
mysql.innodb_rows.Innodb_rows_read >=0
26+
mysql.innodb_rows.Innodb_rows_inserted >=0
27+
mysql.innodb_rows.Innodb_rows_updated >=0
28+
mysql.innodb_rows.Innodb_rows_deleted >=0
29+
mysql.innodb_checkpoint_age.uncheckpointed_bytes >=0
30+
mysql.innodb_insert_buffer.ibuf_inserts >=0
31+
mysql.innodb_insert_buffer.ibuf_merges >=0
32+
mysql.innodb_insert_buffer.ibuf_merged >=0
33+
mysql.capacity.PercentageOfConnections >=0
34+
mysql.capacity.PercentageOfBufferPool >=0
35+
mysql.innodb_row_lock_time.Innodb_row_lock_time >=0
36+
mysql.innodb_lock_structures.innodb_lock_structs >=0
37+
mysql.innodb_memory_allocation.total_mem_alloc >=0
38+
mysql.join.Select_full_join >=0
39+
mysql.join.Select_full_range_join >=0
40+
mysql.join.Select_range >=0
41+
mysql.join.Select_range_check >=0
42+
mysql.join.Select_scan >=0
43+
mysql.traffic.Bytes_sent >=0
44+
mysql.traffic.Bytes_received >=0
45+
mysql.cmd.Com_insert >=0
46+
mysql.cmd.Com_insert_select >=0
47+
mysql.cmd.Com_select >=0
48+
mysql.cmd.Com_update >=0
49+
mysql.cmd.Com_update_multi >=0
50+
mysql.cmd.Com_delete >=0
51+
mysql.cmd.Com_delete_multi >=0
52+
mysql.cmd.Com_replace >=0
53+
mysql.cmd.Com_replace_select >=0
54+
mysql.cmd.Com_load >=0
55+
mysql.cmd.Com_set_option >=0
56+
mysql.cmd.Questions >=0
57+
mysql.innodb_insert_buffer_usage.ibuf_cell_count >=0
58+
mysql.innodb_insert_buffer_usage.ibuf_used_cells >=0
59+
mysql.innodb_insert_buffer_usage.ibuf_free_cells >=0
60+
mysql.innodb_semaphores.spin_waits >=0
61+
mysql.innodb_semaphores.os_waits >=0
62+
mysql.threads.thread_cache_size >=0
63+
mysql.threads.Threads_connected >=0
64+
mysql.threads.Threads_running >=0
65+
mysql.threads.Threads_created >=0
66+
mysql.threads.Threads_cached >=0
67+
mysql.innodb_buffer_pool_efficiency.Innodb_buffer_pool_reads >=0
68+
mysql.innodb_buffer_pool_efficiency.Innodb_buffer_pool_read_requests >=0
69+
mysql.innodb_adaptive_hash_index.hash_index_cells_total >=0
70+
mysql.innodb_adaptive_hash_index.hash_index_cells_used >=0
71+
mysql.innodb_transactions_active_locked.current_transactions >=0
72+
mysql.innodb_transactions_active_locked.read_views >=0
73+
mysql.innodb_buffer_pool_activity.pages_created >=0
74+
mysql.innodb_buffer_pool_activity.pages_read >=0
75+
mysql.innodb_buffer_pool_activity.pages_written >=0
76+
mysql.innodb_io.file_reads >=0
77+
mysql.innodb_io.file_writes >=0
78+
mysql.innodb_io.file_fsyncs >=0
79+
mysql.innodb_io.log_writes >=0
80+
mysql.seconds_behind_master.Seconds_Behind_Master >=0
81+
mysql.table_locks.Table_locks_immediate >=0
82+
mysql.table_locks.Table_locks_waited >=0
83+
mysql.table_locks.Slow_queries >=0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[mysqld]
2+
server-id = 1
3+
log-bin
4+
enforce-gtid-consistency=ON
5+
gtid-mode=ON
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE USER 'replica'@'%' IDENTIFIED BY 'replica';
2+
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'%';

0 commit comments

Comments
 (0)