Skip to content

Commit 8cf70a7

Browse files
author
Roel Van de Paar
committed
2 parents ef884db + 274c32a commit 8cf70a7

File tree

5 files changed

+219
-12
lines changed

5 files changed

+219
-12
lines changed

pmm-tests/pgsql-specific-tests.bats

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env bats
2+
3+
## postgresql:metrics
4+
5+
6+
PGSQL_USER='psql'
7+
PGSQL_HOST='localhost'
8+
PGSQL_SOCK=5432
9+
10+
@test "run pmm-admin under regular(non-root) user privileges" {
11+
if [[ $(id -u) -eq 0 ]] ; then
12+
skip "Skipping this test, because you are running under root"
13+
fi
14+
run pmm-admin
15+
echo "$output"
16+
[ "$status" -eq 1 ]
17+
[ "${lines[0]}" = "pmm-admin requires superuser privileges to manage system services." ]
18+
}
19+
20+
21+
@test "run pmm-admin under root privileges" {
22+
if [[ $(id -u) -ne 0 ]] ; then
23+
skip "Skipping this test, because you are NOT running under root"
24+
fi
25+
run pmm-admin
26+
echo "$output"
27+
[ "$status" -eq 1 ]
28+
[ "${lines[0]}" = "Usage:" ]
29+
}
30+
31+
32+
@test "run pmm-admin add postgresql:metrics based on running intsances" {
33+
COUNTER=0
34+
CURRENT_COUNT=$(sudo pmm-admin list | grep "postgresql:metrics" | sed 's|.*(||;s|)||' | wc -l)
35+
for i in $(seq ${CURRENT_COUNT}); do
36+
let COUNTER=COUNTER+1
37+
run sudo pmm-admin add postgresql:metrics --port=${PGSQL_SOCK} --user=${PGSQL_USER} pgsql_metrics_$COUNTER
38+
echo "$output"
39+
[ "$status" -eq 0 ]
40+
echo "${lines[0]}" | grep "OK, now monitoring"
41+
done
42+
}
43+
44+
@test "run pmm-admin add postgresql:metrics again based on running instances" {
45+
COUNTER=0
46+
CURRENT_COUNT=$(sudo pmm-admin list | grep "pgsql_metrics_" | grep -Eo '\/.*\)' | sed 's/)$//' | wc -l)
47+
for i in $(seq ${CURRENT_COUNT}); do
48+
let COUNTER=COUNTER+1
49+
run sudo pmm-admin add postgresql:metrics --user=${PGSQL_USER} --port=${PGSQL_SOCK} pgsql_metrics_$COUNTER
50+
echo "$output"
51+
[ "$status" -eq 1 ]
52+
[ "${lines[0]}" = "Error adding PostgreSQL metrics: there is already one instance with this name under monitoring." ]
53+
done
54+
}
55+
56+
57+
@test "run pmm-admin remove postgresql:metrics" {
58+
COUNTER=0
59+
CURRENT_COUNT=$(sudo pmm-admin list | grep "pgsql_metrics_" | wc -l)
60+
for i in $(seq ${CURRENT_COUNT}) ; do
61+
let COUNTER=COUNTER+1
62+
run sudo pmm-admin remove postgresql:metrics pgsql_metrics_$COUNTER
63+
echo "$output"
64+
[ "$status" -eq 0 ]
65+
echo "${output}" | grep "OK, removed PostgreSQL metrics"
66+
done
67+
}
68+
69+
70+
@test "run pmm-admin remove postgresql:metrics again" {
71+
COUNTER=0
72+
for i in $(sudo pmm-admin list | grep "pgsql_metrics_") ; do
73+
let COUNTER=COUNTER+1
74+
run sudo pmm-admin remove postgresql:metrics pgsql_metrics_$COUNTER
75+
echo "$output"
76+
[ "$status" -eq 0 ]
77+
echo "${output}" | grep "no service found"
78+
done
79+
}
80+
81+
## add postgresql
82+
83+
@test "run pmm-admin add postgresql" {
84+
COUNTER=0
85+
CURRENT_COUNT=$(sudo pmm-admin list | grep "postgresql:metrics" | sed 's|.*(||;s|).*||' | wc -l)
86+
for i in $(seq ${CURRENT_COUNT}) ; do
87+
let COUNTER=COUNTER+1
88+
run sudo pmm-admin add postgresql --user=${PGSQL_USER} --port=${PGSQL_SOCK} postgresql_$COUNTER
89+
echo "$output"
90+
[ "$status" -eq 0 ]
91+
echo "${lines[0]}" | grep "OK, already"
92+
echo "${lines[1]}" | grep "OK, now"
93+
done
94+
}
95+
96+
@test "run pmm-admin add postgresql again" {
97+
COUNTER=0
98+
CURRENT_COUNT=$(sudo pmm-admin list | grep "postgresql:metrics" | grep "postgresql_" | sed 's|.*(||;s|).*||' | wc -l)
99+
for i in $(seq ${CURRENT_COUNT}); do
100+
let COUNTER=COUNTER+1
101+
run sudo pmm-admin add postgresql --user=${PGSQL_USER} --port=${PGSQL_SOCK} postgresql_$COUNTER
102+
echo "$output"
103+
[ "$status" -eq 0 ]
104+
echo "${lines[0]}" | grep "OK, already"
105+
echo "${lines[1]}" | grep "OK, already"
106+
done
107+
}
108+
109+
@test "run pmm-admin remove postgresql" {
110+
COUNTER=0
111+
CURRENT_COUNT=$(sudo pmm-admin list | grep "postgresql:metrics" | grep "postgresql_" | sed 's|.*(||;s|).*||' | wc -l)
112+
for i in $(seq ${CURRENT_COUNT}); do
113+
let COUNTER=COUNTER+1
114+
run sudo pmm-admin remove postgresql postgresql_$COUNTER
115+
echo "$output"
116+
[ "$status" -eq 0 ]
117+
echo "${lines[0]}" | grep "OK, no system"
118+
echo "${lines[1]}" | grep "OK, removed"
119+
done
120+
121+
}
122+
123+
function teardown() {
124+
echo "$output"
125+
}

