-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark.sh
executable file
·94 lines (74 loc) · 2.03 KB
/
benchmark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
set -eo pipefail
TEST_DURATION=5s
opa_pid=""
eopa_pid=""
function cleanup {
if [ ! -z "$opa_pid" ]; then
kill "$opa_pid"
fi
if [ ! -z "$eopa_pid" ]; then
kill "$eopa_pid"
fi
}
trap cleanup EXIT
trap cleanup ERR
usage="$(basename "$0") [opa-bundle] [enterprise-opa-bundle] [query_list]"
if [ "$#" -ne 3 ]; then
echo "Usage: $usage"
exit 1
fi
if command -v opa>/dev/null 2>&1 ; then
echo "opa version: $(opa version | head -n 1 | cut -d ' ' -f 2)"
else
echo "opa not found"
exit 1
fi
if command -v eopa>/dev/null 2>&1 ; then
echo "eopa version: $(eopa version | head -n 1 | cut -d ' ' -f 2)"
else
echo "eopa not found"
exit 1
fi
if command -v k6>/dev/null 2>&1 ; then
echo "k6 version: $(k6 version | head -n 1 | cut -d ' ' -f 2)"
else
echo "k6 not found"
exit 1
fi
if [ -z "${EOPA_LICENSE_KEY}" ]; then
echo "EOPA_LICENSE_KEY must be set"
exit 1
fi
echo "OPA bundle: $1"
echo "Enterprise OPA bundle: $2"
echo "Query list: $3"
echo ""
# OPA Test
nohup opa run --server -b "$1" > opa.log 2>&1 &
opa_pid="$!"
while [[ "$(curl -X "POST" -d $'{"input": {}}' -s -o /dev/null -w ''%{http_code}'' http://localhost:8181/v1/data/rbac/allow?metrics)" != "200" ]]; do
echo "Waiting for OPA to start..."
sleep 4
done
echo "Running OPA test..."
k6 -q run -u 10 -d $TEST_DURATION -e HOST=localhost -e QUERY_FILE="$3" test.js
echo "" # needed to make sure k6 output is on a new line
echo "Stopping OPA..."
kill "$opa_pid"
opa_pid=""
echo ""
# Enterprise OPA Test
nohup eopa run --server -b "$2" > eopa.log 2>&1 &
eopa_pid="$!"
while [[ "$(curl -X "POST" -d $'{"input": {}}' -s -o /dev/null -w ''%{http_code}'' http://localhost:8181/v1/data/rbac/allow?metrics)" != "200" ]]; do
echo "Waiting for Enterprise OPA to start..."
sleep 2
done
echo "Running Enterprise OPA test..."
k6 -q run -u 10 -d $TEST_DURATION -e HOST=localhost -e QUERY_FILE="$3" test.js
echo "" # needed to make sure k6 output is on a new line
echo "Stopping Enterprise OPA..."
kill "$eopa_pid"
eopa_pid=""
cleanup