File: 1617

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (240 lines) | stat: -rwxr-xr-x 6,093 bytes parent folder | download
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
#!/bin/sh
# PCP QA Test No. 1617
# Exercise pmproxy logger REST API with key server.
#
# Copyright (c) 2025 Red Hat.  All Rights Reserved.
#

if [ $# -eq 0 ]
then
    seq=`basename $0`
    echo "QA output created by $seq"
else
    # use $seq from caller, unless not set
    [ -n "$seq" ] || seq=`basename $0`
    echo "QA output created by `basename $0` $*"
fi

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
. ./common.keys

_check_valgrind
_check_series

cached=false
[ "$1" = "--cached" ] && cached=true

_cleanup()
{
    cd $here
    [ -n "$key_server_port" ] && $keys_cli -p $key_server_port shutdown
    [ -d $archive_path ] && $sudo rm -fr $archive_path

    # undo changes to PCP_RUN_DIR PCP_TMP_DIR PCP_REMOTE_ARCHIVE_DIR
    unset PCP_ENV_DONE PCP_RUN_DIR PCP_TMP_DIR PCP_REMOTE_ARCHIVE_DIR
    . $PCP_DIR/etc/pcp.env

    _restore_auto_restart pmlogger
    _service pmlogger start 2>&1 | _filter_pcp_start
    _wait_for_pmlogger

    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

# prevent a local logger interfering with remote testing
_stop_auto_restart pmlogger
_service pmlogger stop 2>&1 | _filter_pcp_stop

_filter()
{
    sed \
	-e "s@$tmp@TMP@g" \
	-e "s@$archive@ARCHIVE@g" \
	-e "s@$archive_path@ARCHIVE_PATH@g" \
    # end
}

_filter_ls()
{
    sed \
        -e 's/\([r-][w-][x-]\)\. /\1 /' \
        -e 's/tmp\/[0-9][0-9]*/tmp\/PID/' \
        -e 's/[A-Z][a-z][a-z]  *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]/TIME/' \
    | $PCP_AWK_PROG '
/TIME/  { $3 = "user"; $4 = "group" }
        { print }'
}

_filter_values()
{
    # filter on specific times/values from the archive, however
    # some indeterminism exists from use of floating point math
    sed \
	-e 's/11:53:38.*1999/11:53:38 1999/g' \
	-e 's/4.147.*e+06/4.147e+06/g' \
    # end
}

# remove -Dcontext diagnostics from output ... they remain in $seq_full
#
_filter_context_debug()
{
    sed \
	-e '/^on_client_/d' \
	-e '/^pmNewContext(/d' \
	-e '/^Dump Contexts:/d' \
	-e '/^contexts\[/d' \
	-e '/^Dump Instance Profile/d' \
	-e '/^pmWhichContext/d' \
	-e '/^pmUseContext/d' \
	-e '/^__pmSetVersionIPC:/d' \
	-e '/^IPC table /d' \
	-e '/^refcnt=[0-9]* vol=[0-9]* offset=[0-9]*/d' \
    # end
}

PCP_DERIVED_CONFIG=""; export PCP_DERIVED_CONFIG
archive=$here/archives/ok-mv-bigbin

# need to check *just* the metrics from the target archive
# because pmproxy may start to gather metrics from the primary
# logger's archive which means pmseries reports a whole lot more
# than we're expecting
#
pminfo -a $archive \
| sed \
    -e "/^pmcd\.*/d" \
    -e "/^event\.*/d" \
    -e 's/.*/\/^&$\/p/' >$tmp.metrics.sed
echo "+++ metrics.sed +++" >>$seq_full
cat $tmp.metrics.sed >>$seq_full

# similarly, *just* the labels from the target archive
# e.g. labels {"hostname":"ha2"}
#
pminfo -a $archive -l \
| sed -n \
    -e '/ labels /{
s/.*{"//
s/":".*//
s/.*/\/^&$\/p/p
}' \
| LC_COLLATE=POSIX sort \
| uniq >$tmp.labels.sed
echo "+++ labels.sed +++" >>$seq_full
cat $tmp.labels.sed >>$seq_full

# real QA test starts here
user=`id -nu`
pmproxy_port=`_find_free_port`
_filter_pmproxy_port()
{
    sed \
        -e "s/ FD $pmproxy_port / FD PORT /g" \
        -e '/PORT ipv6 /d' \
    # end
}
no_pmproxy_port=`expr $pmproxy_port + 1`
key_server_port=`_find_free_port $no_pmproxy_port`

echo "Start test key server ..."
$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

cat >$tmp.conf << End-Of-File
[keys]
enabled = true
servers = localhost:$key_server_port
[pmproxy]
http.enabled = true
[pmlogger]
enabled = true
cached = $cached
[discover]
enabled = true
[pmseries]
enabled = true
End-Of-File

mkdir -p $tmp.pmproxy/pmproxy
PCP_RUN_DIR=$tmp.pmproxy; export PCP_RUN_DIR
PCP_TMP_DIR=$tmp.pmproxy; export PCP_TMP_DIR
PCP_REMOTE_ARCHIVE_DIR=$tmp.pmproxy/pmproxy; export PCP_REMOTE_ARCHIVE_DIR

echo "Start test pmproxy ..."
archive_host=`hostname`
archive_path=$PCP_REMOTE_ARCHIVE_DIR/$archive_host
archive_botch=$PCP_LOG_DIR/pmproxy/pmproxy
$sudo rm -fr $archive_path $archive_botch

$valgrind_clean_assert pmproxy -Dcontext -f -p $pmproxy_port -U $user -l- -c $tmp.conf >$tmp.valout 2>$tmp.valerr &
pid=$!

echo "valgrind pid: $pid" >>$seq_full
echo "pmproxy port: $pmproxy_port" >>$seq_full

# valgrind takes awhile to fire up
i=0
while [ $i -lt 40 ]
do
    $PCP_BINADM_DIR/telnet-probe -c localhost $pmproxy_port && break
    sleep 1
    i=`expr $i + 1`
done
if $PCP_BINADM_DIR/telnet-probe -c localhost $pmproxy_port
then 
    echo "Startup took $i secs" >>$seq_full
else
    echo "Arrgh: valgrind failed to start pmproxy on port $pmproxy_port after 40 secs"
    exit
fi

# also wait for pmproxy to establish a key server connection
_wait_for_pcp_schema $key_server_port

echo "=== pmlogpush to pmproxy ==="
pmlogpush -p $pmproxy_port $archive
pmsleep 1.5 # allow time for key server as well

pminfo -a $archive | sed -n -f $tmp.metrics.sed | LC_COLLATE=POSIX sort

# start valgrind pmproxy process exit
pmsignal $pid

# while that happens, check state of the key server
echo "=== pmseries value check ==="
pmseries -c $tmp.conf -Z UTC 'sample.milliseconds[count:1,timezone:"UTC"]' | _filter_values

echo "=== pmseries labels check ==="
pmseries -c $tmp.conf -l | sed -n -f $tmp.labels.sed | LC_COLLATE=POSIX sort

echo "=== pmseries metrics check ==="
pmseries -c $tmp.conf -m | sed -n -f $tmp.metrics.sed | LC_COLLATE=POSIX sort

# valgrind takes awhile to shutdown too
_wait_process_end $pid
echo "=== valgrind stdout ===" | tee -a $seq_full
cat $tmp.valout | tee -a $seq_full | _filter_valgrind

echo "=== valgrind stderr ===" | tee -a $seq_full
cat $tmp.valerr | tee -a $seq_full | _filter_context_debug | _filter_pmproxy_log | grep -v "Cannot connect to key server" | _filter_pmproxy_port

# final sanity check
if [ -d $archive_botch ]
then
    echo "Bad archive path $archive_botch found but should not be"
    status=1
    exit
fi

# success, all done
exit