pmm-tests/pmm-framework.sh

+70-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ usage () {
3636
echo " --pmm-port Pass port for PMM docker"
3737
echo " --ps-version Pass Percona Server version info"
3838
echo " --ms-version Pass MySQL Server version info"
39+
echo " --pgsql-version Pass Postgre SQL server version Info"
3940
echo " --md-version Pass MariaDB Server version info"
4041
echo " --pxc-version Pass Percona XtraDB Cluster version info"
4142
echo " --mysqld-startup-options Pass MySQL startup options. eg : --mysqld-startup-options='--innodb_buffer_pool_size=1G --innodb_log_file_size=1G'"
@@ -74,7 +75,7 @@ usage () {
7475
# Check if we have a functional getopt(1)
7576
if ! getopt --test
7677
then
77-
go_out="$(getopt --options=u: --longoptions=addclient:,replcount:,pmm-server:,ami-image:,key-name:,ova-image:,ova-memory:,pmm-server-version:,pmm-port:,pmm-server-memory:,pmm-docker-memory:,pmm-server-username:,pmm-server-password:,query-source:,setup,with-replica,with-shrading,download,ps-version:,ms-version:,md-version:,pxc-version:,mysqld-startup-options:,mo-version:,mongo-with-rocksdb,add-docker-client,list,wipe-clients,wipe-docker-clients,wipe-server,disable-ssl,upgrade-server,upgrade-client,wipe,dev,with-proxysql,sysbench-data-load,sysbench-oltp-run,storage-engine:,compare-query-count,help \
78+
go_out="$(getopt --options=u: --longoptions=addclient:,replcount:,pmm-server:,ami-image:,key-name:,ova-image:,ova-memory:,pmm-server-version:,pmm-port:,pmm-server-memory:,pmm-docker-memory:,pmm-server-username:,pmm-server-password:,query-source:,setup,with-replica,with-shrading,download,ps-version:,ms-version:,pgsql-version:,md-version:,pxc-version:,mysqld-startup-options:,mo-version:,mongo-with-rocksdb,add-docker-client,list,wipe-clients,wipe-docker-clients,wipe-server,disable-ssl,upgrade-server,upgrade-client,wipe,dev,with-proxysql,sysbench-data-load,sysbench-oltp-run,storage-engine:,compare-query-count,help \
7879
--name="$(basename "$0")" -- "$@")"
7980
test $? -eq 0 || exit 1
8081
eval set -- $go_out
@@ -159,6 +160,10 @@ do
159160
ms_version="$2"
160161
shift 2
161162
;;
163+
--pgsql-version )
164+
pgsql_version="$2"
165+
shift 2
166+
;;
162167
--md-version )
163168
md_version="$2"
164169
shift 2
@@ -369,13 +374,28 @@ sanity_check(){
369374
fi
370375
}
371376

