Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 7ff6819

Browse files
committed
nancy prepare-workload: the 1st working version + a test
1 parent 249a5a9 commit 7ff6819

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

.circleci/sample.log

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2018-07-12 22:47:06.085 UTC,"testci","testci",2460,"127.0.0.1:53862",5b47da68.99c,6,"idle",2018-07-12 22:47:04 UTC,,0,LOG,00000,"disconnection: session time: 0:00:01.185 user=testci database=testci host=127.0.0.1 port=53862",,,,,,,,,""
2+
2018-07-12 22:47:06.302 UTC,,,2473,"127.0.0.1:53865",5b47da6a.9a9,1,"",2018-07-12 22:47:06 UTC,,0,LOG,00000,"connection received: host=127.0.0.1 port=53865",,,,,,,,,""
3+
2018-07-12 22:47:07.394 UTC,"testci","testci",28569,"127.0.0.1:53615",5b47d84e.6f99,15,"idle",2018-07-12 22:38:06 UTC,,0,LOG,00000,"disconnection: session time: 0:09:00.762 user=testci database=testci host=127.0.0.1 port=53615",,,,,,,,,""
4+
2018-07-12 22:47:07.838 UTC,"testci","testci",2473,"127.0.0.1:53865",5b47da6a.9a9,4,"SELECT",2018-07-12 22:47:06 UTC,12/0,0,LOG,00000,"duration: 14.564 ms statement: select count(*)
5+
from ""hello_world"" as t
6+
order by t.id desc limit 26",,,,,,,,,""
7+
2018-07-12 22:47:08.053 UTC,"testci","testci",2473,"127.0.0.1:53865",5b47da6a.9a9,5,"SELECT",2018-07-12 22:47:06 UTC,12/0,0,LOG,00000,"duration: 43.544 ms statement: SELECT * FROM ""hello_world"" ""t"" WHERE i > 0 ORDER BY random()",,,,,,,,,""
8+
2018-07-12 22:47:08.547 UTC,"testci","testci",2473,"127.0.0.1:53865",5b47da6a.9a9,6,"idle",2018-07-12 22:47:06 UTC,,0,LOG,00000,"disconnection: session time: 0:00:02.245 user=testci database=testci host=127.0.0.1 port=53865",,,,,,,,,""
9+
2018-07-12 22:47:19.218 UTC,,,2642,"127.0.0.1:54013",5b47da77.a52,1,"",2018-07-12 22:47:19 UTC,,0,LOG,00000,"connection received: host=127.0.0.1 port=54013",,,,,,,,,""
10+
2018-07-12 22:47:19.218 UTC,,,2643,"127.0.0.1:54014",5b47da77.a53,1,"",2018-07-12 22:47:19 UTC,,0,LOG,00000,"connection received: host=127.0.0.1 port=54014",,,,,,,,,""
11+
2018-07-12 22:47:19.218 UTC,,,2644,"127.0.0.1:54015",5b47da77.a54,1,"",2018-07-12 22:47:19 UTC,,0,LOG,00000,"connection received: host=127.0.0.1 port=54015",,,,,,,,,""
12+
2018-07-12 22:47:19.226 UTC,"testci","testci",2644,"127.0.0.1:54015",5b47da77.a54,2,"authentication",2018-07-12 22:47:19 UTC,11/77223,0,LOG,00000,"connection authorized: user=testci database=testci SSL enabled (protocol=TLSv1.2, cipher=ECDHE-RSA-AES256-GCM-SHA384, compression=off)",,,,,,,,,""
13+
2018-07-12 22:47:19.227 UTC,"testci","testci",2642,"127.0.0.1:54013",5b47da77.a52,2,"authentication",2018-07-12 22:47:19 UTC,12/323914,0,LOG,00000,"connection authorized: user=testci database=testci SSL enabled (protocol=TLSv1.2, cipher=ECDHE-RSA-AES256-GCM-SHA384, compression=off)",,,,,,,,,""
14+
2018-07-12 22:47:19.227 UTC,"testci","testci",2643,"127.0.0.1:54014",5b47da77.a53,2,"authentication",2018-07-12 22:47:19 UTC,13/6385,0,LOG,00000,"connection authorized: user=testci database=testci SSL enabled (protocol=TLSv1.2, cipher=ECDHE-RSA-AES256-GCM-SHA384, compression=off)",,,,,,,,,""
15+
2018-07-12 22:47:25.491 UTC,"testci","testci",2687,"127.0.0.1:54016",5b47da7a.a7f,3,"idle",2018-07-12 22:47:22 UTC,,0,LOG,00000,"disconnection: session time: 0:00:02.680 user=testci database=testci host=127.0.0.1 port=54016",,,,,,,,,""

