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

Commit 326c65a

Browse files
authored
Merge branch 'master' into dmius-ebs-size-option
2 parents 830407a + 58ed2e2 commit 326c65a

14 files changed

+252
-91
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- run:
99
name: Install software
1010
command: |
11-
apt-get update && apt-get install -y sudo wget jq \
11+
apt-get update && apt-get install -y sudo wget jq gawk pgreplay bc \
1212
&& wget get.docker.com -q -S -O - | sudo sh
1313
- checkout
1414
- setup_remote_docker
@@ -29,11 +29,11 @@ jobs:
2929
printf "$f${printTail:0:-${#f}}"
3030
bash "$f" -H
3131
status=$?
32-
if [ $status -ne 0 ]; then
32+
if [ "$status" -ne 0 ]; then
3333
errcount="$(($errcount+1))"
3434
fi
3535
done
36-
if [ $errcount -ne 0 ]; then
36+
if [ "$errcount" -ne 0 ]; then
3737
>&2 echo "Oh no! $errcount tests failed"
3838
exit 1
3939
fi

.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",,,,,,,,,""

.circleci/sample.replay

237 Bytes
Binary file not shown.

nancy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ case "$1" in
3131
exit 1;
3232
;;
3333
* )
34-
if [ ! -f "${BASH_SOURCE%/*}/nancy_$1.sh" ]
34+
word="${1/-/_}"
35+
if [ ! -f "${BASH_SOURCE%/*}/nancy_$word.sh" ]
3536
then
3637
>&2 echo "ERROR: Unknown command."
3738
>&2 echo "Try 'nancy help'"
3839
exit 1;
3940
fi
40-
cmd="${BASH_SOURCE%/*}/nancy_$1.sh"
41+
cmd="${BASH_SOURCE%/*}/nancy_$word.sh"
4142
shift;
4243
;;
4344
esac
@@ -58,4 +59,3 @@ done
5859
[ "$DEBUG" -eq "1" ] && echo "CMD: $cmd"
5960

6061
eval $cmd
61-

nancy_prepare_workload.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
3+
DEBUG=0
4+
5+
## Get command line params
6+
while true; do
7+
case "$1" in
8+
help )
9+
echo -e "\033[1mCOMMAND\033[22m
10+
11+
run
12+
13+
\033[1mDESCRIPTION\033[22m
14+
15+
Nancy is a member of Postgres.ai's Artificial DBA team responsible for
16+
conducting experiments.
17+
18+
Use 'nancy prepare-workload' to prepare real-world workload based on Postgres
19+
logs from any of your real Postgres server.
20+
21+
WIP! Not finished. More details TBD later.
22+
23+
\033[1mSEE ALSO\033[22m
24+
" | less -RFX
25+
exit ;;
26+
-d | --debug ) DEBUG=1; shift ;;
27+
--db-name )
28+
DB_NAME="$2"; shift 2 ;;
29+
--output )
30+
OUTPUT="$2"; shift 2 ;;
31+
-- )
32+
>&2 echo "ERROR: Invalid option '$1'"
33+
exit 1
34+
break ;;
35+
* )
36+
if [ "${1:0:2}" == "--" ]; then
37+
>&2 echo "ERROR: Invalid option '$1'. Please double-check options."
38+
exit 1
39+
else
40+
INPUT="$1"
41+
fi
42+
break ;;
43+
esac
44+
done
45+
46+
if [ $DEBUG -eq 1 ]; then
47+
echo "debug: ${DEBUG}"
48+
echo "input: ${INPUT}"
49+
echo "output: ${OUTPUT}"
50+
echo "db_name: ${DB_NAME}"
51+
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+
awk_version=$((awk -Wversion 2>/dev/null || awk --version) | head -n1)
64+
if [ "${awk_version:0:3}" != "GNU" ]; then
65+
>&2 echo "ERROR: GNU awk is required. Your awk version is: ${awk_version}. Try to install gawk."
66+
exit 1;
67+
fi
68+
69+
pgreplay_version=$(pgreplay -v 2>/dev/null)
70+
if [ "${pgreplay_version:0:8}" != "pgreplay" ]; then
71+
>&2 echo "ERROR: pgreplay is not installed."
72+
exit 1;
73+
fi
74+
75+
bc_version=$(bc -v 2>/dev/null)
76+
if [ "${bc_version:0:2}" != "bc" ]; then
77+
>&2 echo "ERROR: bc is not installed."
78+
exit 1;
79+
fi
80+
81+
cat $INPUT \
82+
| 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/' \
83+
| sed "s/\"\"/NANCY_TWO_DOUBLE_QUOTES_SEPARATOR/g" \
84+
| awk -v dbname="\"$DB_NAME\"" '
85+
BEGIN {
86+
RS="\nNANCY_NEW_LINE_SEPARATOR\n";
87+
FPAT = "([^,]+)|(\"[^\"]+\")"
88+
OFS=","
89+
}
90+
{
91+
if ($3 == dbname && substr($14, 0, 11) == "\"duration: ") {
92+
duration_ms = substr($14, 0, 30)
93+
if (match($14, /^"duration: ([^ ]+) ms statement: (.*)$/, match_arr)) {
94+
duration = match_arr[1] * 1000
95+
statement = "\"statement: " match_arr[2]
96+
}
97+
"date -u -d @$(echo \"scale=6; ($(date -u --date=\"" $1 "\" +'%s%6N') - " duration \
98+
") / 1000000\" | bc) +\"%Y-%m-%d %H:%M:%S.%6N%:::z\" | tr -d \"\\n\"" | getline res_ts
99+
print res_ts,"\"postgres\"","\"test\"",$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,statement ",,,,,,,,"
100+
}
101+
}' \
102+
| sed "s/NANCY_TWO_DOUBLE_QUOTES_SEPARATOR/\"\"/g" \
103+
| pgreplay -f -c -o "$OUTPUT"

0 commit comments

Comments
 (0)