377+
sudo_check(){
378+
379+
USER=$1
380+
# Sudo check
381+
if [ "$(sudo -H -u ${USER} bash -c "echo 'test'" 2>/dev/null)" != "test" ]; then
382+
echo "Error: sudo is not available or requires a password. This script needs to be able to use sudo, without password, from the userID that invokes it ($(whoami))"
383+
echo "To get your setup correct, you may like to use a tool like visudo (use 'sudo visudo' or 'su' and then 'visudo') and consider adding the following line to the file:"
384+
echo "$(whoami) ALL=(ALL) NOPASSWD:ALL"
385+
echo "If you do not have sudo installed yet, try 'su' and then 'yum install sudo' or the apt-get equivalent"
386+
echo "Terminating now."
387+
exit 1
388+
fi
389+
}
390+
372391
if [[ -z "${ps_version}" ]]; then ps_version="5.7"; fi
373392
if [[ -z "${pxc_version}" ]]; then pxc_version="5.7"; fi
374393
if [[ -z "${ms_version}" ]]; then ms_version="8.0"; fi
375394
if [[ -z "${md_version}" ]]; then md_version="10.2"; fi
376395
if [[ -z "${mo_version}" ]]; then mo_version="3.4"; fi
377396
if [[ -z "${REPLCOUNT}" ]]; then REPLCOUNT="1"; fi
378397
if [[ -z "${ova_memory}" ]]; then ova_memory="2048";fi
398+
if [[ -z "${pgsql_version}" ]]; then pgsql_version="10.5";fi
379399