nancy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ done
5959
[ "$DEBUG" -eq "1" ] && echo "CMD: $cmd"
6060

6161
eval $cmd
62-

nancy_prepare_workload.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ while true; do
2626
-d | --debug ) DEBUG=1; shift ;;
2727
--db-name )
2828
DB_NAME="$2"; shift 2 ;;
29+
--output )
30+
OUTPUT="$2"; shift 2 ;;
2931
-- )
3032
>&2 echo "ERROR: Invalid option '$1'"
3133
exit 1
@@ -47,3 +49,37 @@ if [ $DEBUG -eq 1 ]; then
4749
echo "output: ${OUTPUT}"
4850
echo "db_name: ${DB_NAME}"
4951
fi
52+
53+
if [ -z ${INPUT+x} ]; then
54+
>&2 echo "ERROR: the input (path to Postgres log file) is not specified."
55+
exit 1;
56+
fi
57+
58+
if [ -z ${OUTPUT+x} ]; then
59+
>&2 echo "ERROR: the output path is not specified."
60+
exit 1;
61+
fi
62+
63+
cat $INPUT \
64+
| sed -r 's/^([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} .*)$/\nNANCY_NEW_LINE_SEPARATOR\n\1/' \
65+
| sed "s/\"\"/NANCY_TWO_DOUBLE_QUOTES_SEPARATOR/g" \
66+
| awk -v dbname="\"$DB_NAME\"" '
67+
BEGIN {
68+
RS="\nNANCY_NEW_LINE_SEPARATOR\n";
69+
FPAT = "([^,]+)|(\"[^\"]+\")"
70+
OFS=","
71+
}
72+
{
73+
if ($3 == dbname && substr($14, 0, 11) == "\"duration: ") {
74+
duration_ms = substr($14, 0, 30)
75+
if (match($14, /^"duration: ([^ ]+) ms statement: (.*)$/, match_arr)) {
76+
duration = match_arr[1] * 1000
77+
statement = "\"statement: " match_arr[2]
78+
}
79+
"date -u -d @$(echo \"scale=6; ($(date -u --date=\"" $1 "\" +'%s%6N') - " duration \
80+
") / 1000000\" | bc) +\"%Y-%m-%d %H:%M:%S.%6N%:::z\" | tr -d \"\\n\"" | getline res_ts
81+
print res_ts,"\"postgres\"","\"test\"",$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,statement ",,,,,,,,"
82+
}
83+
}' \
84+
| sed "s/NANCY_TWO_DOUBLE_QUOTES_SEPARATOR/\"\"/g" \
85+
| pgreplay -f -c -o "$OUTPUT"

tests/nancy_prepare_workload.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
export PATH=$PATH:${BASH_SOURCE%/*}/..
4+
5+
output=$( \
6+
nancy prepare-workload --db-name testci \
7+
--output ./test.replay ./.circleci/sample.log \
8+
2>&1
9+
)
10+
11+
if [[ $output =~ "Total SQL statements processed: 2" ]]; then
12+
echo -e "\e[36mOK\e[39m"
13+
else
14+
>&2 echo -e "\e[31mFAILED\e[39m"
15+
>&2 echo -e "Output: $output"
16+
exit 1
17+
fi
18+

0 commit comments

Comments
 (0)