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
|
#!/bin/sh
# PCP QA Test No. 1306
# Test pmdaopenmetrics label filtering, including optional labels
#
# Copyright (c) 2018 Red Hat. All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.openmetrics
_pmdaopenmetrics_check || _notrun "openmetrics pmda not installed"
status=1 # failure is the default!
_cleanup()
{
cd $here
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
_restore_config $PCP_ETC_DIR/pcp/labels
_sighup_pmcd
_pmdaopenmetrics_cleanup
$sudo rm -rf $tmp $tmp.*
}
_prepare_pmda openmetrics
trap "_cleanup; exit \$status" 0 1 2 3 15
_stop_auto_restart pmcd
_filter()
{
# Filter a bunch of labels that we dont want for QA purposes
sed \
-e 's/"domainname":"[^"]*"//' \
-e 's/"groupid":[0-9]*//' \
-e 's/"userid":[0-9]*//' \
-e 's/"hostname":"[^"]*"//' \
-e 's/"machineid":"[^"]*"//' \
-e 's/"url":"[^"]*"//' \
-e 's/,[,]*/,/g' -e 's/,}/}/'
}
# real QA test starts here
_pmdaopenmetrics_save_config
_save_config $PCP_ETC_DIR/pcp/labels
$sudo rm -rf $PCP_ETC_DIR/pcp/labels/*
# add the URL for this test
# need to be a place the user $PCP_USER (pmcd) can read
#
file=labelfiltering.txt
cp $here/openmetrics/samples/$file $tmp.$file
urlbase=`basename "$file" .txt | tr .- _`
echo 'file://'$tmp.$file >$tmp.tmp
# add a bunch of label filters to exercise various filtering options
cat <<EOF >>$tmp.tmp
# Filter to remove the "uninteresting" label
FILTER: EXCLUDE LABEL uninteresting
# Filter to remove all labels in metric2, thus it becomes singular
FILTER: EXCLUDE LABEL removeme
# Filter to exclude label "def" hence metric3 has duplicate instances
FILTER: EXCLUDE LABEL def
#
# *** NOTE: optional labels are not implemented yet
# Filter to flag some_optional_label as optional in metric4
# (an optional label is not present in instance name, but still included as a label for the metric)
# FILTER: OPTIONAL LABEL some_optional_label
# implicit final rule includes all labels not matching anything above
# (this implicit rule is listed here just for testing purposes)
FILTER: INCLUDE .*
EOF
$sudo cp $tmp.tmp $PCP_PMDAS_DIR/openmetrics/config.d/$urlbase.url
_pmdaopenmetrics_install
if ! _pmdaopenmetrics_wait_for_metric openmetrics.control.calls
then
status=1
exit
fi
echo; echo === URL configuration file contains
sed -e "s;$tmp;TMP;g" < $PCP_PMDAS_DIR/openmetrics/config.d/$urlbase.url
echo; echo === pminfo listing. Note some labels in the pminfo listing have been removed, see _filter
names=`pminfo openmetrics | grep -F -v openmetrics.control | LC_COLLATE=POSIX sort` 2>$tmp.err
if [ -z "$names" ]; then
echo "FAILED - no openmetrics metrics to show"
else
if pminfo -fl `pminfo openmetrics | grep -F -v openmetrics.control | LC_COLLATE=POSIX sort` > $tmp.info 2>$tmp.err
then
:
else
echo "... failed! ... here is the Install log ..."
cat $tmp.out
fi
cat $tmp.info $tmp.err | _filter
fi
echo == Note: check $seq.full for details
echo == pmdaopenmetrics LOG == >>$seq_full
cat $PCP_LOG_DIR/pmcd/openmetrics.log >>$seq_full
_pmdaopenmetrics_remove
# success, all done
status=0
exit
|