File: 1727

package info (click to toggle)
pcp 7.0.5-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,916 kB
  • sloc: ansic: 1,478,844; sh: 177,285; xml: 160,462; cpp: 83,809; python: 24,349; perl: 18,303; yacc: 6,877; lex: 2,864; makefile: 2,694; awk: 165; fortran: 60; java: 52
file content (113 lines) | stat: -rwxr-xr-x 3,161 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
#!/bin/sh
# PCP QA Test No. 1727
# Test duplicate instname labels in /metrics webapi when a context
# level label such as "hostname" is explicitly specified.
# Test invalid OpenMetrics metric names also.
#
# Copyright (c) 2021 Red Hat.  All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.openmetrics

_check_series   # ensure pmproxy makes a REST API available
_pmdaopenmetrics_check || _notrun "openmetrics pmda not installed"
which curl >/dev/null 2>&1 || _notrun curl not installed

status=1	# failure is the default!

# only stop pmproxy if it was not running before the QA test starts
if [ -n "`_get_pids_by_name pmproxy`" ]
then
    pmproxy_was_running=true
else
    pmproxy_was_running=false
    if ! _service pmproxy start >>$seq_full 2>&1; then _exit 1; fi
fi
echo "pmproxy_was_running=$pmproxy_was_running" >>$seq_full

_cleanup()
{
    cd $here
    if $need_restore
    then
        $sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
        _restore_config $PCP_ETC_DIR/pcp/labels
	$pmproxy_was_running || _service pmproxy stop >>$seq_full 2>&1
        need_restore=false
    fi
    _pmdaopenmetrics_cleanup
    $sudo rm -rf $tmp $tmp.*
}

_filter_openmetrics_labels()
{
    sed \
    -e "s;$PCP_PMDAS_DIR;PCP_PMDAS_DIR;g" \
    -e 's;machineid="[a-z0-9]*";machineid=MACHINEID;g' \
    -e 's;hostname="[a-zA-Z0-9_\.\-]*";hostname=HOSTNAME;g' \
    -e 's;hostname:[a-zA-Z0-9_\.\-]*";hostname:HOSTNAME";g' \
    -e 's;domainname="[a-zA-Z0-9_\.\-]*";domainname=DOMAINNAME;g' \
    -e 's;144\.[0-9]*\.[0-9]*;NUMERIC_PMID;g' \
    -e 's;144\.[0-9]*;NUMERIC_INDOM;g' \
    # end
}

need_restore=true
_prepare_pmda openmetrics
trap "_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd

# real QA test starts here
_pmdaopenmetrics_save_config
_save_config $PCP_ETC_DIR/pcp/labels
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*

# set up a scripted config
MYHOST=`hostname`
cat <<EOF >$tmp.script
#! /bin/bash

echo '# HELP somemetric metric to test duplicate instname labels'
echo '# TYPE somemetric gauge'
echo 'somemetric{hostname="$MYHOST"} 1234'
EOF

cat <<EOF >$tmp.badxml
#! /bin/bash

cat $here/sadist/891688-dash-time.xml
echo '# TYPE somemetric gauge'
echo 'somemetric{hostname="$MYHOST"} 1234'
EOF

chmod 755 $tmp.script $tmp.badxml
$sudo mv $tmp.script $PCP_PMDAS_DIR/openmetrics/config.d/duplicate_instname_label.sh
$sudo mv $tmp.badxml $PCP_PMDAS_DIR/openmetrics/config.d/invalid_metrics_badinput.sh

_pmdaopenmetrics_install
if ! _pmdaopenmetrics_wait_for_metric openmetrics.control.calls
then
    status=1
    exit
fi

echo; echo === /metrics webapi listing. The instname label should appear only once.
curl -Gs 'http://localhost:44322/metrics?names=openmetrics.duplicate_instname_label.somemetric' \
| _filter_openmetrics_labels

echo; echo === verify metric name validity using pminfo
pminfo -v openmetrics

# squash errors for a clean uninstall
$sudo rm $PCP_PMDAS_DIR/openmetrics/config.d/invalid_metrics_badinput.sh
# capture openmetrics log for posterity
cat $PCP_LOG_DIR/pmcd/openmetrics.log >> $seq_full

_pmdaopenmetrics_remove

# success, all done
status=0
exit