forked from openshift/origin-aggregated-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf-test-operations.sh
124 lines (109 loc) · 3.77 KB
/
perf-test-operations.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# This tests for raw .operations index performance - write a bunch of messages
# to the system log and see how long it takes all of them to show up in ES
if [[ $VERBOSE ]]; then
set -ex
else
set -e
VERBOSE=
fi
set -o nounset
set -o pipefail
if [[ $# -ne 1 || "$1" = "false" ]]; then
# assuming not using OPS cluster
CLUSTER="false"
ops=
else
CLUSTER="$1"
ops="-ops"
fi
ARTIFACT_DIR=${ARTIFACT_DIR:-${TMPDIR:-/tmp}/origin-aggregated-logging}
if [ ! -d $ARTIFACT_DIR ] ; then
mkdir -p $ARTIFACT_DIR
fi
# number of messages to send
NMESSAGES=${NMESSAGES:-10000}
# number size e.g. log base 10 of $NMESSAGES
NSIZE=${NSIZE:-5}
# printf format for message number
NFMT=${NFMT:-"%0${NSIZE}d"}
# size of each message - number of bytes to write to each line of the logger file, not
# the actual size of the JSON that is stored into ES
MSGSIZE=${MSGSIZE:-200}
USE_LOGGER=${USE_LOGGER:-false}
get_running_pod() {
# $1 is component for selector
oc get pods -l component=$1 | awk -v sel=$1 '$1 ~ sel && $3 == "Running" {print $1}'
}
wait_until_cmd() {
ii=$2
interval=${3:-10}
while [ $ii -gt 0 ] ; do
$1 && break
sleep $interval
ii=`expr $ii - $interval`
done
if [ $ii -le 0 ] ; then
return 1
fi
return 0
}
# construct the logger file
loggerfile=`mktemp`
comparefile=$loggerfile
justthemessage=`mktemp`
ii=1
prefix=`uuidgen`
# need $MSGSIZE - (36 + "-" + $NSIZE + " ") bytes
n=`expr $MSGSIZE - 36 - 1 - $NSIZE - 1`
EXTRAFMT=${EXTRAFMT:-"%0${n}d"}
echo writing $NMESSAGES messages to file $loggerfile with prefix $prefix
while [ $ii -le $NMESSAGES ] ; do
if [ "$USE_LOGGER" = "true" ] ; then
# format messages for use by logger
printf "%s-$NFMT $EXTRAFMT\n" $prefix $ii 1 >> $loggerfile
else
# direct to /var/log/messages format
printf "%s %s %s[%d]: %s-$NFMT $EXTRAFMT\n" "$(date +'%b %d %H:%M:%S')" `hostname -s` \
$prefix $$ $prefix $ii 1 >> $loggerfile
printf "%s-$NFMT $EXTRAFMT\n" $prefix $ii 1 >> $justthemessage
fi
ii=`expr $ii + 1`
done
# get current count of .operations
kpod=`get_running_pod kibana${ops}`
STARTTIME=$(date +%s)
if [ "$USE_LOGGER" = "true" ] ; then
echo starting logger at `date`
# there is some sort of throttling going on in journald? rsyslog? only ~ 760 messages
# end up in /var/log/messages
echo logger -i -p local6.info -t $prefix -f $loggerfile
time logger -i -p local6.info -t $prefix -f $loggerfile
echo finished logger at `date`
else
cat $loggerfile | sudo tee -a /var/log/messages > /dev/null
comparefile=$justthemessage
fi
# not used now, but in case we need it
INDEX_PREFIX=
count_ge_nmessages() {
curcount=`oc exec $kpod -- curl -s -k --cert /etc/kibana/keys/cert --key /etc/kibana/keys/key \
https://logging-es${ops}:9200/${INDEX_PREFIX}.operations*/_count\?q=message:$prefix | \
python -c 'import json, sys; print json.loads(sys.stdin.read())["count"]'`
# output: time count
echo $(date +%s) $curcount
test $curcount -ge $NMESSAGES
}
echo waiting for $NMESSAGES messages in elasticsearch
wait_until_cmd count_ge_nmessages 600 1
# now total number of records >= $startcount + $NMESSAGES
# mark time
MARKTIME=$(date +%s)
echo duration `expr $MARKTIME - $STARTTIME`
# search ES and extract the messages
esmessages=`mktemp`
oc exec $kpod -- curl -s -k --cert /etc/kibana/keys/cert --key /etc/kibana/keys/key \
https://logging-es${ops}:9200/${INDEX_PREFIX}.operations*/_search\?q=ident:$prefix\&fields=message\&size=`expr $NMESSAGES + 1` | \
python -c 'import json, sys; print "\n".join([ii["fields"]["message"][0] for ii in json.loads(sys.stdin.read())["hits"]["hits"]])' | sort -n > $esmessages
diff $comparefile $esmessages
echo ES content is identical to log content