380400
if [[ -z "$query_source" ]];then
381401
query_source=perfschema
@@ -650,7 +670,11 @@ get_basedir(){
650670
BASE_TAR=$(ls -1td $SERVER_STRING 2>/dev/null | grep ".tar" | head -n1)
651671
if [ ! -z $BASE_TAR ];then
652672
tar -xzf $BASE_TAR
653-
BASEDIR=$(ls -1td $SERVER_STRING 2>/dev/null | grep -v ".tar" | head -n1)
673+
if [[ "${PRODUCT_NAME}" == "postgresql" ]]; then
674+
BASEDIR=$(ls -1td pgsql 2>/dev/null | grep -v ".tar" | head -n1)
675+
else
676+
BASEDIR=$(ls -1td $SERVER_STRING 2>/dev/null | grep -v ".tar" | head -n1)
677+
fi
654678
BASEDIR="$WORKDIR/$BASEDIR"
655679
rm -rf $BASEDIR/node*
656680
else
@@ -670,7 +694,11 @@ get_basedir(){
670694
BASE_TAR=$(ls -1td $SERVER_STRING 2>/dev/null | grep ".tar" | head -n1)
671695
if [ ! -z $BASE_TAR ];then
672696
tar -xzf $BASE_TAR
673-
BASEDIR=$(ls -1td $SERVER_STRING 2>/dev/null | grep -v ".tar" | head -n1)
697+
if [[ "${PRODUCT_NAME}" == "postgresql" ]]; then
698+
BASEDIR=$(ls -1td pgsql 2>/dev/null | grep -v ".tar" | head -n1)
699+
else
700+
BASEDIR=$(ls -1td $SERVER_STRING 2>/dev/null | grep -v ".tar" | head -n1)
701+
fi
674702
BASEDIR="$WORKDIR/$BASEDIR"
675703
if [[ "${CLIENT_NAME}" == "mo" ]]; then
676704
sudo rm -rf $BASEDIR/data
@@ -782,6 +810,10 @@ add_clients(){
782810
NODE_NAME="MS_NODE"
783811
get_basedir mysql "mysql-${ms_version}*" "MySQL Server binary tar ball" ${ms_version}
784812
MYSQL_CONFIG="--init-file ${SCRIPT_PWD}/QRT_Plugin.sql --innodb_monitor_enable=all --performance_schema=ON"
813+
elif [[ "${CLIENT_NAME}" == "pgsql" ]]; then
814+
PORT_CHECK=501
815+
NODE_NAME="PGSQL_NODE"
816+
get_basedir postgresql "postgresql-${pgsql_version}*" "Postgre SQL Binary tar ball" ${pgsql_version}
785817
elif [[ "${CLIENT_NAME}" == "md" ]]; then
786818
PORT_CHECK=301
787819
NODE_NAME="MD_NODE"
@@ -795,8 +827,8 @@ add_clients(){
795827
elif [[ "${CLIENT_NAME}" == "mo" ]]; then
796828
get_basedir psmdb "percona-server-mongodb-${mo_version}*" "Percona Server Mongodb binary tar ball" ${mo_version}
797829
fi
798-
if [[ "${CLIENT_NAME}" != "md" && "${CLIENT_NAME}" != "mo" ]]; then
799-
VERSION="$(${BASEDIR}/bin/mysqld --version | grep -oe '[58]\.[5670]' | head -n1)"
830+
if [[ "${CLIENT_NAME}" != "md" && "${CLIENT_NAME}" != "mo" && "${CLIENT_NAME}" != "pgsql" ]]; then
831+
VERSION="$(${BASEDIR}/bin/mysqld --version | grep -oe '[58]\.[5670]' | head -n1)"
800832
if [ "$VERSION" == "5.7" -o "$VERSION" == "8.0" ]; then
801833
MID="${BASEDIR}/bin/mysqld --default-authentication-plugin=mysql_native_password --initialize-insecure --basedir=${BASEDIR}"
802834
else
@@ -897,6 +929,39 @@ add_clients(){
897929
$BASEDIR/bin/mongo --quiet --eval "printjson(db.getSisterDB('admin').runCommand({addShard: 'r${k}/localhost:${PSMDB_PORTS[$n]}'}))"
898930
done
899931
fi
932+
elif [[ "${CLIENT_NAME}" == "pgsql" ]]; then
933+
echo "Creating postgresql Dedicated User psql"
934+
IP_ADDRESS=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
935+
if id psql >/dev/null 2>&1; then
936+
echo "yes the user psql exists"
937+
else
938+
echo "No, the user psql does not exist, Adding"
939+
sudo adduser --disabled-password --gecos "" psql
940+
fi
941+
PGSQL_PORT=5431
942+
for j in `seq 1 ${ADDCLIENTS_COUNT}`;do
943+
PGSQL_PORT=$((PGSQL_PORT+j))
944+
cd ${BASEDIR}/bin
945+
if [ -d ${BASEDIR}/${NODE_NAME}_${j}/data ]; then
946+
echo "PGSQL Data Directory Exist, Removing old Directory, Stopping already running Server and creating a new one"
947+
sudo -H -u psql bash -c "./pg_ctl -D ${BASEDIR}/${NODE_NAME}_${j}/data -l ${BASEDIR}/${NODE_NAME}_${j}/data/logfile -o '-F -p ${PGSQL_PORT}' stop" > /dev/null 2>&1;
948+
sudo rm -r ${BASEDIR}/${NODE_NAME}_${j}
949+
sudo mkdir -p ${BASEDIR}/${NODE_NAME}_${j}/data
950+
else
951+
sudo mkdir -p ${BASEDIR}/${NODE_NAME}_${j}/data
952+
fi
953+
sudo chown -R psql ${BASEDIR}/${NODE_NAME}_${j}/data
954+
sudo_check psql
955+
echo "Starting PGSQL server at port ${PGSQL_PORT}"
956+
sudo -H -u psql bash -c "./pg_ctl -D ${BASEDIR}/${NODE_NAME}_${j}/data initdb" > /dev/null 2>&1;
957+
sudo -H -u psql bash -c "./pg_ctl -D ${BASEDIR}/${NODE_NAME}_${j}/data -l ${BASEDIR}/${NODE_NAME}_${j}/data/logfile -o '-F -p ${PGSQL_PORT}' start" > /dev/null 2>&1;
958+
if [ $disable_ssl -eq 1 ]; then
959+
sudo pmm-admin add postgresql --user psql --host localhost --port ${PGSQL_PORT} --disable-ssl PGSQL-${NODE_NAME}-${j}
960+
check_disable_ssl PGSQL-${NODE_NAME}-${j}
961+
else
962+
sudo pmm-admin add postgresql --user psql --host localhost --port ${PGSQL_PORT} PGSQL-${NODE_NAME}-${j}
963+
fi
964+
done
900965
else
901966
if [ -r ${BASEDIR}/lib/mysql/plugin/ha_tokudb.so ]; then
902967
TOKUDB_STARTUP="--plugin-load-add=tokudb=ha_tokudb.so --tokudb-check-jemalloc=0"

pmm-tests/pmm-testsuite.sh

+13
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ function run_ps_specific_tests() {
7070
fi
7171
}
7272

73+
function run_postgresql_specific_tests() {
74+
if [[ $tap == 1 ]] ; then
75+
bats --tap ${DIRNAME}/pgsql-specific-tests.bats
76+
else
77+
bats ${DIRNAME}/pgsql-specific-tests.bats
78+
fi
79+
}
80+
7381
function run_pxc_specific_tests() {
7482
if [[ $tap == 1 ]] ; then
7583
bats --tap ${DIRNAME}/pxc-specific-tests.bats
@@ -228,6 +236,11 @@ if [[ $instance_t == "ps" ]]; then
228236
run_ps_specific_tests
229237
fi
230238

239+
if [[ $instance_t == "pgsql" ]]; then
240+
echo "Running Postgre SQL specific tests"
241+
run_postgresql_specific_tests
242+
fi
243+
231244

232245
if [[ $instance_t == "pxc" ]]; then
233246
echo "Running PXC specific tests"

pquery-clean-known.sh

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@
77
SCRIPT_PWD=$(cd `dirname $0` && pwd)
88

99
# Check if this an automated (pquery-reach.sh) run
10+
REACH=0 # Normal output
1011
if [ "$1" == "reach" ]; then
1112
REACH=1 # Minimal output, and no 2x enter required
12-
else
13-
REACH=0 # Normal output
1413
fi
1514

1615
# Check if this is a pxc run
16+
PXC=0
1717
if [ "$(grep 'PXC Mode:' ./pquery-run.log 2> /dev/null | sed 's|^.*PXC Mode[: \t]*||' )" == "TRUE" ]; then
18-
export PXC=1
19-
else
20-
export PXC=0
18+
PXC=1
2119
fi
2220

2321
# Check if this is a group replication run
22+
GRP_RPL=0
2423
if [ "$(grep 'Group Replication Mode:' ./pquery-run.log 2> /dev/null | sed 's|^.*Group Replication Mode[: \t]*||')" == "TRUE" ]; then
2524
GRP_RPL=1
26-
else
27-
GRP_RPL=0
2825
fi
2926

3027
# Current location checks

pquery-del-trial.sh

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ if [[ $PXC -eq 1 ]];then
77
PXC_NODE=$(echo $TRIAL | cut -d'-' -f2)
88
TRIAL=$(echo $TRIAL | cut -d'-' -f1)
99
fi
10+
11+
# Check if this is a pxc run
12+
PXC=0
13+
if [ "$(grep 'PXC Mode:' ./pquery-run.log 2> /dev/null | sed 's|^.*PXC Mode[: \t]*||' )" == "TRUE" ]; then
14+
PXC=1
15+
fi
16+
1017
if [ "${TRIAL}" == "" ]; then
1118
echo "This script deletes a given pquery trial completely. Execute this script from within the pquery workdir"
1219
echo "Example: to delete trial 10 (./10), execute as: ./delete_single_trial.sh 10"

0 commit comments

Comments
 (0)