File: 1130

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 (152 lines) | stat: -rwxr-xr-x 5,683 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
#! /bin/sh
# PCP QA Test No. 1130
# checks basic pcp2elasticsearch functionality
#
# Copyright (c) 2017-2025 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"

. ./common.python

$python -c "from pcp import pmapi" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python pcp pmapi module not installed"

which socat >/dev/null 2>&1 || _notrun "socat binary not installed"
which pcp2elasticsearch >$seq_full 2>&1 || _notrun "pcp2elasticsearch not installed"

$python -c "import requests" >/dev/null 2>&1
[ $? -eq 0 ] || _notrun "python requests module not installed"

port=9200
$PCP_BINADM_DIR/telnet-probe -c localhost $port
[ $? -eq 1 ] || _notrun "Elasticsearch port $port is already in use"

[ "$PCP_PLATFORM" = freebsd ] && _notrun "socat use here does not work on FreeBSD"

signal=$PCP_BINADM_DIR/pmsignal
status=1       # failure is the default!

trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

# deal with non-determinism in arithmetic values from pcp2elasticsearch
# e.g. "clock": 3029.0309999999999 -> "clock": 3029.031
#
_filter_prec()
{
    sed \
	-e '/"bogomips":/s/\(5587.42\)0*[1-3]/\1/' \
	-e '/"clock":/s/\(3029.03\)09*[7-9]/\11/' \
	-e '/"load":/s/\(0.0\)89*[7-9]/\19/' \
	-e '/"speed":/s/\(781261.93\)79*[7-9]/\18/' \
	-e '/"clock":/s/\(2723.43\)69*[7-9]/\17/' \
	-e '/"load":/s/\(0.08\)0*[1-3]/\1/' \
	-e '/"user":/s/\(9.999\)0*[1-6]/\1/' \
	-e '/"clock":/s/\(2800.10\)89*[7-9]/\19/' \
    # end
}

_full_stash()
{
    echo "--- pcp2elasticsearch stdout --" >>$seq_full
    cat $tmp.p2e.out >>$seq_full
    echo "--- pcp2elasticsearch stderr --" >>$seq_full
    cat $tmp.p2e.err >>$seq_full
    echo "--- socket cat stdout --" >>$seq_full
    cat $tmp.socat.out >>$seq_full
    echo "--- socket cat stderr --" >>$seq_full
    cat $tmp.socat.err >>$seq_full
    echo "--- socket cat logfile --" >>$seq_full
    cat $tmp.socat.log >>$seq_full
    rm -f $tmp.p2e.out $tmp.p2e.err $tmp.socat.out $tmp.socat.err $tmp.socat.log
}

ncpu=`pmprobe -v hinv.ncpu | awk '{print $3}'`
pcp2elasticsearch="$python `which pcp2elasticsearch`"

echo | tee -a $seq_full
echo "=== 1. pcp2elasticsearch one-shot one-metric ===" | tee -a $seq_full
echo start socat `date '+%H:%M:%S.%N'` >>$seq_full
socat -lf $tmp.socat.log -v -t 0.000001 tcp-listen:$port,reuseaddr,fork system:"echo HTTP/1.1 201 Created" >$tmp.socat.out 2>$tmp.socat.err &
pid=$!
sleep 2
echo start pcp2elasticsearch `date '+%H:%M:%S.%N'` >>$seq_full
$pcp2elasticsearch -t 1 -s 1 hinv.ncpu >$tmp.p2e.out 2>$tmp.p2e.err
sleep 5
echo kill pcp2elasticsearch `date '+%H:%M:%S.%N'` >>$seq_full
$signal $pid 2>/dev/null
wait
# some fatal errors in socat.err, some in socat.log ...
#
grep -q 'socat.* Remote end closed connection without response' $tmp.socat.err && \
	_notrun "socat on this platform is not behaving as expected [closed conn]"

# From Paul 13 Jan 2025 ...
# Getting reset connection messages with socat even though exporter works
# correctly meaning the test is not being run. Happens with prior upstream
# exporter version also:
#     ... socat[957217] E read(6, 0x558187c97000, 8192): Connection reset by peer
#
# Commenting out the check and allowing QA test to run
#
#grep -q 'socat.* Connection reset by peer' $tmp.socat.log && \
#	_notrun "socat on this platform is not behaving as expected [reset conn]"

grep -q 'socat.* Broken pipe' $tmp.socat.log && \
	_notrun "socat on this platform is not behaving as expected [broken pipe]"
grep -E -q '^POST /+pcp/_doc HTTP/' $tmp.socat.err
[ $? -eq 0 ] && echo "Found correct index in output"
grep -E -q '"hinv": \{"ncpu": '$ncpu'}' $tmp.socat.err
[ $? -eq 0 ] && echo "Found correct value in output"
_full_stash

echo "=== 2. pcp2elasticsearch non-default targets ===" | tee -a $seq_full
socat -lf $tmp.socat.log -s -v -t 0.000001 tcp-listen:$port,reuseaddr,fork system:"echo HTTP/1.1 201 Created" >$tmp.socat.out 2>$tmp.socat.err &
pid=$!
sleep 2
$pcp2elasticsearch -t 1 -s 1 -X QAHOST -x INDEX hinv.ncpu >$tmp.p2e.out 2>$tmp.p2e.err
sleep 2
$signal $pid 2>/dev/null
wait
grep -E -q '^POST /+INDEX/_doc HTTP/' $tmp.socat.err
[ $? -eq 0 ] && echo "Found correct index in output"
grep -E -q '"@host-id": "QAHOST"' $tmp.socat.err
[ $? -eq 0 ] && echo "Found proper hostid in output"
_full_stash

echo "=== 3. pcp2elasticsearch full-blown archive replay session ===" | tee -a $seq_full
socat -lf $tmp.socat.log -s -v -t 0.000001 tcp-listen:$port,reuseaddr,fork system:"echo HTTP/1.1 201 Created" >$tmp.socat.out 2>$tmp.socat.err &
pid=$!
sleep 2
$pcp2elasticsearch -a $here/archives/rep -I "" >$tmp.p2e.out 2>$tmp.p2e.err
sleep 2
$signal $pid 2>/dev/null
wait
echo "--- Start of received data ---" | tee -a $seq_full
# sed is trying to dodge text fragments like this at the end of the
# line ...
# > 2025/08/25 07:36:48.000221044  length=973 from=0 to=972
grep -E '(slack)' $tmp.socat.err | sed -e 's,[<>] [1-9][0-9/:. ]*length=.*,,' >$tmp.archive.data
cat $tmp.archive.data >>$seq_full
while read -r line
do
  echo $line | _filter_prec | pmjson | LC_COLLATE=POSIX sort | tr -d ,
done < $tmp.archive.data
echo "--- End of received data ---" | tee -a $seq_full
_full_stash

echo "=== 4. pcp2elasticsearch with custom --es-search-type ===" | tee -a $seq_full
socat -lf $tmp.socat.log -s -v -t 0.000001 tcp-listen:$port,reuseaddr,fork system:"echo HTTP/1.1 201 Created" >$tmp.socat.out 2>$tmp.socat.err &
pid=$!
sleep 2
$pcp2elasticsearch -t 1 -s 1 -X QAHOST -x INDEX hinv.ncpu --es-search-type=test_search_type >$tmp.p2e.out 2>$tmp.p2e.err
sleep 2
$signal $pid 2>/dev/null
wait
echo "--- Start of received data ---"
grep -E -q '^POST /+INDEX/test_search_type HTTP/' $tmp.socat.err
[ $? -eq 0 ] && echo "Found correct index in output"
_full_stash

status=0
exit