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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
#!/bin/sh
# PCP QA Test No. 1600
# Exercise log discovery, pmproxy and pmseries.
#
# Copyright (c) 2018-2020 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
. ./common.keys
_check_series
_cleanup()
{
[ -n "$pmproxy_pid" ] && $signal -s TERM $pmproxy_pid
[ -n "$options" ] && $keys_cli $options shutdown
cd $here
if $need_restore
then
need_restore=false
$sudo rm -rf $PCP_SYSCONF_DIR/pcp/labels/*
_restore_config $PCP_SYSCONF_DIR/labels
_restore_config $PCP_SYSCONF_DIR/pmproxy
_restore_config $PCP_SYSCONF_DIR/pmseries
[ -d $PCP_TMP_DIR/mmv.$seq ] && _restore_config $PCP_TMP_DIR/mmv
_sighup_pmcd
fi
$sudo rm -rf $tmp $tmp.*
}
status=1 # failure is the default!
signal=$PCP_BINADM_DIR/pmsignal
userid=`id -u`
groupid=`id -g`
username=`id -u -n`
hostname=`hostname`
machineid=`_machine_id`
domainname=`_domain_name`
need_restore=false
trap "_cleanup; exit \$status" 0 1 2 3 15
_filter_series()
{
sed \
-e 's/[0-9a-z]\{40\}/TIMESERIES/g' \
#end
}
_filter_labels()
{
sed \
-e "s/.domainname.:.${domainname}./\"domainname\":\"DOMAIN\"/g" \
-e "s/.machineid.:.${machineid}./\"machineid\":\"MACHINE\"/g" \
-e "s/.hostname.:.${hostname}./\"hostname\":\"HOST\"/g" \
-e "s/.groupid.:$groupid/\"groupid\":GID/g" \
-e "s/.userid.:$userid/\"userid\":UID/g" \
#end
}
# not only dodge the timestamp and value, but the number of
# [TIMESTAMP] VALUE
# lines may be 1 or 2
#
_filter_values()
{
sed \
-e 's/\[[0-9][0-9]*\.[0-9][0-9]*\]/[TIMESTAMP]/g' \
-e 's/ [0-9][0-9]*$/ VALUE/g' \
| $PCP_AWK_PROG '
BEGIN { n = 0 }
$2 == "VALUE" { n++
if (n > 2) {
print "Unexpected extra line:",$0
}
else {
if (n == 1) print
next
}
}
{ print }'
}
_filter_label_values()
{
sed \
-e "s/^domainname: \"${domainname}\"/domainname: \"DOMAIN\"/g" \
-e "s/^machineid: \"${machineid}\"/machineid: \"MACHINE\"/g" \
-e "s/^hostname: \"${hostname}\"/hostname: \"HOSTNAME\"/g" \
-e "s/^groupid: $groupid/groupid: GID/g" \
-e "s/^userid: $userid/userid: UID/g" \
-e "s/transient: false, true/transient: false/g" \
-e "s/changed: false, true/changed: false/g" \
-e "/metric_label: null/d" \
#end
}
# sort the values in this line
# agent: "mmv", "sample", "pmcd"
#
_filter_agents()
{
LC_COLLATE=POSIX $PCP_AWK_PROG '
$1 == "agent:" { printf "%s ",$1
for (i = 2; i <= NF; i++) {
small = -1
for (j = 2; j <= NF; j++) {
if ($j == "")
continue
if (small == -1 || $j < $small)
small = j
}
if (i > 2)
printf ", "
gsub(/,/, "", $small)
printf "%s",$small
$small = ""
}
printf "\n"
next
}
{ print }'
}
# real QA test starts here
_save_config $PCP_SYSCONF_DIR/labels
_save_config $PCP_SYSCONF_DIR/pmproxy
_save_config $PCP_SYSCONF_DIR/pmseries
[ -d $PCP_TMP_DIR/mmv ] && _save_config $PCP_TMP_DIR/mmv
$sudo rm -f $PCP_SYSCONF_DIR/pmseries/*
$sudo rm -f $PCP_SYSCONF_DIR/pmproxy/*
$sudo rm -rf $PCP_SYSCONF_DIR/labels/*
$sudo rm -f $PCP_TMP_DIR/mmv/*
need_restore=true
echo '{"latitude": -25.28496, "longitude": 152.87886}' > $tmp.labels
$sudo cp $tmp.labels $PCP_SYSCONF_DIR/labels/pcpqa.location
_sighup_pmcd || _exit 1
echo "Start test key server ..."
key_server_port=`_find_free_port`
options="-p $key_server_port"
$key_server --port $key_server_port --save "" > $tmp.keys 2>&1 &
_check_key_server_ping $key_server_port
_check_key_server $key_server_port
echo
_check_key_server_version $key_server_port
# prepare logging location and config
PCP_ARCHIVE_DIR=$tmp.log/pmlogger; export PCP_ARCHIVE_DIR
mkdir -p $PCP_ARCHIVE_DIR
cat >$tmp.pmlogger.conf << End-Of-File
log mandatory on default {
mmv
pmcd
sample.long
sample.ulong
sample.double
sample.rapid
sample.colour
sample.mirage
sample.needprofile
}
End-Of-File
cat >$tmp.pmproxy.conf << End-Of-File
[discover]
enabled = true
[pmseries]
enabled = true
End-Of-File
# start long-running pmlogger actively writing archives
pmlogger -t 0.25 -T 3sec -c $tmp.pmlogger.conf -l $tmp.pmlogger.log $PCP_ARCHIVE_DIR/archive &
pmlogger_pid=$!
#echo pmlogger=$pmlogger_pid
_wait_for_pmlogger $pmlogger_pid $tmp.pmlogger.log || _exit 1
pmsleep 0.5 # time for pmlogger to start logging
# start pmproxy
proxyport=`_find_free_port`
proxyopts="-f -A -p $proxyport -r $key_server_port -U $username"
#proxyopts="$pmproxyopts -Dseries,discovery"
pmproxy -c $tmp.pmproxy.conf -x $seq_full -l $tmp.pmproxy.log $proxyopts &
pmproxy_pid=$!
#echo pmproxy=$pmproxy_pid
# check pmproxy has started and is discovering timeseries
pmcd_wait -h localhost@localhost:$proxyport -v -t 5sec
pmsleep 0.5 # time for pmproxy to start discovering
$PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '/pmlogger|/pmproxy|/valkey|/redis' >> $seq_full
$keys_cli $options keys pcp:* >> $seq_full
ls -lR $PCP_ARCHIVE_DIR >> $seq_full
cat $tmp.pmproxy.log >> $seq_full
# uncomment this block to pause the test so you can investigate the
# new pmproxy, then enter RETURN for shell running this script to
# continue the test
#debug# echo "pausing for diagnosis ($options ... $PCP_ARCHIVE_DIR)"
#debug# echo pmlogger:
#debug# cat $tmp.pmlogger.log
#debug# echo pmproxy:
#debug# cat $tmp.pmproxy.log
#debug# echo "options=$options"
#debug# echo "series=$series"
#debug# if [ -e /dev/tty ]; then read x </dev/tty; fi
#
# verify we have data loading and can issue various queries
#
echo "== verify metric names" | tee -a $seq_full
pmseries $options sample.double.bin* | _filter_series
echo "== verify metric descs" | tee -a $seq_full
series=`pmseries $options sample.long.ten`
[ -z "$series" ] && _fail "Cannot find any timeseries matching sample.long.ten"
pmseries $options -d $series | _filter_series
echo "== verify metric insts" | tee -a $seq_full
series=`pmseries $options sample.ulong.bin`
[ -z "$series" ] && _fail "Cannot find any timeseries matching sample.ulong.bin"
pmseries $options -i $series | _filter_series
echo "== verify metric labels" | tee -a $seq_full
series=`pmseries $options sample.double.bin`
[ -z "$series" ] && _fail "Cannot find any timeseries matching sample.double.bin"
pmseries $options -l $series | _filter_labels | _filter_series
echo "== verify metric values" | tee -a $seq_full
pmsleep 0.5
pmseries $options -t sample.ulong.million[samples:2] \
| tee -a $seq_full \
| _filter_values \
| _filter_series
echo "== verify label names and values" | tee -a $seq_full
labels=`pmseries $options -l | LC_COLLATE=POSIX sort`
pmseries $options -v $labels | _filter_label_values | _filter_agents
# pause until pmlogger exits to prevent confusion when removing archives
wait $pmlogger_pid
#
# verify discovery handling of archive deletion
#
echo "== verify archive removal" | tee -a $seq_full
rm -fr $PCP_ARCHIVE_DIR
pmsleep 0.5 # allow filesystem event some time to arrive
pmcd_wait -h localhost@localhost:$proxyport -v -t 1sec # pmproxy still up?
echo "== log " >> $seq_full
cat $tmp.pmproxy.log >> $seq_full
echo "== key server log " >> $seq_full
cat $tmp.keys >> $seq_full
echo "== all done" | tee -a $seq_full
# success, all done
status=0
exit
|